Skip to content

Commit

Permalink
ag2 socket close hook
Browse files Browse the repository at this point in the history
  • Loading branch information
davorinrusevljan committed Feb 5, 2025
1 parent 86bae56 commit f3daa6d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/webRTC.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { WebSocketEvents } from 'vitest';

interface AG2InitMessage {
type: 'ag2.init';
config: {
Expand All @@ -17,11 +19,15 @@ export class WebRTC {
private microphone?: MediaStreamTrack;
private ws: WebSocket | null;
private pc: RTCPeerConnection | undefined;
public onAG2SocketClose: (ev: CloseEvent) => void;

constructor(ag2SocketUrl: string, microphone?: MediaStreamTrack) {
this.ag2SocketUrl = ag2SocketUrl;
this.microphone = microphone;
this.ws = null;
this.onAG2SocketClose = (ev: CloseEvent) => {
console.log('AG2 Websocket closed');
};
}

async disconnect(): Promise<void> {
Expand Down Expand Up @@ -138,6 +144,10 @@ export class WebRTC {
console.log('web socket opened');
};

this.ws.onclose = (event) => {
this.onAG2SocketClose(event);
};

this.ws.onmessage = async (event) => {
try {
const message: AG2Message = JSON.parse(event.data);
Expand Down

0 comments on commit f3daa6d

Please sign in to comment.