Skip to content

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mshafiee committed Mar 17, 2024
1 parent 486cb99 commit e675c03
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ func (b *TelegramBot) handlePlayer(w http.ResponseWriter, r *http.Request) {
const statusText = document.getElementById('status');
let ws;
let latestMedia = { url: null, mimeType: null };
let attemptReconnect = true;
const setupWebSocket = () => {
const wsAddress = 'ws://' + window.location.host + '/ws/{{.ChatID}}';
Expand All @@ -873,6 +874,16 @@ func (b *TelegramBot) handlePlayer(w http.ResponseWriter, r *http.Request) {
latestMedia = { url: data.url, mimeType: data.mimeType };
playMedia(data.url, data.mimeType);
};
const handleWebSocketClose = () => {
console.log('WebSocket closed. Attempting to reconnect...');
if (attemptReconnect) setTimeout(setupWebSocket, 3000);
};
const handleWebSocketError = (error) => {
console.error('WebSocket encountered an error: ', error.message);
ws.close(); // Ensure the WebSocket is closed properly before attempting to reconnect
};
const playMedia = (url, mimeType) => {
if (mimeType.startsWith('video')) {
Expand Down

0 comments on commit e675c03

Please sign in to comment.