Skip to content
Merged
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
74 changes: 48 additions & 26 deletions bots/google_meet_bot_adapter/google_meet_chromedriver_payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,35 +924,57 @@ class WebSocketClient {
constructor() {
const url = `ws://localhost:${window.initialData.websocketPort}`;
console.log('WebSocketClient url', url);
this.ws = new WebSocket(url);
this.ws.binaryType = 'arraybuffer';

this.ws.onopen = () => {
console.log('WebSocket Connected');
};

this.ws.onmessage = (event) => {
this.handleMessage(event.data);
};

this.ws.onerror = (error) => {
console.error('WebSocket Error:', error);
};

this.ws.onclose = () => {
console.log('WebSocket Disconnected');
};
this.websocketUrl = url;
this.reconnectAttempts = 0;
this.maxReconnectAttempts = 30;
this.reconnectDelay = 1000; // Start with 1 second
this.maxReconnectDelay = 30000; // Cap at 30 seconds

this.connect();
this.mediaSendingEnabled = false;

/*
We no longer need this because we're not using MediaStreamTrackProcessor's
this.lastVideoFrameTime = performance.now();
this.fillerFrameInterval = null;
}

connect() {
try {
this.ws = new WebSocket(this.websocketUrl);
this.ws.binaryType = 'arraybuffer';

this.ws.onopen = () => {
console.log('WebSocket Connected');
this.reconnectAttempts = 0; // Reset on successful connection
this.reconnectDelay = 1000;
};

this.ws.onmessage = (event) => {
this.handleMessage(event.data);
};

this.ws.onerror = (error) => {
console.error('WebSocket Error:', error);
};

this.ws.onclose = () => {
console.log('WebSocket Disconnected, attempting reconnect');
this.scheduleReconnect();
};
} catch (error) {
console.error('Error creating WebSocket:', error);
this.scheduleReconnect();
}
}

scheduleReconnect() {
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
console.error('Max reconnection attempts reached, giving up');
return;
}

this.reconnectAttempts++;
// Exponential backoff: delay doubles each time, capped at maxReconnectDelay
const delay = Math.min(this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1), this.maxReconnectDelay);
console.log(`Scheduling WebSocket reconnect in ${delay}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`);

this.lastVideoFrame = this.getBlackFrame();
this.blackVideoFrame = this.getBlackFrame();
*/
setTimeout(() => this.connect(), delay);
}

/*
Expand Down