From 864e194398031c4dad453cda0c429ea1f2103c9f Mon Sep 17 00:00:00 2001 From: RainyXeon / Date: Sun, 12 May 2024 18:20:18 +0700 Subject: [PATCH] remove: VoiceReceiver plugin --- README.md | 22 ++++-- package.json | 2 +- src/Interface/Constants.ts | 6 -- src/Plugin/VoiceReceiver/Plugin.ts | 121 ----------------------------- src/Plugin/index.ts | 26 ------- src/Rainlink.ts | 72 ----------------- src/index.ts | 2 - 7 files changed, 17 insertions(+), 234 deletions(-) delete mode 100644 src/Plugin/VoiceReceiver/Plugin.ts delete mode 100644 src/Plugin/index.ts diff --git a/README.md b/README.md index 7997109..b2ebe9e 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,6 @@ Another lavalink wrapper but focus on stability and rich features -# ⚠️ Warning!! - -⚠️ This lavalink wrapper is just in the beta stage, it will have some bug so please report it on github! - -⚠️ Update 5: Rainlink now in stage 25 of development (Near stable) - # 🌟 Features - Stable client - Support TypeScript @@ -49,6 +43,7 @@ This is the list of all rainlink plugin currently supported | rainlink-deezer | Official | [npmjs](https://www.npmjs.com/package/rainlink-deezer) / [github](https://github.com/RainyProduction/rainlink-deezer) | RainyXeon | | rainlink-apple | Official | [npmjs](https://www.npmjs.com/package/rainlink-apple) / [github](https://github.com/RainyProduction/rainlink-apple) | RainyXeon | | rainlink-spotify | Official | [npmjs](https://www.npmjs.com/package/rainlink-spotify) / [github](https://github.com/RainyProduction/rainlink-spotify) | RainyXeon | +| rainlink-voice | Official | [npmjs](hhttps://www.npmjs.com/package/rainlink-voice) / [github](https://github.com/RainyProduction/rainlink-voice) | RainyXeon | # ⚙ Drivers @@ -62,6 +57,21 @@ This is the list of all rainlink driver currently supported (codename is made up | frequenc/v1/miku | [FrequenC](https://github.com/PerformanC/FrequenC) | C | IN TESTING | miku | This driver is in testing so don't use it or you will have errors | # 📃 Migrtation logs: +## 0.9.2 -> 1.0.0 +```diff +src/index.ts +- Plugin +- Plugin.VoiceReceiver +- Plugin.PlayerMoved +src/Interface/Constants.ts +- VoiceConnect = 'voiceConnect', +- VoiceDisconnect = 'voiceDisconnect', +- VoiceError = 'voiceError', +- VoiceStartSpeaking = 'voiceStartSpeaking', +- VoiceEndSpeaking = 'voiceEndSpeaking', +src/Plugin/RainlinkPlugin.ts ++ isRainlinkPlugin +``` ## 0.9.0 -> 0.9.2 ```diff diff --git a/package.json b/package.json index 4d3e814..7f59072 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rainlink", - "version": "0.9.4", + "version": "1.0.0", "description": "Another lavalink wrapper but focus on stability and rich features", "repository": { "type": "git", diff --git a/src/Interface/Constants.ts b/src/Interface/Constants.ts index 2e1b239..32ae4cf 100644 --- a/src/Interface/Constants.ts +++ b/src/Interface/Constants.ts @@ -30,12 +30,6 @@ export enum RainlinkEvents { QueueShuffle = 'queueShuffle', QueueClear = 'queueClear', QueueEmpty = 'queueEmpty', - // Voice receiver - VoiceConnect = 'voiceConnect', - VoiceDisconnect = 'voiceDisconnect', - VoiceError = 'voiceError', - VoiceStartSpeaking = 'voiceStartSpeaking', - VoiceEndSpeaking = 'voiceEndSpeaking', } /** diff --git a/src/Plugin/VoiceReceiver/Plugin.ts b/src/Plugin/VoiceReceiver/Plugin.ts deleted file mode 100644 index 42ca819..0000000 --- a/src/Plugin/VoiceReceiver/Plugin.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { RainlinkPlugin as Plugin } from '../RainlinkPlugin'; -import { Rainlink } from '../../Rainlink'; -import { RainlinkEvents, RainlinkPluginType } from '../../Interface/Constants'; -import { RainlinkNode } from '../../Node/RainlinkNode'; -import { metadata } from '../../metadata'; -import { VoiceChannelOptions } from '../../Interface/Player'; -import { RainlinkWebsocket } from '../../Utilities/RainlinkWebsocket'; -import { RainlinkDatabase } from '../../Utilities/RainlinkDatabase'; - -export class RainlinkPlugin extends Plugin { - protected manager: Rainlink | null = null; - protected runningWs: RainlinkDatabase = new RainlinkDatabase(); - - constructor() { - super(); - } - - /** Name function for getting plugin name */ - public name(): string { - return 'rainlink-voiceReceiver'; - } - - /** Type function for diferent type of plugin */ - public type(): RainlinkPluginType { - return RainlinkPluginType.Default; - } - - /** Open the ws voice reciver client */ - public open(node: RainlinkNode, voiceOptions: VoiceChannelOptions): void { - if (!this.manager) throw new Error('This plugin is unloaded!'); - const wsUrl = `${node.options.secure ? 'wss' : 'ws'}://${node.options.host}:${node.options.port}`; - const ws = new RainlinkWebsocket(wsUrl + '/connection/data', { - headers: { - authorization: node.options.auth, - 'user-id': this.manager!.id, - 'client-name': `${metadata.name}/${metadata.version} (${metadata.github})`, - 'user-agent': this.manager!.rainlinkOptions.options!.userAgent!, - 'guild-id': voiceOptions.guildId, - }, - }); - this.runningWs.set(voiceOptions.guildId, ws); - ws.on('open', () => { - this.debug('Connected to nodelink\'s voice receive server!'); - this.manager?.emit(RainlinkEvents.VoiceConnect, node); - }); - ws.on('message', (data: string) => this.wsMessageEvent(node, data)); - ws.on('error', err => { - this.debug('Errored at nodelink\'s voice receive server!'); - this.manager?.emit(RainlinkEvents.VoiceError, node, err); - }); - ws.on('close', (code: number, reason: Buffer) => { - ws.removeAllListeners(); - this.debug(`Disconnected to nodelink's voice receive server! Code: ${code} Reason: ${reason}`); - this.manager?.emit(RainlinkEvents.VoiceDisconnect, node, code, reason); - }); - } - - /** Open the ws voice reciver client */ - public close(guildId: string): void { - if (!this.manager) throw new Error('This plugin is unloaded!'); - const targetWs = this.runningWs.get(guildId); - if (!targetWs) return; - targetWs.close(1006, 'Self closed'); - this.runningWs.delete(guildId); - this.debug('Destroy connection to nodelink\'s voice receive server!'); - return; - } - - protected wsMessageEvent(node: RainlinkNode, data: string) { - if (!this.manager) throw new Error('This plugin is unloaded!'); - const wsData = JSON.parse(data.toString()); - this.debug(String(data)); - switch (wsData.type) { - case 'startSpeakingEvent': { - this.manager?.emit(RainlinkEvents.VoiceStartSpeaking, node, wsData.data.userId, wsData.data.guildId); - break; - } - case 'endSpeakingEvent': { - this.manager?.emit( - RainlinkEvents.VoiceEndSpeaking, - node, - wsData.data.data, - wsData.data.userId, - wsData.data.guildId, - ); - break; - } - } - } - - /** Load function for make the plugin working */ - public load(manager: Rainlink): void { - this.manager = manager; - this.manager.on('playerCreate', player => { - if (!player.node.driver.id.includes('nodelink')) return; - this.open(player.node, { - guildId: player.guildId, - shardId: player.shardId, - voiceId: player.voiceId || '', - textId: player.textId, - }); - }); - this.manager.on('playerDestroy', player => { - if (!player.node.driver.id.includes('nodelink')) return; - this.close(player.guildId); - }); - } - - /** unload function for make the plugin stop working */ - public unload(): void { - this.manager?.removeListener('playerCreate', () => {}); - this.manager?.removeListener('playerDestroy', () => {}); - this.manager = null; - } - - protected debug(logs: string) { - this.manager - ? this.manager.emit(RainlinkEvents.Debug, `[Rainlink] / [Plugin] / [Voice Receiver] | ${logs}`) - : true; - } -} diff --git a/src/Plugin/index.ts b/src/Plugin/index.ts deleted file mode 100644 index 2204678..0000000 --- a/src/Plugin/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { RainlinkPlugin as VoiceReceiver } from './VoiceReceiver/Plugin.js'; - -/** - * Import example: - * @example - * ```ts - * - * const { Rainlink, Plugin, Library } = require('rainlink'); - * - * const rainlink = new Rainlink( - * { - * nodes: Nodes, - * library: new Library.DiscordJS(client), - * plugins: [ - * // About voice receiver plugin: - * // This plugin only works with node use Nodelink2 driver. - * new Plugin.VoiceReceiver() - * ], - * }, - * ); - * ``` - */ - -export default { - VoiceReceiver, -}; diff --git a/src/Rainlink.ts b/src/Rainlink.ts index f4fcba0..500d10e 100644 --- a/src/Rainlink.ts +++ b/src/Rainlink.ts @@ -158,40 +158,6 @@ export declare interface Rainlink { */ on(event: 'queueEmpty', listener: (player: RainlinkPlayer, queue: RainlinkQueue) => void): this; ////// ------------------------- Queue Event ------------------------- ///// - - ////// ------------------------- Voice Event ------------------------- ///// - /** - * Emitted when connected to voice receive server [ONLY Nodelink DRIVER!!!!!!]. - * @event Rainlink#voiceConnect - */ - on(event: 'voiceConnect', listener: (node: RainlinkNode) => void): this; - /** - * Emitted when disconnected to voice receive server [ONLY Nodelink DRIVER!!!!!!]. - * @event Rainlink#voiceDisconnect - */ - on(event: 'voiceDisconnect', listener: (node: RainlinkNode, code: number, reason: Buffer) => void): this; - /** - * Emitted when voice receive server errored [ONLY Nodelink DRIVER!!!!!!]. - * @event Rainlink#VoiceError - */ - on(event: 'VoiceError', listener: (node: RainlinkNode, error: Error) => void): this; - /** - * Emitted when user started speaking [ONLY Nodelink DRIVER!!!!!!]. - * @event Rainlink#voiceStartSpeaking - */ - on( - event: 'voiceStartSpeaking', - listener: (node: RainlinkNode, userId: string, guildId: string) => void, - ): this; - /** - * Emitted when user finished speaking [ONLY Nodelink DRIVER!!!!!!]. - * @event Rainlink#voiceEndSpeaking - */ - on( - event: 'voiceEndSpeaking', - listener: (node: RainlinkNode, userTrack: string, userId: string, guildId: string) => void, - ): this; - ////// ------------------------- Voice Event ------------------------- ///// // ------------------------- ON EVENT ------------------------- // // ------------------------- ONCE EVENT ------------------------- // @@ -260,25 +226,6 @@ export declare interface Rainlink { /** @ignore */ once(event: 'queueEmpty', listener: (player: RainlinkPlayer, queue: RainlinkQueue) => void): this; ////// ------------------------- Queue Event ------------------------- ///// - - ////// ------------------------- Voice Event ------------------------- ///// - /** @ignore */ - once(event: 'voiceConnect', listener: (node: RainlinkNode) => void): this; - /** @ignore */ - once(event: 'voiceDisconnect', listener: (node: RainlinkNode, code: number, reason: Buffer) => void): this; - /** @ignore */ - once(event: 'VoiceError', listener: (node: RainlinkNode, error: Error) => void): this; - /** @ignore */ - once( - event: 'voiceStartSpeaking', - listener: (node: RainlinkNode, userId: string, guildId: string) => void, - ): this; - /** @ignore */ - once( - event: 'voiceEndSpeaking', - listener: (node: RainlinkNode, userTrack: string, userId: string, guildId: string) => void, - ): this; - ////// ------------------------- Voice Event ------------------------- ///// // ------------------------- ONCE EVENT ------------------------- // // ------------------------- OFF EVENT ------------------------- // @@ -347,25 +294,6 @@ export declare interface Rainlink { /** @ignore */ off(event: 'queueEmpty', listener: (player: RainlinkPlayer, queue: RainlinkQueue) => void): this; ////// ------------------------- Queue Event ------------------------- ///// - - ////// ------------------------- Voice Event ------------------------- ///// - /** @ignore */ - off(event: 'voiceConnect', listener: (node: RainlinkNode) => void): this; - /** @ignore */ - off(event: 'voiceDisconnect', listener: (node: RainlinkNode, code: number, reason: Buffer) => void): this; - /** @ignore */ - off(event: 'VoiceError', listener: (node: RainlinkNode, error: Error) => void): this; - /** @ignore */ - off( - event: 'voiceStartSpeaking', - listener: (node: RainlinkNode, userId: string, guildId: string) => void, - ): this; - /** @ignore */ - off( - event: 'voiceEndSpeaking', - listener: (node: RainlinkNode, userTrack: string, userId: string, guildId: string) => void, - ): this; - ////// ------------------------- Voice Event ------------------------- ///// // ------------------------- OFF EVENT ------------------------- // } diff --git a/src/index.ts b/src/index.ts index 19ca642..ed815e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ import { metadata } from './metadata'; import Library from './Library'; -import Plugin from './Plugin'; // Export main class export * from './Rainlink'; @@ -30,7 +29,6 @@ export * from './Interface/Track'; // Export plugin export * from './Plugin/RainlinkPlugin'; export * from './Plugin/SourceRainlinkPlugin'; -export { Plugin }; // Export driver export * from './Drivers/AbstractDriver'; export * from './Drivers/Lavalink3';