Fishjam Web SDK - v0.18.0
    Preparing search index...

    Main class that is responsible for connecting to the RTC Engine, sending and receiving media.

    Hierarchy

    • WebRTCEndpoint_base
      • WebRTCEndpoint
    Index

    Constructors

    • Returns WebRTCEndpoint

    Properties

    bandwidthEstimation: bigint
    cleanUp: () => void

    Cleans up WebRTCEndpoint instance.

    connect: (metadata: unknown) => void

    Tries to connect to the RTC Engine. If user is successfully connected then WebRTCEndpointEvents.connected will be emitted.

    Type declaration

      • (metadata: unknown): void
      • Parameters

        Returns void

    let webrtc = new WebRTCEndpoint();
    webrtc.connect({displayName: "Bob"});
    connectionManager?: ConnectionManager
    disableTrackEncoding: (trackId: string, encoding: Variant) => Promise<void>

    Disables track encoding so that it will be no longer sent to the server.

    Type declaration

      • (trackId: string, encoding: Variant): Promise<void>
      • Parameters

        • trackId: string

          id of track

        • encoding: Variant

          encoding that will be disabled

        Returns Promise<void>

    const trackId = webrtc.addTrack(track, stream, {}, {enabled: true, activeEncodings: ["l", "m", "h"]});
    webrtc.disableTrackEncoding(trackId, "l");
    disconnect: () => void

    Disconnects from the room. This function should be called when user disconnects from the room in a clean way e.g. by clicking a dedicated, custom button disconnect. As a result there will be generated one more media event that should be sent to the RTC Engine. Thanks to it each other endpoint will be notified that endpoint was removed in WebRTCEndpointEvents.endpointRemoved,

    enableTrackEncoding: (trackId: string, encoding: Variant) => Promise<void>

    Enables track encoding so that it will be sent to the server.

    Type declaration

      • (trackId: string, encoding: Variant): Promise<void>
      • Parameters

        • trackId: string

          id of track

        • encoding: Variant

          encoding that will be enabled

        Returns Promise<void>

    const trackId = webrtc.addTrack(track, stream, {}, {enabled: true, activeEncodings: ["l", "m", "h"]});
    webrtc.disableTrackEncoding(trackId, "l");
    // wait some time
    webrtc.enableTrackEncoding(trackId, "l");
    receiveMediaEvent: (mediaEvent: SerializedMediaEvent) => Promise<void>

    Feeds media event received from RTC Engine to WebRTCEndpoint. This function should be called whenever some media event from RTC Engine was received and can result in WebRTCEndpoint generating some other media events.

    Type declaration

    This example assumes phoenix channels as signalling layer. As phoenix channels require objects, RTC Engine encapsulates binary data into map with one field that is converted to object with one field on the TS side.

    webrtcChannel.on("mediaEvent", (event) => webrtc.receiveMediaEvent(event.data));
    
    updateEndpointMetadata: (metadata: any) => void

    Updates the metadata for the current endpoint.

    Type declaration

      • (metadata: any): void
      • Parameters

        • metadata: any

          Data about this endpoint that other endpoints will receive upon being added.

          If the metadata is different from what is already tracked in the room, the optional event endpointUpdated will be emitted for other endpoint in the room.

        Returns void

    updateTrackMetadata: (trackId: string, trackMetadata: any) => void

    Updates the metadata for a specific track.

    Type declaration

      • (trackId: string, trackMetadata: any): void
      • Parameters

        • trackId: string

          trackId (generated in addTrack) of audio or video track.

        • trackMetadata: any

          Data about this track that other endpoint will receive upon being added.

          If the metadata is different from what is already tracked in the room, the optional event trackUpdated will be emitted for other endpoints in the room.

        Returns void

    Methods

    • Adds track that will be sent to the RTC Engine.

      Parameters

      • track: MediaStreamTrack

        Audio or video track e.g. from your microphone or camera.

      • OptionaltrackMetadata: unknown

        Any information about this track that other endpoints will receive in WebRTCEndpointEvents.endpointAdded. E.g. this can source of the track - whether it's screensharing, webcam or some other media device.

      • OptionalsimulcastConfig: SimulcastConfig

        Simulcast configuration. By default simulcast is disabled. For more information refer to SimulcastConfig.

      • OptionalmaxBandwidth: TrackBandwidthLimit

        maximal bandwidth this track can use. Defaults to 0 which is unlimited. This option has no effect for simulcast and audio tracks. For simulcast tracks use `WebRTCEndpoint.setTrackBandwidth.

      Returns Promise<string>

      Returns id of added track

      let localStream: MediaStream = new MediaStream();
      try {
      localAudioStream = await navigator.mediaDevices.getUserMedia(
      AUDIO_CONSTRAINTS
      );
      localAudioStream
      .getTracks()
      .forEach((track) => localStream.addTrack(track));
      } catch (error) {
      console.error("Couldn't get microphone permission:", error);
      }

      try {
      localVideoStream = await navigator.mediaDevices.getUserMedia(
      VIDEO_CONSTRAINTS
      );
      localVideoStream
      .getTracks()
      .forEach((track) => localStream.addTrack(track));
      } catch (error) {
      console.error("Couldn't get camera permission:", error);
      }

      localStream
      .getTracks()
      .forEach((track) => webrtc.addTrack(track, localStream));
    • Returns (string | symbol)[]

    • Returns bigint

    • Returns EndpointWithTrackContext

    • Returns number

    • Returns a snapshot of currently received remote endpoints.

      Returns Record<string, EndpointWithTrackContext>

    • Returns a snapshot of currently received remote tracks.

      Returns Record<string, TrackContext>

      if (webRTCEndpoint.getRemoteTracks()[trackId]?.simulcastConfig?.enabled) {
      webRTCEndpoint.setTargetTrackEncoding(trackId, encoding);
      }
    • Retrieves statistics related to the RTCPeerConnection. These statistics provide insights into the performance and status of the connection.

      Parameters

      • Optionalselector: null | MediaStreamTrack

      Returns Promise<RTCStatsReport>

    • Type Parameters

      Parameters

      • event: E

      Returns number

    • Type Parameters

      Parameters

      • Optionalevent: E

      Returns this

    • Removes a track from connection that was sent to the RTC Engine.

      Parameters

      • trackId: string

        Id of audio or video track to remove.

      Returns Promise<void>

      // setup camera
      let localStream: MediaStream = new MediaStream();
      try {
      localVideoStream = await navigator.mediaDevices.getUserMedia(
      VIDEO_CONSTRAINTS
      );
      localVideoStream
      .getTracks()
      .forEach((track) => localStream.addTrack(track));
      } catch (error) {
      console.error("Couldn't get camera permission:", error);
      }

      let trackId
      localStream
      .getTracks()
      .forEach((track) => trackId = webrtc.addTrack(track, localStream));

      // remove track
      webrtc.removeTrack(trackId)
    • Replaces a track that is being sent to the RTC Engine.

      Parameters

      • trackId: string

        Audio or video track.

      • newTrack: null | MediaStreamTrack

      Returns Promise<void>

      success

      // setup camera
      let localStream: MediaStream = new MediaStream();
      try {
      localVideoStream = await navigator.mediaDevices.getUserMedia(
      VIDEO_CONSTRAINTS
      );
      localVideoStream
      .getTracks()
      .forEach((track) => localStream.addTrack(track));
      } catch (error) {
      console.error("Couldn't get camera permission:", error);
      }
      let oldTrackId;
      localStream
      .getTracks()
      .forEach((track) => trackId = webrtc.addTrack(track, localStream));

      // change camera
      const oldTrack = localStream.getVideoTracks()[0];
      let videoDeviceId = "abcd-1234";
      navigator.mediaDevices.getUserMedia({
      video: {
      ...(VIDEO_CONSTRAINTS as {}),
      deviceId: {
      exact: videoDeviceId,
      },
      }
      })
      .then((stream) => {
      let videoTrack = stream.getVideoTracks()[0];
      webrtc.replaceTrack(oldTrackId, videoTrack);
      })
      .catch((error) => {
      console.error('Error switching camera', error);
      })
    • Updates maximum bandwidth for the given simulcast encoding of the given track.

      Parameters

      • trackId: string

        id of the track

      • rid: Variant

        rid of the encoding

      • bandwidth: number

        desired max bandwidth used by the encoding (in kbps)

      Returns Promise<void>

    • Parameters

      • maxListeners: number

      Returns this

    • Sets track variant that server should send to the client library.

      The variant will be sent whenever it is available. If chosen variant is temporarily unavailable, some other variant will be sent until the chosen variant becomes active again.

      Parameters

      • trackId: string

        id of track

      • variant: Variant

        variant to receive

      Returns void

      webrtc.setTargetTrackEncoding(incomingTrackCtx.trackId, "l")
      
    • Updates maximum bandwidth for the track identified by trackId. This value directly translates to quality of the stream and, in case of video, to the amount of RTP packets being sent. In case trackId points at the simulcast track bandwidth is split between all of the variant streams proportionally to their resolution.

      Parameters

      • trackId: string
      • bandwidth: number

        in kbps

      Returns Promise<void>

      success