An implementation of the AVClient which uses the simple-peer library and the Foundry socket server for signaling. Credit to bekit#4213 for identifying simple-peer as a viable technology and providing a POC implementation.

Hierarchy (view full)

Properties

localStream: MediaStream = null

The local Stream which captures input video and audio

levelsStream: MediaStream = null

The dedicated audio stream used to measure volume levels for voice activity detection.

peers: Map<any, any> = ...

A mapping of connected peers

remoteStreams: Map<any, any> = ...

A mapping of connected remote streams

audioBroadcastEnabled: boolean = false

Is outbound broadcast of local audio enabled?

_connectionPoll: number = null

The polling interval ID for connected users that might have unexpectedly dropped out of our peer network.

master: AVMaster

The master orchestration instance

settings: AVSettings

The active audio/video settings being used

_initialized: boolean = false

Has the client been successfully initialized?

Accessors

  • get isVoicePTT(): boolean
  • Is audio broadcasting push-to-talk enabled?

    Returns boolean

  • get isVoiceAlways(): boolean
  • Is audio broadcasting always enabled?

    Returns boolean

  • get isVoiceActivated(): boolean
  • Is audio broadcasting voice-activation enabled?

    Returns boolean

  • get isMuted(): boolean
  • Is the current user muted?

    Returns boolean

Methods

  • Returns Promise<boolean>

  • Parameters

    • userId: any
    • videoElement: any

    Returns Promise<void>

  • Initialize a local media stream for the current user

    Returns Promise<MediaStream>

  • Listen for Audio/Video updates on the av socket to broker connections between peers

    Returns void

  • Initialize a stream connection with a new peer

    Parameters

    • userId: string

      The Foundry user ID for which the peer stream should be established

    Returns Promise<SimplePeer>

    A Promise which resolves once the peer stream is initialized

  • Receive a request to establish a peer signal with some other User id

    Parameters

    • userId: string

      The Foundry user ID who is requesting to establish a connection

    • data: object

      The connection details provided by SimplePeer

    Returns void

  • Connect to a peer directly, either as the initiator or as the receiver

    Parameters

    • userId: string

      The Foundry user ID with whom we are connecting

    • isInitiator: boolean = false

      Is the current user initiating the connection, or responding to it?

    Returns SimplePeer

    The constructed and configured SimplePeer instance

  • Disconnect from a peer by stopping current stream tracks and destroying the SimplePeer instance

    Parameters

    • userId: string

      The Foundry user ID from whom we are disconnecting

    Returns Promise<void>

    A Promise which resolves once the disconnection is complete

  • Disconnect from all current peer streams

    Returns Promise<any[]>

    A Promise which resolves once all peers have been disconnected

  • Replace the local stream for each connected peer with a re-generated MediaStream.

    Returns Promise<void>

  • Provide an Object of available audio sources which can be used by this implementation. Each object key should be a device id and the key should be a human-readable label.

    Returns Promise<{
        object: any;
    }>

  • Provide an Object of available audio sources which can be used by this implementation. Each object key should be a device id and the key should be a human-readable label.

    Returns Promise<{
        object: any;
    }>

  • Provide an Object of available video sources which can be used by this implementation. Each object key should be a device id and the key should be a human-readable label.

    Returns Promise<{
        object: any;
    }>

  • Private

    Try to establish a peer connection with each user connected to the server.

    Returns Promise<any[]>

  • Private

    Attempt to create local media streams.

    Parameters

    • params: {
          video: object;
          audio: object;
      }

      Parameters for the getUserMedia request.

      • video: object
      • audio: object

    Returns Promise<Error | MediaStream>

    The created MediaStream or an error.

  • Private

    Create the SimplePeer instance for the desired peer connection. Modules may implement more advanced connection strategies by overriding this method.

    Parameters

    • userId: string

      The Foundry user ID with whom we are connecting

    • isInitiator: boolean

      Is the current user initiating the connection, or responding to it?

    Returns any

  • Private

    Setup the custom TURN relay to be used in subsequent calls if there is one configured. TURN credentials are mandatory in WebRTC.

    Parameters

    • options: object

      The SimplePeer configuration object.

    Returns void