Optional
config: CreateConfig<PeerMetadata, TrackMetadata>Private
connectPrivate
handlePrivate
initPrivate
initPrivate
isLeaves the room. This function should be called when user leaves 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 peer will be notified that peer left in MessageEvents.peerLeft,
Private
Readonly
peerPrivate
reconnectPrivate
removePrivate
setupPrivate
Readonly
trackUpdates the metadata for the current peer.
Data about this peer that other peers will receive upon joining.
If the metadata is different from what is already tracked in the room, the event MessageEvents.peerUpdated will be emitted for other peers in the room.
Updates the metadata for a specific track.
TrackId (generated in addTrack) of audio or video track.
Data about this track that other peers will receive upon joining.
If the metadata is different from what is already tracked in the room, the event MessageEvents.trackUpdated will be emitted for other peers in the room.
Private
webrtcPrivate
websocketAdds track that will be sent to the RTC Engine.
Audio or video track e.g. from your microphone or camera.
Optional
trackMetadata: TrackMetadataAny information about this track that other peers will receive in MessageEvents.peerJoined. E.g. this can source of the track - wheather it's screensharing, webcam or some other media device.
Optional
simulcastConfig: SimulcastConfigSimulcast configuration. By default, simulcast is disabled. For more information refer to SimulcastConfig.
Optional
maxBandwidth: TrackBandwidthLimitMaximal 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 FishjamClient.setTrackBandwidth.
Returns id of added track
const localStream: MediaStream = new MediaStream();
try {
const localAudioStream = await navigator.mediaDevices.getUserMedia(
{ audio: true }
);
localAudioStream
.getTracks()
.forEach((track) => localStream.addTrack(track));
} catch (error) {
console.error("Couldn't get microphone permission:", error);
}
try {
const localVideoStream = await navigator.mediaDevices.getUserMedia(
{ video: true }
);
localVideoStream
.getTracks()
.forEach((track) => localStream.addTrack(track));
} catch (error) {
console.error("Couldn't get camera permission:", error);
}
localStream
.getTracks()
.forEach((track) => client.addTrack(track, localStream));
Uses the WebSocket connection and !WebRTCEndpoint | WebRTCEndpoint to join to the room. Registers the callbacks to handle the events emitted by the !WebRTCEndpoint | WebRTCEndpoint. Make sure that peer metadata is serializable.
Configuration object for the client
const client = new FishjamClient<PeerMetadata, TrackMetadata>();
client.connect({
peerMetadata: {},
token: peerToken
});
Disables track encoding so that it will be no longer sent to the server.
Id of track
Encoding that will be disabled
const trackId = webrtc.addTrack(track, stream, {}, {enabled: true, active_encodings: ["l", "m", "h"]});
webrtc.disableTrackEncoding(trackId, "l");
Rest
...args: Parameters<Required<MessageEvents<PeerMetadata, TrackMetadata>>[E]>Enables track encoding so that it will be sent to the server.
Id of track
Encoding that will be enabled
const trackId = webrtc.addTrack(track, stream, {}, {enabled: true, active_encodings: ["l", "m", "h"]});
webrtc.disableTrackEncoding(trackId, "l");
// wait some time
webrtc.enableTrackEncoding(trackId, "l");
Returns a snapshot of currently received remote endpoints.
Returns a snapshot of currently received remote peers.
Returns a snapshot of currently received remote tracks.
if (client.getRemoteTracks()[trackId]?.simulcastConfig?.enabled) {
client.setTargetTrackEncoding(trackId, encoding);
}
Retrieves statistics related to the RTCPeerConnection. These statistics provide insights into the performance and status of the connection.
Optional
selector: null | MediaStreamTrackRemove a callback from the list of callbacks to be called when the event is emitted.
Event name from MessageEvents
Reference to function to be removed from called callbacks
This
const callback = ()=>{ };
client.on("onJoinSuccess", callback);
client.off("onJoinSuccess", callback);
Register a callback to be called when the event is emitted. Full list of callbacks can be found here MessageEvents.
Event name from MessageEvents
Callback function to be called when the event is emitted
This
const callback = ()=>{ };
client.on("onJoinSuccess", callback);
Optional
event: ERemoves a track from connection that was being sent to the RTC Engine.
Id of audio or video track to remove.
// 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.
Id of audio or video track to replace.
New audio or video track.
Optional
newTrackMetadata: TrackMetadataOptional track metadata to apply to the new track. If no track metadata is passed, the old track metadata is retained.
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.
Id of the track
Rid of the encoding
Desired max bandwidth used by the encoding (in kbps)
Sets track encoding that server should send to the client library.
The encoding will be sent whenever it is available. If chosen encoding is temporarily unavailable, some other encoding will be sent until chosen encoding becomes active again.
Id of track
Encoding to receive
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.
In kbps
Success
FishjamClient is the main class to interact with Fishjam.
Example
You can register callbacks to handle the events emitted by the Client.
Example