New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@guildedts/ws

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@guildedts/ws - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

6

CHANGELOG.md
# @guildedts/ws
## 0.0.2
### Patch Changes
- All issues with dependencies should now be fixed.
## 0.0.1

@@ -4,0 +10,0 @@

58

lib/index.js

@@ -1,21 +0,39 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
'use strict';
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = {
enumerable: true,
get: function () {
return m[k];
},
};
}
Object.defineProperty(o, k2, desc);
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __exportStar =
(this && this.__exportStar) ||
function (m, exports) {
for (var p in m)
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
__createBinding(exports, m, p);
};
Object.defineProperty(exports, '__esModule', { value: true });
exports.default = void 0;
var WebsocketManager_1 = require("./WebsocketManager");
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return WebsocketManager_1.WebsocketManager; } });
__exportStar(require("./WebsocketManager"), exports);
//# sourceMappingURL=index.js.map
var WebsocketManager_1 = require('./WebsocketManager');
Object.defineProperty(exports, 'default', {
enumerable: true,
get: function () {
return WebsocketManager_1.WebsocketManager;
},
});
__exportStar(require('./WebsocketManager'), exports);
//# sourceMappingURL=index.js.map

@@ -1,83 +0,84 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
'use strict';
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, '__esModule', { value: true });
exports.WebsocketManager = void 0;
const ws_1 = __importDefault(require("ws"));
const events_1 = __importDefault(require("events"));
const ws_1 = __importDefault(require('ws'));
const events_1 = __importDefault(require('events'));
/** The Websocket manager for the Guilded API. */
class WebsocketManager extends events_1.default {
version;
/** The authoization token for the websocket. */
token;
/** The websocket. */
socket;
/** Whether the websocket is connected. */
connected = false;
/** The time of when the websocket connected. */
connectedAt;
/** @param version The API version for the websocket. */
constructor(version) {
super();
this.version = version;
}
/** The timestamp of when the websocket connected. */
get connectedTimestamp() {
return this.connectedAt?.getTime();
}
/** How long the websocket has been connected. (in MS) */
get uptime() {
return this.connected ? Date.now() - this.connectedTimestamp : undefined;
}
/** The URL for the websocket. */
get url() {
return `wss://api.guilded.gg/v${this.version}/websocket`;
}
/**
* Connect to the websocket.
* @param token The authorization token.
* @returns The websocket manager.
*/
connect(token) {
this.token = token;
this.socket = new ws_1.default(this.url, {
headers: {
Authorization: `Bearer ${this.token}`,
},
});
this.socket.on('close', () => {
this.token = undefined;
this.socket = undefined;
this.connected = false;
this.connectedAt = undefined;
this.emit('disconnect');
});
this.socket.on('message', (data) => {
const { op, t, d } = JSON.parse(data.toString());
switch (op) {
case 0:
this.emit('data', t, d);
break;
case 1:
this.connected = true;
this.connectedAt = new Date();
this.emit('connect', d.user);
break;
}
});
return this;
}
/**
* Disconnect from the websocket.
* @returns The websocket manager.
*/
disconnect() {
if (!this.socket || !this.socket.OPEN)
throw new Error('Websocket is not connected.');
this.socket.close();
return this;
}
version;
/** The authoization token for the websocket. */
token;
/** The websocket. */
socket;
/** Whether the websocket is connected. */
connected = false;
/** The time of when the websocket connected. */
connectedAt;
/** @param version The API version for the websocket. */
constructor(version) {
super();
this.version = version;
}
/** The timestamp of when the websocket connected. */
get connectedTimestamp() {
return this.connectedAt?.getTime();
}
/** How long the websocket has been connected. (in MS) */
get uptime() {
return this.connected ? Date.now() - this.connectedTimestamp : undefined;
}
/** The URL for the websocket. */
get url() {
return `wss://api.guilded.gg/v${this.version}/websocket`;
}
/**
* Connect to the websocket.
* @param token The authorization token.
* @returns The websocket manager.
*/
connect(token) {
this.token = token;
this.socket = new ws_1.default(this.url, {
headers: {
Authorization: `Bearer ${this.token}`,
},
});
this.socket.on('close', () => {
this.token = undefined;
this.socket = undefined;
this.connected = false;
this.connectedAt = undefined;
this.emit('disconnect');
});
this.socket.on('message', (data) => {
const { op, t, d } = JSON.parse(data.toString());
switch (op) {
case 0:
this.emit('data', t, d);
break;
case 1:
this.connected = true;
this.connectedAt = new Date();
this.emit('connect', d.user);
break;
}
});
return this;
}
/**
* Disconnect from the websocket.
* @returns The websocket manager.
*/
disconnect() {
if (!this.socket || !this.socket.OPEN) throw new Error('Websocket is not connected.');
this.socket.close();
return this;
}
}
exports.WebsocketManager = WebsocketManager;
//# sourceMappingURL=WebsocketManager.js.map
//# sourceMappingURL=WebsocketManager.js.map
{
"name": "@guildedts/ws",
"version": "0.0.1",
"version": "0.0.2",
"description": "The Websocket API manager for Guilded.TS.",

@@ -35,2 +35,3 @@ "main": "lib/index.js",

"dependencies": {
"@types/ws": "^8.5.3",
"ws": "^8.5.0"

@@ -37,0 +38,0 @@ },

export { WebsocketManager as default } from './WebsocketManager';
export * from './WebsocketManager';
//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map

@@ -7,61 +7,73 @@ /// <reference types="node" />

export declare class WebsocketManager extends EventEmitter {
readonly version: number;
/** The authoization token for the websocket. */
token?: string;
/** The websocket. */
socket?: Websocket;
/** Whether the websocket is connected. */
connected: boolean;
/** The time of when the websocket connected. */
connectedAt?: Date;
/** @param version The API version for the websocket. */
constructor(version: number);
/** The timestamp of when the websocket connected. */
get connectedTimestamp(): number | undefined;
/** How long the websocket has been connected. (in MS) */
get uptime(): number | undefined;
/** The URL for the websocket. */
get url(): `wss://api.guilded.gg/v${number}/websocket`;
/**
* Connect to the websocket.
* @param token The authorization token.
* @returns The websocket manager.
*/
connect(token: string): this;
/**
* Disconnect from the websocket.
* @returns The websocket manager.
*/
disconnect(): this;
readonly version: number;
/** The authoization token for the websocket. */
token?: string;
/** The websocket. */
socket?: Websocket;
/** Whether the websocket is connected. */
connected: boolean;
/** The time of when the websocket connected. */
connectedAt?: Date;
/** @param version The API version for the websocket. */
constructor(version: number);
/** The timestamp of when the websocket connected. */
get connectedTimestamp(): number | undefined;
/** How long the websocket has been connected. (in MS) */
get uptime(): number | undefined;
/** The URL for the websocket. */
get url(): `wss://api.guilded.gg/v${number}/websocket`;
/**
* Connect to the websocket.
* @param token The authorization token.
* @returns The websocket manager.
*/
connect(token: string): this;
/**
* Disconnect from the websocket.
* @returns The websocket manager.
*/
disconnect(): this;
}
export interface WebsocketManager {
/** @ignore */
on<Event extends keyof WSManagerEvents>(event: Event, listener: (...args: WSManagerEvents[Event]) => any): this;
/** @ignore */
once<Event extends keyof WSManagerEvents>(event: Event, listener: (...args: WSManagerEvents[Event]) => any): this;
/** @ignore */
off<Event extends keyof WSManagerEvents>(event: Event, listener: (...args: WSManagerEvents[Event]) => any): this;
/** @ignore */
emit<Event extends keyof WSManagerEvents>(event: Event, ...args: WSManagerEvents[Event]): boolean;
/** @ignore */
on<Event extends keyof WSManagerEvents>(
event: Event,
listener: (...args: WSManagerEvents[Event]) => any,
): this;
/** @ignore */
once<Event extends keyof WSManagerEvents>(
event: Event,
listener: (...args: WSManagerEvents[Event]) => any,
): this;
/** @ignore */
off<Event extends keyof WSManagerEvents>(
event: Event,
listener: (...args: WSManagerEvents[Event]) => any,
): this;
/** @ignore */
emit<Event extends keyof WSManagerEvents>(
event: Event,
...args: WSManagerEvents[Event]
): boolean;
}
/** The websocket manager events. */
export interface WSManagerEvents {
/** Emitted when the websocket is connected. */
connect: [user: APIUser];
/** Emitted when the websocket is disconnected. */
disconnect: [];
/** Emitted when data is received from the websocket. */
data: {
[K in keyof WSEvents]: [type: K, data: WSEvents[K]];
}[keyof WSEvents];
/** Emitted when the websocket is connected. */
connect: [user: APIUser];
/** Emitted when the websocket is disconnected. */
disconnect: [];
/** Emitted when data is received from the websocket. */
data: {
[K in keyof WSEvents]: [type: K, data: WSEvents[K]];
}[keyof WSEvents];
}
/** The websocket data. */
export interface WSData {
/** The operation code. */
op: number;
/** The event type. */
t: any;
/** The event data. */
d: any;
/** The operation code. */
op: number;
/** The event type. */
t: any;
/** The event data. */
d: any;
}
//# sourceMappingURL=WebsocketManager.d.ts.map
//# sourceMappingURL=WebsocketManager.d.ts.map
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc