@discordjs/voice
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
import { PlayerSubscription } from './PlayerSubscription'; | ||
import TypedEmitter from 'typed-emitter'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
export declare const SILENCE_FRAME: Buffer; | ||
@@ -135,3 +135,2 @@ /** | ||
}; | ||
declare const AudioPlayer_base: new () => TypedEmitter<AudioPlayerEvents>; | ||
/** | ||
@@ -147,3 +146,3 @@ * Used to play audio resources (i.e. tracks, streams) to voice connections. | ||
*/ | ||
export declare class AudioPlayer extends AudioPlayer_base { | ||
export declare class AudioPlayer extends TypedEmitter<AudioPlayerEvents> { | ||
/** | ||
@@ -272,3 +271,2 @@ * The state that the AudioPlayer is in | ||
export declare function createAudioPlayer(options?: CreateAudioPlayerOptions): AudioPlayer; | ||
export {}; | ||
//# sourceMappingURL=AudioPlayer.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createAudioPlayer = exports.AudioPlayer = exports.AudioPlayerStatus = exports.NoSubscriberBehavior = exports.SILENCE_FRAME = void 0; | ||
const events_1 = require("events"); | ||
const DataStore_1 = require("../DataStore"); | ||
@@ -10,2 +9,3 @@ const util_1 = require("../util/util"); | ||
const PlayerSubscription_1 = require("./PlayerSubscription"); | ||
const tiny_typed_emitter_1 = require("tiny-typed-emitter"); | ||
// The Opus "silent" frame | ||
@@ -65,3 +65,3 @@ exports.SILENCE_FRAME = Buffer.from([0xf8, 0xff, 0xfe]); | ||
*/ | ||
class AudioPlayer extends events_1.EventEmitter { | ||
class AudioPlayer extends tiny_typed_emitter_1.TypedEmitter { | ||
/** | ||
@@ -68,0 +68,0 @@ * Creates a new AudioPlayer |
/// <reference types="node" /> | ||
import { Edge, StreamType } from './TransformerGraph'; | ||
import { Readable } from 'stream'; | ||
import { VolumeTransformer } from 'prism-media'; | ||
import { VolumeTransformer, opus } from 'prism-media'; | ||
import type { AudioPlayer } from './AudioPlayer'; | ||
@@ -43,7 +43,7 @@ /** | ||
*/ | ||
readonly pipeline: Edge[]; | ||
readonly edges: readonly Edge[]; | ||
/** | ||
* Optional metadata that can be used to identify the resource. | ||
*/ | ||
metadata?: T; | ||
metadata: T; | ||
/** | ||
@@ -55,2 +55,7 @@ * If the resource was created with inline volume transformation enabled, then this will be a | ||
/** | ||
* If using an Opus encoder to create this audio resource, then this will be a prism-media opus.Encoder. | ||
* You can use this to control settings such as bitrate, FEC, PLP. | ||
*/ | ||
readonly encoder?: opus.Encoder; | ||
/** | ||
* The audio player that the resource is subscribed to, if any. | ||
@@ -67,3 +72,3 @@ */ | ||
started: boolean; | ||
constructor(pipeline: Edge[], playStream: Readable, metadata?: T, volume?: VolumeTransformer); | ||
constructor(edges: readonly Edge[], streams: readonly Readable[], metadata: T); | ||
/** | ||
@@ -111,4 +116,4 @@ * Attempts to read an Opus packet from the audio resource. If a packet is available, the playbackDuration | ||
*/ | ||
export declare function createAudioResource<T>(input: string | Readable, options?: CreateAudioResourceOptions<T>): AudioResource<T>; | ||
export declare function createAudioResource<T>(input: string | Readable, options?: CreateAudioResourceOptions<T>): AudioResource<T | null>; | ||
export {}; | ||
//# sourceMappingURL=AudioResource.d.ts.map |
@@ -14,3 +14,3 @@ "use strict"; | ||
class AudioResource { | ||
constructor(pipeline, playStream, metadata, volume) { | ||
constructor(edges, streams, metadata) { | ||
/** | ||
@@ -24,6 +24,13 @@ * The playback duration of this audio resource, given in milliseconds. | ||
this.started = false; | ||
this.pipeline = pipeline; | ||
this.playStream = playStream; | ||
this.edges = edges; | ||
this.playStream = streams.length > 1 ? stream_1.pipeline(streams, util_1.noop) : streams[0]; | ||
this.metadata = metadata; | ||
this.volume = volume; | ||
for (const stream of streams) { | ||
if (stream instanceof prism_media_1.VolumeTransformer) { | ||
this.volume = stream; | ||
} | ||
else if (stream instanceof prism_media_1.opus.Encoder) { | ||
this.encoder = stream; | ||
} | ||
} | ||
stream_1.once(this.playStream, 'readable') | ||
@@ -100,2 +107,3 @@ .then(() => (this.started = true)) | ||
function createAudioResource(input, options = {}) { | ||
var _a, _b; | ||
let inputType = options.inputType; | ||
@@ -117,3 +125,3 @@ let needsInlineVolume = Boolean(options.inlineVolume); | ||
// No adjustments required | ||
return new AudioResource([], input, options.metadata); | ||
return new AudioResource([], [input], (_a = options.metadata) !== null && _a !== void 0 ? _a : null); | ||
} | ||
@@ -123,9 +131,5 @@ const streams = transformerPipeline.map((edge) => edge.transformer(input)); | ||
streams.unshift(input); | ||
// the callback is called once the stream ends | ||
const playStream = streams.length > 1 ? stream_1.pipeline(streams, util_1.noop) : streams[0]; | ||
// attempt to find the volume transformer in the pipeline (if one exists) | ||
const volume = streams.find((stream) => stream instanceof prism_media_1.VolumeTransformer); | ||
return new AudioResource(transformerPipeline, playStream, options.metadata, volume); | ||
return new AudioResource(transformerPipeline, streams, (_b = options.metadata) !== null && _b !== void 0 ? _b : null); | ||
} | ||
exports.createAudioResource = createAudioResource; | ||
//# sourceMappingURL=AudioResource.js.map |
/// <reference types="node" /> | ||
import { VoiceUDPSocket } from './VoiceUDPSocket'; | ||
import { VoiceWebSocket } from './VoiceWebSocket'; | ||
import TypedEmitter from 'typed-emitter'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
export declare const SUPPORTED_ENCRYPTION_MODES: string[]; | ||
@@ -126,7 +126,6 @@ /** | ||
} | ||
declare const Networking_base: new () => TypedEmitter<NetworkingEvents>; | ||
/** | ||
* Manages the networking required to maintain a voice connection and dispatch audio packets | ||
*/ | ||
export declare class Networking extends Networking_base { | ||
export declare class Networking extends TypedEmitter<NetworkingEvents> { | ||
private _state; | ||
@@ -133,0 +132,0 @@ /** |
@@ -23,3 +23,2 @@ "use strict"; | ||
exports.Networking = exports.NetworkingStatusCode = exports.SUPPORTED_ENCRYPTION_MODES = void 0; | ||
const events_1 = require("events"); | ||
const VoiceUDPSocket_1 = require("./VoiceUDPSocket"); | ||
@@ -29,2 +28,3 @@ const VoiceWebSocket_1 = require("./VoiceWebSocket"); | ||
const util_1 = require("../util/util"); | ||
const tiny_typed_emitter_1 = require("tiny-typed-emitter"); | ||
// The number of audio channels required by Discord | ||
@@ -57,3 +57,3 @@ const CHANNELS = 2; | ||
*/ | ||
class Networking extends events_1.EventEmitter { | ||
class Networking extends tiny_typed_emitter_1.TypedEmitter { | ||
/** | ||
@@ -60,0 +60,0 @@ * Creates a new Networking instance. |
/// <reference types="node" /> | ||
import TypedEmitter from 'typed-emitter'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
/** | ||
@@ -17,7 +17,6 @@ * Stores an IP address and port. Used to store socket details for the local client as well as | ||
} | ||
declare const VoiceUDPSocket_base: new () => TypedEmitter<VoiceUDPSocketEvents>; | ||
/** | ||
* Manages the UDP networking for a voice connection. | ||
*/ | ||
export declare class VoiceUDPSocket extends VoiceUDPSocket_base { | ||
export declare class VoiceUDPSocket extends TypedEmitter<VoiceUDPSocketEvents> { | ||
/** | ||
@@ -93,3 +92,2 @@ * The underlying network Socket for the VoiceUDPSocket. | ||
export declare function parseLocalPacket(message: Buffer): SocketConfig; | ||
export {}; | ||
//# sourceMappingURL=VoiceUDPSocket.d.ts.map |
@@ -5,4 +5,4 @@ "use strict"; | ||
const dgram_1 = require("dgram"); | ||
const events_1 = require("events"); | ||
const net_1 = require("net"); | ||
const tiny_typed_emitter_1 = require("tiny-typed-emitter"); | ||
/** | ||
@@ -23,3 +23,3 @@ * The interval in milliseconds at which keep alive datagrams are sent | ||
*/ | ||
class VoiceUDPSocket extends events_1.EventEmitter { | ||
class VoiceUDPSocket extends tiny_typed_emitter_1.TypedEmitter { | ||
/** | ||
@@ -26,0 +26,0 @@ * Creates a new VoiceUDPSocket. |
import WebSocket, { MessageEvent } from 'ws'; | ||
import TypedEmitter from 'typed-emitter'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
/** | ||
@@ -16,3 +16,2 @@ * Debug event for VoiceWebSocket. | ||
} | ||
declare const VoiceWebSocket_base: new () => TypedEmitter<VoiceWebSocketEvents>; | ||
/** | ||
@@ -22,3 +21,3 @@ * An extension of the WebSocket class to provide helper functionality when interacting | ||
*/ | ||
export declare class VoiceWebSocket extends VoiceWebSocket_base { | ||
export declare class VoiceWebSocket extends TypedEmitter<VoiceWebSocketEvents> { | ||
/** | ||
@@ -88,3 +87,2 @@ * The current heartbeat interval, if any | ||
} | ||
export {}; | ||
//# sourceMappingURL=VoiceWebSocket.d.ts.map |
@@ -7,4 +7,4 @@ "use strict"; | ||
exports.VoiceWebSocket = void 0; | ||
const events_1 = __importDefault(require("events")); | ||
const ws_1 = __importDefault(require("ws")); | ||
const tiny_typed_emitter_1 = require("tiny-typed-emitter"); | ||
/** | ||
@@ -14,3 +14,3 @@ * An extension of the WebSocket class to provide helper functionality when interacting | ||
*/ | ||
class VoiceWebSocket extends events_1.default { | ||
class VoiceWebSocket extends tiny_typed_emitter_1.TypedEmitter { | ||
/** | ||
@@ -17,0 +17,0 @@ * Creates a new VoiceWebSocket |
@@ -1,2 +0,2 @@ | ||
import TypedEmitter from 'typed-emitter'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
/** | ||
@@ -27,7 +27,6 @@ * The known data for a user in a Discord voice connection | ||
} | ||
declare const SSRCMap_base: new () => TypedEmitter<SSRCMapEvents>; | ||
/** | ||
* Maps audio SSRCs to data of users in voice connections. | ||
*/ | ||
export declare class SSRCMap extends SSRCMap_base { | ||
export declare class SSRCMap extends TypedEmitter<SSRCMapEvents> { | ||
/** | ||
@@ -58,3 +57,2 @@ * The underlying map | ||
} | ||
export {}; | ||
//# sourceMappingURL=SSRCMap.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SSRCMap = void 0; | ||
const events_1 = __importDefault(require("events")); | ||
const tiny_typed_emitter_1 = require("tiny-typed-emitter"); | ||
/** | ||
* Maps audio SSRCs to data of users in voice connections. | ||
*/ | ||
class SSRCMap extends events_1.default { | ||
class SSRCMap extends tiny_typed_emitter_1.TypedEmitter { | ||
constructor() { | ||
@@ -13,0 +10,0 @@ super(); |
@@ -8,3 +8,3 @@ /// <reference types="node" /> | ||
import { Networking } from './networking/Networking'; | ||
import TypedEmitter from 'typed-emitter'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
/** | ||
@@ -126,7 +126,6 @@ * The various status codes a voice connection can hold at any one time. | ||
}; | ||
declare const VoiceConnection_base: new () => TypedEmitter<VoiceConnectionEvents>; | ||
/** | ||
* A connection to the voice server of a Guild, can be used to play audio in voice channels. | ||
*/ | ||
export declare class VoiceConnection extends VoiceConnection_base { | ||
export declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> { | ||
/** | ||
@@ -302,3 +301,2 @@ * The number of consecutive reconnect attempts. Initially 0, and increments for each reconnect. | ||
export declare function createVoiceConnection(joinConfig: JoinConfig, options: CreateVoiceConnectionOptions): VoiceConnection; | ||
export {}; | ||
//# sourceMappingURL=VoiceConnection.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createVoiceConnection = exports.VoiceConnection = exports.VoiceConnectionDisconnectReason = exports.VoiceConnectionStatus = void 0; | ||
const events_1 = require("events"); | ||
const DataStore_1 = require("./DataStore"); | ||
const Networking_1 = require("./networking/Networking"); | ||
const util_1 = require("./util/util"); | ||
const tiny_typed_emitter_1 = require("tiny-typed-emitter"); | ||
/** | ||
@@ -55,3 +55,3 @@ * The various status codes a voice connection can hold at any one time. | ||
*/ | ||
class VoiceConnection extends events_1.EventEmitter { | ||
class VoiceConnection extends tiny_typed_emitter_1.TypedEmitter { | ||
/** | ||
@@ -58,0 +58,0 @@ * Creates a new voice connection. |
{ | ||
"name": "@discordjs/voice", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "audio streaming capability for discord.js", | ||
@@ -42,28 +42,28 @@ "main": "dist/index.js", | ||
"prism-media": "^1.2.9", | ||
"ws": "^7.4.4" | ||
"ws": "^7.4.4", | ||
"tiny-typed-emitter": "^2.0.3", | ||
"discord-api-types": "^0.18.1", | ||
"@types/ws": "^7.4.4" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.13.8", | ||
"@babel/preset-env": "^7.13.9", | ||
"@babel/core": "^7.14.3", | ||
"@babel/preset-env": "^7.14.4", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-angular": "^11.0.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.25", | ||
"@types/ws": "^7.4.0", | ||
"@typescript-eslint/eslint-plugin": "^4.14.2", | ||
"@typescript-eslint/parser": "^4.14.2", | ||
"babel-jest": "^26.6.3", | ||
"discord-api-types": "^0.15.1", | ||
"eslint": "^7.20.0", | ||
"eslint-config-marine": "^8.1.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"@commitlint/cli": "^12.1.4", | ||
"@commitlint/config-angular": "^12.1.4", | ||
"@types/jest": "^26.0.23", | ||
"@types/node": "^15.12.2", | ||
"@typescript-eslint/eslint-plugin": "^4.26.1", | ||
"@typescript-eslint/parser": "^4.26.1", | ||
"babel-jest": "^27.0.2", | ||
"eslint": "^7.28.0", | ||
"eslint-config-marine": "^9.0.6", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"husky": "^4.3.8", | ||
"jest": "^26.6.3", | ||
"jest": "^27.0.4", | ||
"jest-websocket-mock": "^2.2.0", | ||
"lint-staged": "^10.5.4", | ||
"lint-staged": "^11.0.0", | ||
"mock-socket": "^9.0.3", | ||
"prettier": "^2.2.1", | ||
"typed-emitter": "^1.3.1", | ||
"prettier": "^2.3.1", | ||
"typedoc": "^0.20.34", | ||
@@ -70,0 +70,0 @@ "typescript": "~4.2.2" |
# @discordjs/voice | ||
<p> | ||
<a href="https://discord.gg/bRCvFy9"><img src="https://img.shields.io/discord/222078108977594368?color=7289da&logo=discord&logoColor=white" alt="Discord server" /></a> | ||
<a href="https://discord.gg/bRCvFy9"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a> | ||
<a href="https://www.npmjs.com/package/@discordjs/voice"><img src="https://img.shields.io/npm/v/@discordjs/voice.svg?maxAge=3600" alt="NPM version" /></a> | ||
@@ -12,8 +12,23 @@ <a href="https://www.npmjs.com/package/@discordjs/voice"><img src="https://img.shields.io/npm/dt/@discordjs/voice.svg?maxAge=3600" alt="NPM downloads" /></a> | ||
> Provides audio streaming functionality to Discord.js | ||
## About | ||
## Status: alpha | ||
An implementation of the Discord Voice API for Node.js, written in TypeScript. | ||
> This library is still in development - the API is subject to change! | ||
**Features:** | ||
- Send and receive* audio in Discord voice-based channels | ||
- A strong focus on reliability and predictable behaviour | ||
- Horizontal scalability and libraries other than [discord.js](https://discord.js.org/) are supported with custom adapters | ||
- A robust audio processing system that can handle a wide range of audio sources | ||
\**Audio receive is not documented by Discord so complete support is not guaranteed* | ||
**Useful links:** | ||
- [Documentation](https://discordjs.github.io/voice) | ||
- [Examples](https://github.com/discordjs/voice/tree/main/examples) | ||
- [GitHub Discussions](https://github.com/discordjs/voice/discussions) | ||
- [Discord.js Server](https://discord.gg/djs) | ||
- [Repository](https://github.com/discordjs/voice) | ||
## Dependencies | ||
@@ -20,0 +35,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
485292
22
60
5
4217
+ Added@types/ws@^7.4.4
+ Addeddiscord-api-types@^0.18.1
+ Addedtiny-typed-emitter@^2.0.3
+ Added@types/node@22.10.2(transitive)
+ Added@types/ws@7.4.7(transitive)
+ Addeddiscord-api-types@0.18.1(transitive)
+ Addedtiny-typed-emitter@2.1.0(transitive)
+ Addedundici-types@6.20.0(transitive)