MediaSFU Angular
    Preparing search index...

    Class SocketManager

    Manages connections to a media socket, allowing users to connect or disconnect based on API credentials.

    SocketManager

    Provides methods to connect and disconnect from a media socket using a provided API key or token.

    validateApiKeyToken - Validates the API key or token for correct format. connectSocket - Establishes a connection to the media socket using either the API key or token. disconnectSocket - Disconnects an active socket connection.

    const socketManager = new SocketManager();

    // Example of connecting to the socket
    const socketConnection = await socketManager.connectSocket({
    apiUserName: 'user123',
    apiKey: 'validApiKeyOf64Characters',
    link: 'https://socketserver.example.com'
    });

    // Example of disconnecting the socket
    const isDisconnected = await socketManager.disconnectSocket({
    socket: socketConnection
    });

    The active socket instance on connection, or a boolean indicating disconnection success.

    Index

    Constructors

    Methods

    • Connects to a media socket using the provided connection options.

      Parameters

      • options: ConnectSocketOptions

        The connection options.

        • apiUserName: string
        • OptionalapiKey?: string
        • OptionalapiToken?: string

      Returns Promise<Socket<DefaultEventsMap, DefaultEventsMap>>

      A promise that resolves to the connected socket.

      const options = {
      apiUserName: 'user123',
      apiKey: 'validApiKeyOf64Characters',
      link: 'https://socketserver.example.com'
      };

      try {
      const socket = await connectSocket(options);
      console.log('Connected to socket:', socket);
      } catch (error) {
      console.error('Failed to connect to socket:', error);
      }
    • Disconnects an active socket connection.

      Parameters

      Returns Promise<boolean>

      A promise that resolves to true if the socket was disconnected successfully, or false otherwise.

      const options = {
      socket: mySocketInstance,
      };

      try {
      const isDisconnected = await disconnectSocket(options);
      console.log("Socket disconnected:", isDisconnected);
      } catch (error) {
      console.error("Failed to disconnect socket:", error);
      }