Skip to content

Commit f965022

Browse files
authored
Merge pull request #112 from deepgram/add-close-event-reason
added reason to close event
2 parents ba433b7 + 49edf8c commit f965022

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/transcription/liveTranscription.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export class LiveTranscription extends EventEmitter {
3636
};
3737

3838
this._socket.onclose = (event: WebSocket.CloseEvent) => {
39+
// changing the event.target to any to access the private _req property that isn't available on the WebSocket.CloseEvent type
40+
const newTarget: any = event.target;
41+
if (newTarget["_req"]) {
42+
const dgErrorIndex =
43+
newTarget["_req"].res.rawHeaders.indexOf("dg-error");
44+
event.reason = newTarget["_req"].res.rawHeaders[dgErrorIndex + 1];
45+
}
3946
this.emit(LiveTranscriptionEvents.Close, event);
4047
};
4148

0 commit comments

Comments
 (0)