35 lines
No EOL
1.1 KiB
TypeScript
35 lines
No EOL
1.1 KiB
TypeScript
import {AudioLibrary} from "tc-backend/web/audio-lib/index";
|
|
import {LogCategory, logWarn} from "tc-shared/log";
|
|
|
|
export class AudioClient {
|
|
private readonly handle: AudioLibrary;
|
|
private readonly clientId: number;
|
|
public callback_decoded: (buffer: AudioBuffer) => void;
|
|
public callback_ended: () => void;
|
|
|
|
constructor(handle: AudioLibrary, clientId: number) {
|
|
this.handle = handle;
|
|
this.clientId = clientId;
|
|
}
|
|
|
|
async initialize() { }
|
|
|
|
destroy() {
|
|
this.handle.destroyClient(this.clientId);
|
|
}
|
|
|
|
enqueueBuffer(buffer: Uint8Array, packetId: number, codec: number) {
|
|
this.handle.getWorker().executeThrow("enqueue-audio-packet", {
|
|
clientId: this.clientId,
|
|
|
|
codec: codec,
|
|
packetId: packetId,
|
|
|
|
buffer: buffer.buffer,
|
|
byteLength: buffer.byteLength,
|
|
byteOffset: buffer.byteOffset,
|
|
}, 5000, [buffer.buffer]).catch(error => {
|
|
logWarn(LogCategory.AUDIO, tr("Failed to enqueue audio buffer for audio client %d: %o"), this.clientId, error);
|
|
});
|
|
}
|
|
} |