Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Constructors

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?

Methods

  • connect(): Promise<boolean>
  • disconnect(): Promise<boolean>
  • initialize(): Promise<void>
  • getConnectedUsers(): any[]
  • getMediaStreamForUser(userId: any): any
  • getLevelsStreamForUser(userId: any): any
  • isAudioEnabled(): boolean
  • isVideoEnabled(): boolean
  • toggleAudio(enabled: any): void
  • toggleBroadcast(enabled: any): void
  • toggleVideo(enabled: any): void
  • setUserVideo(userId: any, videoElement: any): Promise<void>
  • initializeLocalStream(): Promise<MediaStream>
  • Initialize a local media stream for the current user

    Returns Promise<MediaStream>

  • activateSocketListeners(): void
  • Listen for Audio/Video updates on the av socket to broker connections between peers

    Returns void

  • initializePeerStream(userId: string): Promise<SimplePeer>
  • 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

  • receiveSignal(userId: string, data: any): void
  • 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: any

      The connection details provided by SimplePeer

    Returns void

  • connectPeer(userId: string, isInitiator?: boolean): SimplePeer
  • 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

  • disconnectPeer(userId: string): Promise<void>
  • 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

  • disconnectAll(): Promise<any[]>
  • Disconnect from all current peer streams

    Returns Promise<any[]>

    A Promise which resolves once all peers have been disconnected

  • onSettingsChanged(changed: any): Promise<void>
  • updateLocalStream(): Promise<void>
  • Replace the local stream for each connected peer with a re-generated MediaStream.

    Returns Promise<void>

  • getAudioSinks(): 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 }>

    }

  • getAudioSources(): 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 }>

    }

  • getVideoSources(): 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 }>

    }

  • _connect(): Promise<any[]>
  • Try to establish a peer connection with each user connected to the server.

    Returns Promise<any[]>

  • _createMediaStream(params: { video: any; audio: any }): Promise<Error | MediaStream>
  • Attempt to create local media streams.

    Parameters

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

      Parameters for the getUserMedia request.

      • video: any
      • audio: any

    Returns Promise<Error | MediaStream>

    The created MediaStream or an error.

  • _createPeerConnection(userId: string, isInitiator: boolean): any
  • 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

  • _setupCustomTURN(options: any): void
  • Setup the custom TURN relay to be used in subsequent calls if there is one configured. TURN credentials are mandatory in WebRTC.

    Parameters

    • options: any

      The SimplePeer configuration object.

    Returns void

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