@discordjs/voice
Advanced tools
Comparing version 0.3.1 to 0.4.0
/// <reference types="node" /> | ||
import { Awaited } from '../util/util'; | ||
import { VoiceConnection } from '../VoiceConnection'; | ||
@@ -126,9 +127,9 @@ import { AudioPlayerError } from './AudioPlayerError'; | ||
export declare type AudioPlayerEvents = { | ||
error: (error: AudioPlayerError) => void; | ||
debug: (message: string) => void; | ||
stateChange: (oldState: AudioPlayerState, newState: AudioPlayerState) => void; | ||
subscribe: (subscription: PlayerSubscription) => void; | ||
unsubscribe: (subscription: PlayerSubscription) => void; | ||
error: (error: AudioPlayerError) => Awaited<void>; | ||
debug: (message: string) => Awaited<void>; | ||
stateChange: (oldState: AudioPlayerState, newState: AudioPlayerState) => Awaited<void>; | ||
subscribe: (subscription: PlayerSubscription) => Awaited<void>; | ||
unsubscribe: (subscription: PlayerSubscription) => Awaited<void>; | ||
} & { | ||
[status in AudioPlayerStatus]: (oldState: AudioPlayerState, newState: AudioPlayerState) => void; | ||
[status in AudioPlayerStatus]: (oldState: AudioPlayerState, newState: AudioPlayerState) => Awaited<void>; | ||
}; | ||
@@ -229,7 +230,9 @@ /** | ||
/** | ||
* Stops playback of the current resource and destroys the resource. The player will transition to the Idle state. | ||
* Stops playback of the current resource and destroys the resource. The player will either transition to the Idle state, | ||
* or remain in its current state until the silence padding frames of the resource have been played. | ||
* | ||
* @returns true if the player was successfully stopped, otherwise false. | ||
* @param force - If true, will force the player to enter the Idle state even if the resource has silence padding frames. | ||
* @returns true if the player will come to a stop, otherwise false. | ||
*/ | ||
stop(): boolean; | ||
stop(force?: boolean): boolean; | ||
/** | ||
@@ -236,0 +239,0 @@ * Checks whether the underlying resource (if any) is playable (readable). |
@@ -193,3 +193,3 @@ "use strict"; | ||
play(resource) { | ||
if (resource.playStream.readableEnded || resource.playStream.destroyed) { | ||
if (resource.ended) { | ||
throw new Error('Cannot play a resource that has already ended.'); | ||
@@ -296,12 +296,19 @@ } | ||
/** | ||
* Stops playback of the current resource and destroys the resource. The player will transition to the Idle state. | ||
* Stops playback of the current resource and destroys the resource. The player will either transition to the Idle state, | ||
* or remain in its current state until the silence padding frames of the resource have been played. | ||
* | ||
* @returns true if the player was successfully stopped, otherwise false. | ||
* @param force - If true, will force the player to enter the Idle state even if the resource has silence padding frames. | ||
* @returns true if the player will come to a stop, otherwise false. | ||
*/ | ||
stop() { | ||
stop(force = false) { | ||
if (this.state.status === AudioPlayerStatus.Idle) | ||
return false; | ||
this.state = { | ||
status: AudioPlayerStatus.Idle, | ||
}; | ||
if (force || this.state.resource.silencePaddingFrames === 0) { | ||
this.state = { | ||
status: AudioPlayerStatus.Idle, | ||
}; | ||
} | ||
else if (this.state.resource.silenceRemaining === -1) { | ||
this.state.resource.silenceRemaining = this.state.resource.silencePaddingFrames; | ||
} | ||
return true; | ||
@@ -319,3 +326,3 @@ } | ||
// If the stream has been destroyed or is no longer readable, then transition to the Idle state. | ||
if (!state.resource.playStream.readable) { | ||
if (!state.resource.readable) { | ||
this.state = { | ||
@@ -384,3 +391,3 @@ status: AudioPlayerStatus.Idle, | ||
else if (this.behaviors.noSubscriber === NoSubscriberBehavior.Stop) { | ||
this.stop(); | ||
this.stop(true); | ||
} | ||
@@ -387,0 +394,0 @@ } |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import { VolumeTransformer, opus } from 'prism-media'; | ||
import type { AudioPlayer } from './AudioPlayer'; | ||
import { AudioPlayer } from './AudioPlayer'; | ||
/** | ||
@@ -28,2 +28,7 @@ * Options that are set when creating a new audio resource. | ||
inlineVolume?: boolean; | ||
/** | ||
* The number of silence frames to append to the end of the resource's audio stream, to prevent interpolation glitches. | ||
* Defaults to 5. | ||
*/ | ||
silencePaddingFrames?: number; | ||
} | ||
@@ -72,4 +77,21 @@ /** | ||
started: boolean; | ||
constructor(edges: readonly Edge[], streams: readonly Readable[], metadata: T); | ||
/** | ||
* The number of silence frames to append to the end of the resource's audio stream, to prevent interpolation glitches. | ||
*/ | ||
readonly silencePaddingFrames: number; | ||
/** | ||
* The number of remaining silence frames to play. If -1, the frames have not yet started playing. | ||
*/ | ||
silenceRemaining: number; | ||
constructor(edges: readonly Edge[], streams: readonly Readable[], metadata: T, silencePaddingFrames: number); | ||
/** | ||
* Whether this resource is readable. If the underlying resource is no longer readable, this will still return true | ||
* while there are silence padding frames left to play. | ||
*/ | ||
get readable(): boolean; | ||
/** | ||
* Whether this resource has ended or not. | ||
*/ | ||
get ended(): boolean; | ||
/** | ||
* Attempts to read an Opus packet from the audio resource. If a packet is available, the playbackDuration | ||
@@ -76,0 +98,0 @@ * is incremented. |
@@ -8,2 +8,3 @@ "use strict"; | ||
const prism_media_1 = require("prism-media"); | ||
const AudioPlayer_1 = require("./AudioPlayer"); | ||
/** | ||
@@ -15,3 +16,3 @@ * Represents an audio resource that can be played by an audio player. | ||
class AudioResource { | ||
constructor(edges, streams, metadata) { | ||
constructor(edges, streams, metadata, silencePaddingFrames) { | ||
/** | ||
@@ -25,5 +26,10 @@ * The playback duration of this audio resource, given in milliseconds. | ||
this.started = false; | ||
/** | ||
* The number of remaining silence frames to play. If -1, the frames have not yet started playing. | ||
*/ | ||
this.silenceRemaining = -1; | ||
this.edges = edges; | ||
this.playStream = streams.length > 1 ? stream_1.pipeline(streams, util_1.noop) : streams[0]; | ||
this.metadata = metadata; | ||
this.silencePaddingFrames = silencePaddingFrames; | ||
for (const stream of streams) { | ||
@@ -42,2 +48,23 @@ if (stream instanceof prism_media_1.VolumeTransformer) { | ||
/** | ||
* Whether this resource is readable. If the underlying resource is no longer readable, this will still return true | ||
* while there are silence padding frames left to play. | ||
*/ | ||
get readable() { | ||
if (this.silenceRemaining === 0) | ||
return false; | ||
const real = this.playStream.readable; | ||
if (!real) { | ||
if (this.silenceRemaining === -1) | ||
this.silenceRemaining = this.silencePaddingFrames; | ||
return this.silenceRemaining !== 0; | ||
} | ||
return real; | ||
} | ||
/** | ||
* Whether this resource has ended or not. | ||
*/ | ||
get ended() { | ||
return this.playStream.readableEnded || this.playStream.destroyed || this.silenceRemaining === 0; | ||
} | ||
/** | ||
* Attempts to read an Opus packet from the audio resource. If a packet is available, the playbackDuration | ||
@@ -52,2 +79,9 @@ * is incremented. | ||
read() { | ||
if (this.silenceRemaining === 0) { | ||
return null; | ||
} | ||
else if (this.silenceRemaining > 0) { | ||
this.silenceRemaining--; | ||
return AudioPlayer_1.SILENCE_FRAME; | ||
} | ||
const packet = this.playStream.read(); | ||
@@ -110,3 +144,3 @@ if (packet) { | ||
function createAudioResource(input, options = {}) { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
let inputType = options.inputType; | ||
@@ -128,3 +162,3 @@ let needsInlineVolume = Boolean(options.inlineVolume); | ||
// No adjustments required | ||
return new AudioResource([], [input], ((_a = options.metadata) !== null && _a !== void 0 ? _a : null)); | ||
return new AudioResource([], [input], ((_a = options.metadata) !== null && _a !== void 0 ? _a : null), (_b = options.silencePaddingFrames) !== null && _b !== void 0 ? _b : 5); | ||
} | ||
@@ -134,5 +168,5 @@ const streams = transformerPipeline.map((edge) => edge.transformer(input)); | ||
streams.unshift(input); | ||
return new AudioResource(transformerPipeline, streams, ((_b = options.metadata) !== null && _b !== void 0 ? _b : null)); | ||
return new AudioResource(transformerPipeline, streams, ((_c = options.metadata) !== null && _c !== void 0 ? _c : null), (_d = options.silencePaddingFrames) !== null && _d !== void 0 ? _d : 5); | ||
} | ||
exports.createAudioResource = createAudioResource; | ||
//# sourceMappingURL=AudioResource.js.map |
@@ -5,4 +5,4 @@ export * from './joinVoiceChannel'; | ||
export * from './receive'; | ||
export { VoiceConnection, VoiceConnectionState, VoiceConnectionStatus, VoiceConnectionConnectingState, VoiceConnectionDestroyedState, VoiceConnectionDisconnectedState, VoiceConnectionDisconnectedBaseState, VoiceConnectionDisconnectedWebSocketState, VoiceConnectionDisconnectReason, VoiceConnectionReadyState, VoiceConnectionSignallingState, VoiceConnectionEvents, } from './VoiceConnection'; | ||
export { VoiceConnection, VoiceConnectionState, VoiceConnectionStatus, VoiceConnectionConnectingState, VoiceConnectionDestroyedState, VoiceConnectionDisconnectedState, VoiceConnectionDisconnectedBaseState, VoiceConnectionDisconnectedOtherState, VoiceConnectionDisconnectedWebSocketState, VoiceConnectionDisconnectReason, VoiceConnectionReadyState, VoiceConnectionSignallingState, VoiceConnectionEvents, } from './VoiceConnection'; | ||
export { getVoiceConnection } from './DataStore'; | ||
//# sourceMappingURL=index.d.ts.map |
/// <reference types="node" /> | ||
import { VoiceUDPSocket } from './VoiceUDPSocket'; | ||
import { VoiceWebSocket } from './VoiceWebSocket'; | ||
import { Awaited } from '../util/util'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
@@ -121,6 +122,6 @@ export declare const SUPPORTED_ENCRYPTION_MODES: string[]; | ||
export interface NetworkingEvents { | ||
debug: (message: string) => void; | ||
error: (error: Error) => void; | ||
stateChange: (oldState: NetworkingState, newState: NetworkingState) => void; | ||
close: (code: number) => void; | ||
debug: (message: string) => Awaited<void>; | ||
error: (error: Error) => Awaited<void>; | ||
stateChange: (oldState: NetworkingState, newState: NetworkingState) => Awaited<void>; | ||
close: (code: number) => Awaited<void>; | ||
} | ||
@@ -127,0 +128,0 @@ /** |
/// <reference types="node" /> | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
import { Awaited } from '../util/util'; | ||
/** | ||
@@ -12,6 +13,6 @@ * Stores an IP address and port. Used to store socket details for the local client as well as | ||
export interface VoiceUDPSocketEvents { | ||
error: (error: Error) => void; | ||
close: () => void; | ||
debug: (message: string) => void; | ||
message: (message: Buffer) => void; | ||
error: (error: Error) => Awaited<void>; | ||
close: () => Awaited<void>; | ||
debug: (message: string) => Awaited<void>; | ||
message: (message: Buffer) => Awaited<void>; | ||
} | ||
@@ -18,0 +19,0 @@ /** |
import WebSocket, { MessageEvent } from 'ws'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
import { Awaited } from '../util/util'; | ||
/** | ||
@@ -10,7 +11,7 @@ * Debug event for VoiceWebSocket. | ||
export interface VoiceWebSocketEvents { | ||
error: (error: Error) => void; | ||
open: (event: WebSocket.OpenEvent) => void; | ||
close: (event: WebSocket.CloseEvent) => void; | ||
debug: (message: string) => void; | ||
packet: (packet: any) => void; | ||
error: (error: Error) => Awaited<void>; | ||
open: (event: WebSocket.OpenEvent) => Awaited<void>; | ||
close: (event: WebSocket.CloseEvent) => Awaited<void>; | ||
debug: (message: string) => Awaited<void>; | ||
packet: (packet: any) => Awaited<void>; | ||
} | ||
@@ -17,0 +18,0 @@ /** |
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
import { Awaited } from '../util/util'; | ||
/** | ||
@@ -24,4 +25,4 @@ * The known data for a user in a Discord voice connection | ||
export interface SSRCMapEvents { | ||
update: (oldData: VoiceUserData | undefined, newData: VoiceUserData) => void; | ||
delete: (deletedData: VoiceUserData) => void; | ||
update: (oldData: VoiceUserData | undefined, newData: VoiceUserData) => Awaited<void>; | ||
delete: (deletedData: VoiceUserData) => Awaited<void>; | ||
} | ||
@@ -28,0 +29,0 @@ /** |
export * from './generateDependencyReport'; | ||
export * from './entersState'; | ||
export * from './adapter'; | ||
export * from './demuxProbe'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -16,2 +16,3 @@ "use strict"; | ||
__exportStar(require("./adapter"), exports); | ||
__exportStar(require("./demuxProbe"), exports); | ||
//# sourceMappingURL=index.js.map |
export declare const noop: () => void; | ||
export declare type Awaited<T> = T | Promise<T>; | ||
//# sourceMappingURL=util.d.ts.map |
@@ -8,2 +8,3 @@ /// <reference types="node" /> | ||
import { Networking } from './networking/Networking'; | ||
import { Awaited } from './util/util'; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
@@ -67,3 +68,2 @@ /** | ||
status: VoiceConnectionStatus.Disconnected; | ||
reason: VoiceConnectionDisconnectReason; | ||
subscription?: PlayerSubscription; | ||
@@ -73,2 +73,9 @@ adapter: DiscordGatewayAdapterImplementerMethods; | ||
/** | ||
* The state that a VoiceConnection will be in when it is not connected to a Discord voice server nor is | ||
* it attempting to connect. You can manually attempt to reconnect using VoiceConnection#reconnect. | ||
*/ | ||
export interface VoiceConnectionDisconnectedOtherState extends VoiceConnectionDisconnectedBaseState { | ||
reason: Exclude<VoiceConnectionDisconnectReason, VoiceConnectionDisconnectReason.WebSocketClose>; | ||
} | ||
/** | ||
* The state that a VoiceConnection will be in when its WebSocket connection was closed. | ||
@@ -88,3 +95,3 @@ * You can manually attempt to reconnect using VoiceConnection#reconnect. | ||
*/ | ||
export declare type VoiceConnectionDisconnectedState = VoiceConnectionDisconnectedBaseState | VoiceConnectionDisconnectedWebSocketState; | ||
export declare type VoiceConnectionDisconnectedState = VoiceConnectionDisconnectedOtherState | VoiceConnectionDisconnectedWebSocketState; | ||
/** | ||
@@ -123,7 +130,7 @@ * The state that a VoiceConnection will be in when it is establishing a connection to a Discord | ||
export declare type VoiceConnectionEvents = { | ||
error: (error: Error) => void; | ||
debug: (message: string) => void; | ||
stateChange: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => void; | ||
error: (error: Error) => Awaited<void>; | ||
debug: (message: string) => Awaited<void>; | ||
stateChange: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => Awaited<void>; | ||
} & { | ||
[status in VoiceConnectionStatus]: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => void; | ||
[status in VoiceConnectionStatus]: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => Awaited<void>; | ||
}; | ||
@@ -130,0 +137,0 @@ /** |
{ | ||
"name": "@discordjs/voice", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Implementation of the Discord Voice API for Node.js", | ||
@@ -43,3 +43,3 @@ "main": "dist/index.js", | ||
"discord-api-types": "^0.18.1", | ||
"prism-media": "^1.2.9", | ||
"prism-media": "^1.3.1", | ||
"tiny-typed-emitter": "^2.0.3", | ||
@@ -46,0 +46,0 @@ "ws": "^7.4.4" |
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
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
507023
104
4404
Updatedprism-media@^1.3.1