refactor: use eslint-config-neon for packages. (#8579)

Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
Suneet Tipirneni
2022-09-01 14:50:16 -04:00
committed by GitHub
parent 4bdb0593ae
commit edadb9fe5d
219 changed files with 2608 additions and 2053 deletions

View File

@@ -1,4 +1,5 @@
import { Readable, ReadableOptions } from 'node:stream';
import type { Buffer } from 'node:buffer';
import { Readable, type ReadableOptions } from 'node:stream';
import { SILENCE_FRAME } from '../audio/AudioPlayer';
/**
@@ -23,11 +24,11 @@ export enum EndBehaviorType {
export type EndBehavior =
| {
behavior: EndBehaviorType.Manual;
behavior: EndBehaviorType.AfterInactivity | EndBehaviorType.AfterSilence;
duration: number;
}
| {
behavior: EndBehaviorType.AfterSilence | EndBehaviorType.AfterInactivity;
duration: number;
behavior: EndBehaviorType.Manual;
};
export interface AudioReceiveStreamOptions extends ReadableOptions {
@@ -64,14 +65,13 @@ export class AudioReceiveStream extends Readable {
}
public override push(buffer: Buffer | null) {
if (buffer) {
if (
this.end.behavior === EndBehaviorType.AfterInactivity ||
if (
buffer &&
(this.end.behavior === EndBehaviorType.AfterInactivity ||
(this.end.behavior === EndBehaviorType.AfterSilence &&
(buffer.compare(SILENCE_FRAME) !== 0 || typeof this.endTimeout === 'undefined'))
) {
this.renewEndTimeout(this.end);
}
(buffer.compare(SILENCE_FRAME) !== 0 || typeof this.endTimeout === 'undefined')))
) {
this.renewEndTimeout(this.end);
}
return super.push(buffer);
@@ -81,6 +81,7 @@ export class AudioReceiveStream extends Readable {
if (this.endTimeout) {
clearTimeout(this.endTimeout);
}
this.endTimeout = setTimeout(() => this.push(null), end.duration);
}

View File

@@ -10,16 +10,16 @@ export interface VoiceUserData {
*/
audioSSRC: number;
/**
* The Discord user id of the user.
*/
userId: string;
/**
* The SSRC of the user's video stream (if one exists)
* Cannot be 0. If undefined, the user has no video stream.
*/
videoSSRC?: number;
/**
* The Discord user id of the user.
*/
userId: string;
}
export interface SSRCMap extends EventEmitter {
@@ -83,7 +83,6 @@ export class SSRCMap extends EventEmitter {
* Deletes the stored voice data about a user.
*
* @param target - The target of the delete operation, either their audio SSRC or user id
*
* @returns The data that was deleted, if any
*/
public delete(target: number | string) {
@@ -93,6 +92,7 @@ export class SSRCMap extends EventEmitter {
this.map.delete(target);
this.emit('delete', existing);
}
return existing;
}

View File

@@ -4,12 +4,14 @@ import { EventEmitter } from 'node:events';
export interface SpeakingMap extends EventEmitter {
/**
* Emitted when a user starts speaking.
*
* @eventProperty
*/
on(event: 'start', listener: (userId: string) => void): this;
/**
* Emitted when a user ends speaking.
*
* @eventProperty
*/
on(event: 'end', listener: (userId: string) => void): this;
@@ -45,6 +47,7 @@ export class SpeakingMap extends EventEmitter {
this.users.set(userId, Date.now());
this.emit('start', userId);
}
this.startTimeout(userId);
}

View File

@@ -1,14 +1,16 @@
/* eslint-disable jsdoc/check-param-names */
import { Buffer } from 'node:buffer';
import { VoiceOpcodes } from 'discord-api-types/voice/v4';
import {
AudioReceiveStream,
AudioReceiveStreamOptions,
createDefaultAudioReceiveStreamOptions,
} from './AudioReceiveStream';
import { SSRCMap } from './SSRCMap';
import { SpeakingMap } from './SpeakingMap';
import type { VoiceConnection } from '../VoiceConnection';
import type { ConnectionData } from '../networking/Networking';
import { methods } from '../util/Secretbox';
import {
AudioReceiveStream,
createDefaultAudioReceiveStreamOptions,
type AudioReceiveStreamOptions,
} from './AudioReceiveStream';
import { SSRCMap } from './SSRCMap';
import { SpeakingMap } from './SpeakingMap';
/**
* Attaches to a VoiceConnection, allowing you to receive audio packets from other
@@ -59,7 +61,6 @@ export class VoiceReceiver {
* Called when a packet is received on the attached connection's WebSocket.
*
* @param packet - The received packet
*
* @internal
*/
public onWsPacket(packet: any) {
@@ -112,6 +113,7 @@ export class VoiceReceiver {
// Open packet
const decrypted = methods.open(buffer.slice(12, end), nonce, secretKey);
if (!decrypted) return;
// eslint-disable-next-line consistent-return
return Buffer.from(decrypted);
}
@@ -122,7 +124,6 @@ export class VoiceReceiver {
* @param mode - The encryption mode
* @param nonce - The nonce buffer used by the connection for encryption
* @param secretKey - The secret key used by the connection for encryption
*
* @returns The parsed Opus packet
*/
private parsePacket(buffer: Buffer, mode: string, nonce: Buffer, secretKey: Uint8Array) {
@@ -135,6 +136,7 @@ export class VoiceReceiver {
packet = packet.subarray(4 + 4 * headerExtensionLength);
}
// eslint-disable-next-line consistent-return
return packet;
}
@@ -142,7 +144,6 @@ export class VoiceReceiver {
* Called when the UDP socket of the attached connection receives a message.
*
* @param msg - The received message
*
* @internal
*/
public onUdpMessage(msg: Buffer) {
@@ -176,7 +177,6 @@ export class VoiceReceiver {
* Creates a subscription for the given user id.
*
* @param target - The id of the user to subscribe to
*
* @returns A readable stream of Opus packets received from the target
*/
public subscribe(userId: string, options?: Partial<AudioReceiveStreamOptions>) {