Constructor
new SimplePeerAVClient()
Extends
Members
_connectionPoll :number|null
The polling interval ID for connected users that might have unexpectedly dropped out of our peer network.
Type:
- number | null
audioBroadcastEnabled :boolean
Is outbound broadcast of local audio enabled?
Type:
- boolean
isMuted
- Inherited From:
Is the current user muted?
isVoiceActivated
- Inherited From:
Is audio broadcasting voice-activation enabled?
isVoiceAlways
- Inherited From:
Is audio broadcasting always enabled?
isVoicePTT
- Inherited From:
Is audio broadcasting push-to-talk enabled?
levelsStream :MediaStream
The dedicated audio stream used to measure volume levels for voice activity detection.
Type:
- MediaStream
localStream :MediaStream
The local Stream which captures input video and audio
Type:
- MediaStream
master :AVMaster
- Inherited From:
The master orchestration instance
Type:
peers :Map
A mapping of connected peers
Type:
- Map
remoteStreams :Map
A mapping of connected remote streams
Type:
- Map
settings :AVSettings
- Inherited From:
The active audio/video settings being used
Type:
Methods
activateSocketListeners()
Listen for Audio/Video updates on the av socket to broker connections between peers
(async) connect() → {Promise.<boolean>}
- Overrides:
Connect to any servers or services needed in order to provide audio/video functionality. Any parameters needed in order to establish the connection should be drawn from the settings object. This function should return a boolean for whether the connection attempt was successful.
Returns:
Was the connection attempt successful?
- Type
- Promise.<boolean>
connectPeer(userId, isInitiator) → {SimplePeer}
Connect to a peer directly, either as the initiator or as the receiver
Parameters:
Name | Type | Default | Description |
---|---|---|---|
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:
The constructed and configured SimplePeer instance
- Type
- SimplePeer
(async) disconnect() → {Promise.<boolean>}
- Overrides:
Disconnect from any servers or services which are used to provide audio/video functionality. This function should return a boolean for whether a valid disconnection occurred.
Returns:
Did a disconnection occur?
- Type
- Promise.<boolean>
(async) disconnectAll() → {Promise.<Array>}
Disconnect from all current peer streams
Returns:
A Promise which resolves once all peers have been disconnected
- Type
- Promise.<Array>
(async) disconnectPeer(userId) → {Promise.<void>}
Disconnect from a peer by stopping current stream tracks and destroying the SimplePeer instance
Parameters:
Name | Type | Description |
---|---|---|
userId |
string | The Foundry user ID from whom we are disconnecting |
Returns:
A Promise which resolves once the disconnection is complete
- Type
- Promise.<void>
(async) getAudioSinks() → {Promise.<{object}>}
- Inherited From:
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:
- Type
- Promise.<{object}>
(async) getAudioSources() → {Promise.<{object}>}
- Inherited From:
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:
- Type
- Promise.<{object}>
getConnectedUsers() → {Array.<string>}
- Overrides:
Return an array of Foundry User IDs which are currently connected to A/V. The current user should also be included as a connected user in addition to all peers.
Returns:
The connected User IDs
- Type
- Array.<string>
getLevelsStreamForUser(userId) → {MediaStream|null}
- Overrides:
Provide a MediaStream for monitoring a given user's voice volume levels.
Parameters:
Name | Type | Description |
---|---|---|
userId |
string | The User ID. |
Returns:
The MediaStream for the user, or null if the user does not have one.
- Type
- MediaStream | null
getMediaStreamForUser(userId) → {MediaStream|null}
- Overrides:
Provide a MediaStream instance for a given user ID
Parameters:
Name | Type | Description |
---|---|---|
userId |
string | The User id |
Returns:
The MediaStream for the user, or null if the user does not have one
- Type
- MediaStream | null
(async) getVideoSources() → {Promise.<{object}>}
- Inherited From:
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:
- Type
- Promise.<{object}>
(async) initialize() → {Promise.<void>}
- Overrides:
One-time initialization actions that should be performed for this client implementation. This will be called only once when the Game object is first set-up.
Returns:
- Type
- Promise.<void>
(async) initializeLocalStream() → {Promise.<MediaStream>}
Initialize a local media stream for the current user
Returns:
- Type
- Promise.<MediaStream>
(async) initializePeerStream(userId) → {Promise.<SimplePeer>}
Initialize a stream connection with a new peer
Parameters:
Name | Type | Description |
---|---|---|
userId |
string | The Foundry user ID for which the peer stream should be established |
Returns:
A Promise which resolves once the peer stream is initialized
- Type
- Promise.<SimplePeer>
isAudioEnabled() → {boolean}
- Overrides:
Is outbound audio enabled for the current user?
Returns:
- Type
- boolean
isVideoEnabled() → {boolean}
- Overrides:
Is outbound video enabled for the current user?
Returns:
- Type
- boolean
(async) onSettingsChanged(changed)
- Overrides:
Handle changes to A/V configuration settings.
Parameters:
Name | Type | Description |
---|---|---|
changed |
object | The settings which have changed |
receiveSignal(userId, data)
Receive a request to establish a peer signal with some other User id
Parameters:
Name | Type | Description |
---|---|---|
userId |
string | The Foundry user ID who is requesting to establish a connection |
data |
object | The connection details provided by SimplePeer |
(async) setUserVideo(userId, videoElement)
- Overrides:
Set the Video Track for a given User ID to a provided VideoElement
Parameters:
Name | Type | Description |
---|---|---|
userId |
string | The User ID to set to the element |
videoElement |
HTMLVideoElement | The HTMLVideoElement to which the video should be set |
toggleAudio(enable)
- Overrides:
Set whether the outbound audio feed for the current game user is enabled. This method should be used when the user marks themselves as muted or if the gamemaster globally mutes them.
Parameters:
Name | Type | Description |
---|---|---|
enable |
boolean | Whether the outbound audio track should be enabled (true) or disabled (false) |
toggleBroadcast(broadcast)
- Overrides:
Set whether the outbound audio feed for the current game user is actively broadcasting. This can only be true if audio is enabled, but may be false if using push-to-talk or voice activation modes.
Parameters:
Name | Type | Description |
---|---|---|
broadcast |
boolean | Whether outbound audio should be sent to connected peers or not? |
toggleVideo(enable)
- Overrides:
Set whether the outbound video feed for the current game user is enabled. This method should be used when the user marks themselves as hidden or if the gamemaster globally hides them.
Parameters:
Name | Type | Description |
---|---|---|
enable |
boolean | Whether the outbound video track should be enabled (true) or disabled (false) |
(async) updateLocalStream()
- Overrides:
Replace the local stream for each connected peer with a re-generated MediaStream.