// src/services/WebSocketManager.js import store from "../store"; // Ensure the path is…
- User
// src/services/WebSocketManager.js
import store from "../store"; // Ensure the path is correct import axios from "axios"; import { receiveMessage, receiveCallNotification, receiveSignalingMessage, // Import the new action receiveError, prependMessages, updateUserStatus, updateMessageStatus, endCall, } from "../slices/notificationSlice"; import { generateRoomName } from "../utils"; // Ensure generateRoomName is correctly implemented
class WebSocketManager { constructor() { // Implement Singleton Pattern if (WebSocketManager.instance) { console.log( "WebSocketManager: Constructor called but instance already exists. Returning existing instance." ); return WebSocketManager.instance; }
codeconsole.log("WebSocketManager: Creating a new instance..."); // Initialize properties this.socket = null; this.isConnected = false; this.reconnectAttempts = 0; this.maxReconnectAttempts = 5; this.reconnectDelay = 3000; // 3 seconds this.messageQueue = []; this.token = null; // Store token for reconnection this.beforeMap = {}; // To track the 'before' timestamp per room this.hasMoreMap = {}; // To track if more messages are available per room this.messageHandlers = []; // Array of registered message handlers this.desiredRooms = new Set(); // Initialize without any rooms WebSocketManager.instance = this;}
/**
- Upload files via HTTP and return their URLs.
- @param {File[]} files - Array of File objects to upload.
- @returns {Promise<string[]>} - Array of uploaded file URLs. */ async uploadFiles(files) { console.log("WebSocketManager: uploadFiles called with", files); const uploadUrl = "/api/upload/"; // Adjust to your upload endpoint const formData = new FormData(); files.forEach((file) => formData.append("files", file));
codetry {code - Assistant
It looks like you've shared your
WebSocketManager.jscode. How can I assist you with it? Are you encountering any issues or would you like help understanding or improving specific parts of the code? Please let me know how I can help!