Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Blob to be passed directly when sending audio buffer #3

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/realtime/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class WebSocketWrapper implements ISocketWrapper {
});
}

sendAudioBuffer(buffer: ArrayBufferLike): void {
sendAudioBuffer(buffer: ArrayBufferLike | Blob): void {
if (this.socket && this.isOpen()) {
this.socket.send(buffer);
} else console.error('Tried to send audio when socket was closed');
Expand Down
9 changes: 7 additions & 2 deletions src/realtime/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ export class NodeWebSocketWrapper implements ISocketWrapper {
});
}

sendAudioBuffer(buffer: ArrayBufferLike): void {
sendAudioBuffer(data: ArrayBufferLike | Blob): void {
if (this.socket && this.isOpen()) {
this.socket.send(buffer);
if (data instanceof Blob) {
// NOTE: Maybe we should add a log message about this potentially being poorer performance in Node
data.arrayBuffer().then((buf) => this.socket?.send(buf));
} else {
this.socket.send(data);
}
} else console.error('tried to send audio when socket was closed');
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/socket-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ISocketWrapper {
onDisconnect?: (event: CloseEvent) => void;
connect(url: string, authToken?: string, appId?: string): Promise<void>;
disconnect(): Promise<void>;
sendAudioBuffer(buffer: ArrayBufferLike): void;
sendAudioBuffer(buffer: ArrayBufferLike | Blob): void;
sendMessage(message: string): void;
isOpen(): boolean;
}
Loading