EasyRTCClient

EasyRTCClient

WebRTC Client using the EasyRTC framework for its implementation. Whenever a new remote stream is received by this implementation, a call to this.webrtc.onUserStreamChange() will be made to notify of the new or deleted stream.

Constructor

new EasyRTCClient(webrtc, settings)

Source:
Implements:
Parameters:
Name Type Description
webrtc WebRTC

The WebRTC object

settings WebRTCSettings

The WebRTC Settings object

Methods

_userIdToEasyRtcId(userId) → {string|null}

Source:

Returns the EasyRtcId of a user There should only be one remote peer per user

Parameters:
Name Type Description
userId string

The ID of the user

Returns:

The EasyRtcId of the peer

Type
string | null

assignStreamToVideo(stream, video)

Source:
Implements:

Assigns a stream to a video element

Parameters:
Name Type Description
stream MediaStream

The stream to assign

video HTMLVideoElement

The video element to configure

(async) closeLocalStream(temporary) → {Promise}

Source:
Implements:

Closes a local media stream. If the master stream is closed, any subsequent WebRTC calls will not have any streams sent to the peer.

If @temporary is false (default), the master stream will be destroyed and all local streams removed from any existing calls. If @temporary is true, closes the temporary stream

Parameters:
Name Type Default Description
temporary boolean false

Whether to create a temporary stream or the master stream

Returns:
Type
Promise

(async) connect(host, room, username, password) → {Promise.boolean}

Source:
Implements:

Connect to the signalling server. Any existing connections will be dropped and any existing calls hung up. Once a connection to the server is established and the user authenticated, join a room and automatically establish a call with other users in that same room. If a local master media stream has been created, add a copy of that stream to every peer. Whether to include audio or video in that cloned stream, or whether to enable or disable the audio and video of the remote stream from that peer will automatically be determined based on the saved settings. This will be called again in case a server configuration changed.

In case of using FVTT server, we can't use the same socket as game.socket because the server side can close the socket in case of errors (such as disconnection/reconnection attempt where it would say that we are 'already connected' and disconnect us forcibly) and thus it could destroy the actual game's socket, so we use a different path for it instead with easyrtc.useThisSocketConnection(game.socket)

Parameters:
Name Type Description
host string

Server host address. Set to null to use current FVTT server

room string

Name of the room to join on the signalling server

username string

Username to authenticate to the server (if needed)

password string

Password to authenticate the user (if needed)

Returns:

Returns success/failure to connect

Type
Promise.boolean

(async) disconnect() → {Promise.boolean}

Source:
Implements:

Disconnect from the signalling server, any existing calls will be terminated. This is also called whenever the server configuration is changed.

Returns:

Returns success/failure to connect

Type
Promise.boolean

(async) getAudioSinks() → {Promise.Object}

Source:
Implements:

Get the list of available audio output devices The expected result is an object with the device id as key and its human-readable label as value

Note: This feature is not supported by Firefox by default as it depends on the enumerateDevices API which doesn't list output devices on Firefox 63+ unless the media.setsinkid.enabled settings is enabled. See https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices

Returns:
Type
Promise.Object

(async) getAudioSources() → {Promise.Object}

Source:
Implements:

Get the list of available audio sources. The expected result is an object with the device id as key and its human-readable label as value.

Returns:
Type
Promise.Object

getConnectedStreams() → {Array.Object}

Source:
Implements:

Get the list of connected streams The result would be an array of objects in the form of {id, pc, local, remote} where id is the user's ID, pc is the RTCPeerConnection object associated to the peer, local is the local stream added to the call and remote is the remote user's stream.

Returns:
Type
Array.Object

getStreamForUser(userId) → {MediaStream}

Source:
Implements:

Retrieve the stream for a user. Calling this with game.user.id is the proper way of retrieving the local master stream without re-initializing it. Any other user will return the remote stream of that user or null if no stream could be found.

Parameters:
Name Type Description
userId string

ID of the user

Returns:

The remote stream of the user

Type
MediaStream

(async) getVideoSources() → {Promise.Object}

Source:
Implements:

Get the list of available video sources. The expected result is an object with the device id as key and its human-readable label as value.

Returns:
Type
Promise.Object

(async) initialize() → {Promise.boolean}

Source:
Implements:

Initialize the WebRTC implementation. This Will only be called once by the main setupGame() initialization function.

Returns:
Type
Promise.boolean

(async) initLocalStream(audioSrc, videoSrc, temporary) → {Promise.MediaStream}

Source:
Implements:

Initialize a local media stream Capture the local audio and video and returns the stream associated with them.

If @temporary is false (default), then this will initialize the master stream, not the actual streams being sent to individual users. However, if a master stream was already created, it will automatically get closed and every individual streams derived from it that are being sent to connected users will be removed from the calls. Each established or subsequent calls will receive a copy of the created stream (A/V depending on user permissions)

If @temporary is true then this only applies to a temporary stream and does not affect the master stream or any streams in existing calls. Note that this assumes only one temporary stream can be created at a time.

Parameters:
Name Type Default Description
audioSrc string | null

ID of the audio source to capture from or null to disable Audio

videoSrc string | null

ID of the video source to capture from or null to disable Video

temporary boolean false

Whether to create a temporary stream or the master stream

Returns:

Returns the local stream or null if none could be created

Type
Promise.MediaStream

onSettingsChanged(changed)

Source:
Implements:

Notify of settings changes This can be used to act according

Parameters:
Name Type Description
changed Object

Object consisting of the changed settings in the form {key: value}

setAudioOutput(video, audioSinkId)

Source:
Implements:

Sets the audio output on a video element

Note: This feature is not supported by Firefox by default as it depends on the setSinkId API which is available behind the media.setsinkid.enabled settings in Firefox See https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId

Parameters:
Name Type Description
video HTMLVideoElement

The video element to configure

audioSinkId String

ID of the audio output device