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.2.0 to 0.2.1

8

CHANGELOG.md
# @guildedts/ws
## 0.2.1
### Patch Changes
- 727d276: # Fixes
- Fix consistency in docs
## 0.2.0

@@ -4,0 +12,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,113 +0,114 @@

"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 {
options;
/** The authoization token for the websocket. */
token;
/** The API version for the Websocket. */
version;
/** The websocket. */
socket;
/** The date the websocket connected. */
connectedAt;
/** The ping of the websocket connection. */
ping;
/** The date of the last ping. */
pingedAt;
/** @param options The options for the Websocket manager. */
constructor(options) {
super();
this.options = options;
this.token = options.token;
this.version = options.version;
}
/** Whether the websocket is connected. */
get isConnected() {
return !!this.connectedAt ?? false;
}
/** The timestamp of when the websocket connected. */
get connectedTimestamp() {
return this.connectedAt?.getTime();
}
/** The timestamp of the last ping. */
get pingedTimestamp() {
return this.pingedAt?.getTime();
}
/** How long the websocket has been connected. (in MS) */
get uptime() {
return this.isConnected ? 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) {
this.token = token;
this.socket = new ws_1.default(this.url, {
headers: {
Authorization: `Bearer ${this.token}`,
},
});
this.socket.on('close', this.onSocketClose.bind(this));
this.socket.on('message', (rawData) => {
const { op, t, d } = JSON.parse(rawData.toString());
this.onSocketData(op, t, d);
});
this.socket.on('ping', this.onSocketPing.bind(this));
this.socket.on('pong', this.onSocketPong.bind(this));
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.terminate();
return this;
}
/** @ignore */
onSocketClose() {
this.token = undefined;
this.socket = undefined;
this.connectedAt = undefined;
this.emit('disconnect');
}
/** @ignore */
onSocketData(op, event, data) {
switch (op) {
case 0:
this.emit('data', event, data);
break;
case 1:
this.socket.emit('ping');
this.connectedAt = new Date();
this.emit('connect', data.user);
break;
}
}
/** @ignore */
onSocketPing() {
this.pingedAt = new Date();
this.socket.ping();
}
/** @ignore */
onSocketPong() {
this.ping = Date.now() - this.pingedTimestamp;
}
options;
/** The auth token for the websocket. */
token;
/** The version of the Websocket API. */
version;
/** The websocket. */
socket;
/** The date the websocket connected. */
connectedAt;
/** The ping of the websocket connection. */
ping;
/** The date the websocket was pinged. */
pingedAt;
/** @param options The options for the Websocket manager. */
constructor(options) {
super();
this.options = options;
this.token = options.token;
this.version = options.version;
}
/** Whether the websocket is connected. */
get isConnected() {
return !!this.connectedAt ?? false;
}
/** The timestamp of when the websocket connected. */
get connectedTimestamp() {
return this.connectedAt?.getTime();
}
/** The timestamp the websocket was pinged. */
get pingedTimestamp() {
return this.pingedAt?.getTime();
}
/** How long the websocket has been connected. */
get uptime() {
return this.isConnected ? Date.now() - this.connectedTimestamp : undefined;
}
/** The URL of the Websocket. */
get url() {
return `wss://api.guilded.gg/v${this.version}/websocket`;
}
/**
* Connect to the Websocket API.
* @param token The auth token.
* @returns The Websocket manager.
*/
connect(token = this.token) {
this.token = token;
this.socket = new ws_1.default(this.url, {
headers: {
Authorization: `Bearer ${this.token}`,
},
});
this.socket.on('close', this.onSocketClose.bind(this));
this.socket.on('message', (raw) => {
const { op, t, d } = JSON.parse(raw.toString());
this.onSocketData(op, t, d);
});
this.socket.on('ping', this.onSocketPing.bind(this));
this.socket.on('pong', this.onSocketPong.bind(this));
return this;
}
/**
* Disconnect from the Websocket API.
* @returns The websocket manager.
*/
disconnect() {
if (!this.socket || !this.socket.OPEN) throw new Error('Websocket is not connected.');
this.socket.terminate();
return this;
}
/** @ignore */
onSocketClose() {
this.token = undefined;
this.socket = undefined;
this.connectedAt = undefined;
this.emit('disconnect');
}
/** @ignore */
onSocketData(op, event, data) {
switch (op) {
case 0:
this.emit('data', event, data);
break;
case 1:
this.socket.emit('ping');
this.connectedAt = new Date();
this.emit('connect', data.user);
break;
}
}
/** @ignore */
onSocketPing() {
this.pingedAt = new Date();
this.socket.ping();
}
/** @ignore */
onSocketPong() {
this.ping = Date.now() - this.pingedTimestamp;
}
}
exports.WebsocketManager = WebsocketManager;
//# sourceMappingURL=WebsocketManager.js.map
//# sourceMappingURL=WebsocketManager.js.map
{
"name": "@guildedts/ws",
"version": "0.2.0",
"version": "0.2.1",
"description": "The Websocket API manager for Guilded.TS.",

@@ -12,5 +12,5 @@ "main": "lib/index.js",

"scripts": {
"build": "yarn clear && yarn tsc",
"clear": "yarn rimraf lib typings",
"prepublishOnly": "yarn build"
"build": "run clear && tsc",
"clear": "rimraf lib typings",
"prepublishOnly": "run build"
},

@@ -41,3 +41,3 @@ "keywords": [

"devDependencies": {
"guilded-api-typings": "^0.2.0",
"guilded-api-typings": "^0.3.0",
"rimraf": "^3.0.2",

@@ -44,0 +44,0 @@ "typescript": "^4.6.3"

<div align="center">
<br />
<a href="https://guildedts.js.org"><img src="https://guildedts.js.org/media/banner.jpg" width="500" alt="Guilded.TS"/></a>
<h3><strong>The Websocket API manager for <a href="https://guildedts.js.org">Guilded.TS</a>.</strong></h3>
<a href="https://guildedts.js.org">
<img src="https://guildedts.js.org/media/banner.jpg" width="500" alt="Guilded.TS"/>
</a>
<h3>The Websocket API manager for <a href="https://guildedts.js.org">Guilded.TS</a>.</h3>
<br />
<div>
<a href="https://www.npmjs.com/package/@guildedts/ws"><img src="https://img.shields.io/npm/v/@guildedts/ws" alt="Version" /></a>
<a href="https://www.npmjs.com/package/@guildedts/ws"><img src="https://img.shields.io/npm/dt/@guildedts/ws" alt="Downloads" /></a>
<a href="https://www.npmjs.com/package/@guildedts/ws"><img src="https://img.shields.io/npm/l/@guildedts/ws" alt="License: Apache-2.0">
<A href="https://guilded.gg/guildedts">
<img src="https://shields.yoki-labs.xyz/shields/vanity/guildedts?style=for-the-badge" alt="Guilded server">
</a>
<a href="https://npmjs.com/@guildedts/ws">
<img src="https://img.shields.io/npm/v/@guildedts/ws?style=for-the-badge" alt="Version" />
</a>
<a href="https://npmjs.com/@guildedts/ws">
<img src="https://img.shields.io/npm/dt/@guildedts/ws?style=for-the-badge" alt="Downloads" />
</a>
<a href="https://github.com/guildedts/guilded.ts/blob/main/LICENSE">
<img src="https://img.shields.io/github/license/guildedts/guilded.ts?style=for-the-badge" alt="License" />
</a>
</div>
<br />
</div>

@@ -15,23 +27,14 @@

- [GitHub](https://github.com/guildedts/guilded.ts)
- [NPM](https://www.npmjs.com/package/guilded.ts)
- [Guilded.TS Guilded Server](https://www.guilded.gg/guildedts)
- [Guilded API Guilded server](https://www.guilded.gg/API-Official)
- [Guide](https://guide.guildedts.js.org)
- [Documentation](https://guildedts.js.org)
- [GitHub](https://github.com/guildedts/guilded.ts/tree/main/packages/ws)
- [NPM](https://npmjs.com/@guildedts/ws)
- [Documentation](https://guildedts.js.org/modules/_guildedts_ws)
# Installation
```
npm i @guildedts/ws
yarn add @guildedts/ws
pnpm add @guildedts/ws
```
- `npm i @guildedts/ws`
- `yarn add @guildedts/ws`
- `pnpm add @guildedts/ws`
# Contributing
[Contribute to Guilded.TS.](https://github.com/guildedts/guilded.ts/tree/main/.github/CONTRIBUTING.md)
---
**Maintained by [Gamertike](https://www.gamertike.com). | Inspired by [discord.js](https://discord.js.org).**
**Maintained by [Gamertike](https://gamertike.com) | [Contribute](https://github.com/guildedts/guilded.ts/tree/main/.github/CONTRIBUTING.md) | Inspired by [discord.js](https://discord.js.org)**
export { WebsocketManager as default } from './WebsocketManager';
export * from './WebsocketManager';
//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map

@@ -7,75 +7,87 @@ /// <reference types="node" />

export declare class WebsocketManager extends EventEmitter {
readonly options: WebsocketOptions;
/** The authoization token for the websocket. */
token?: string;
/** The API version for the Websocket. */
readonly version: number;
/** The websocket. */
socket?: Websocket;
/** The date the websocket connected. */
connectedAt?: Date;
/** The ping of the websocket connection. */
ping?: number;
/** The date of the last ping. */
pingedAt?: Date;
/** @param options The options for the Websocket manager. */
constructor(options: WebsocketOptions);
/** Whether the websocket is connected. */
get isConnected(): boolean;
/** The timestamp of when the websocket connected. */
get connectedTimestamp(): number | undefined;
/** The timestamp of the last ping. */
get pingedTimestamp(): 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;
/** @ignore */
private onSocketClose;
/** @ignore */
private onSocketData;
/** @ignore */
private onSocketPing;
/** @ignore */
private onSocketPong;
readonly options: WebsocketOptions;
/** The auth token for the websocket. */
token?: string;
/** The version of the Websocket API. */
readonly version: number;
/** The websocket. */
socket?: Websocket;
/** The date the websocket connected. */
connectedAt?: Date;
/** The ping of the websocket connection. */
ping?: number;
/** The date the websocket was pinged. */
pingedAt?: Date;
/** @param options The options for the Websocket manager. */
constructor(options: WebsocketOptions);
/** Whether the websocket is connected. */
get isConnected(): boolean;
/** The timestamp of when the websocket connected. */
get connectedTimestamp(): number | undefined;
/** The timestamp the websocket was pinged. */
get pingedTimestamp(): number | undefined;
/** How long the websocket has been connected. */
get uptime(): number | undefined;
/** The URL of the Websocket. */
get url(): `wss://api.guilded.gg/v${number}/websocket`;
/**
* Connect to the Websocket API.
* @param token The auth token.
* @returns The Websocket manager.
*/
connect(token?: string): this;
/**
* Disconnect from the Websocket API.
* @returns The websocket manager.
*/
disconnect(): this;
/** @ignore */
private onSocketClose;
/** @ignore */
private onSocketData;
/** @ignore */
private onSocketPing;
/** @ignore */
private onSocketPong;
}
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 options for the Websocket manager. */
export interface WebsocketOptions {
/** The authoization token for the websocket. */
token?: string;
/** The API version for the websocket. */
version: number;
/** The auth token for the Websocket API. */
token?: string;
/** The version of the Websocket API. */
version: number;
}
/** 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: {
[Event in keyof WSEvents]: [event: Event, data: WSEvents[Event]];
}[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 API. */
data: {
[Event in keyof WSEvents]: [event: Event, data: WSEvents[Event]];
}[keyof WSEvents];
}
//# sourceMappingURL=WebsocketManager.d.ts.map
//# sourceMappingURL=WebsocketManager.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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