-
Notifications
You must be signed in to change notification settings - Fork 0
WebrtcCall
extends
Call
options(): WebrtcCallOptions
customData(): CustomData
pauseIncomingVideo(): void
resumeIncomingVideo(): void
cameraVideo(cameraVideo: boolean): Promise<void>
hasCameraVideo(): boolean
hasRemoteCameraVideo(): boolean
screenShare(screenShare: boolean): Promise<void>
startScreenShare(displayOptions?: DisplayOptions): Promise<void>
stopScreenShare(): Promise<void>
hasScreenShare(): boolean
hasRemoteScreenShare(): boolean
setVideoInputDevice(deviceId: string): Promise<void>
cameraOrientation(): CameraOrientation
setCameraOrientation(cameraOrientation: CameraOrientation): Promise<void>
setVideoFilter(videoFilter: VideoFilter): Promise<void>
videoFilter(): VideoFilter
clearVideoFilter(): Promise<void>
localCapturer(): LocalWebrtcCapturer
serverCapturer(): ServerWebrtcCapturer
dataChannel(): DataChannel
on(event: CallsApiEvent, eventHandler: CallsEventHandlers): void
Returns the call options this call was started with.
none
-
WebrtcCallOptions
- Call options the call was started with.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().build());
console.log(`Call options: ${JSON.stringify(webrtcCall.options())}`);
Getter for the customData
field.
none
-
CustomData
- Value of thecustomData
field that is defined as an object of key-valuestring
pairs.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCallOptions = WebrtcCallOptions.builder().setCustomData({'city': 'New York'}).build();
let webrtcCall = infobipRTC.callWebrtc('alice', webrtcCallOptions);
console.log(`Custom data: ${JSON.stringify(webrtcCall.customData())}`);
Stop receiving the video media of the remote participant.
none
N/A
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
document.addEventListener('visibilitychange', () => {
if (document.visibilityState !== 'visible') {
console.log('Browser lost focus, stop showing remote video media.');
webrtcCall.pauseIncomingVideo();
}
});
});
Start receiving the video media of the remote participant.
none
N/A
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
console.log('Browser got focus back, start showing remote video media again.');
webrtcCall.resumeIncomingVideo();
}
});
});
Controls whether the local camera video should be enabled. For video calls it is enabled by default.
-
cameraVideo
:boolean
- Whether local camera video should be enabled.
-
Promise<void>
- Promise that resolves tovoid
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
webrtcCall.cameraVideo(true)
.catch(error => console.log(`Error: ${error}`));
});
Returns information whether the current call has local camera video.
none
-
boolean
-true
if the call has local camera video, otherwisefalse
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCallOptions = WebrtcCallOptions.builder().setVideo(true).build();
let webrtcCall = infobipRTC.callWebrtc('alice', webrtcCallOptions);
let callType = webrtcCall.hasCameraVideo() ? 'video' : 'audio';
console.log(`Making ${callType} WebRTC call.`);
Returns information whether the current call has remote video.
none
-
boolean
-true
if the call has remote video, otherwisefalse
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
let remoteVideo = webrtcCall.hasRemoteCameraVideo() ? 'has camera video' : 'doesn\'t have camera video';
console.log(`Remote user ${remoteVideo}.`);
});
Please note that this method is being deprecated. Instead, You can use the
startScreenShare
andstopScreenShare
methods.
Toggles sharing the screen during the call.
This method is not available in mobile versions of browsers.
-
screenShare
:boolean
- Controls whether the screen sharing should be started or stopped.
-
Promise<void>
- Promise that resolves tovoid
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on('established', _ => {
webrtcCall.screenShare(true)
.catch(error => console.log(`Error: ${error}`));
});
webrtcCall.on('screen-share-added', _ => {
console.log('Started sharing screen');
})
Starts sharing the screen during the call and optionally provides the ability to control surfaces which can be shared.
After one participant in the call starts sharing their screen, the screen-share-added
event will be triggered on their side, and remote-screen-share-added
event will be triggered on the remote side.
This method is not available in mobile versions of browsers.
-
displayOptions
:DisplayOptions
- Optional argument which provides control over surfaces that can be shared during the call. If not provided, no restrictions on display surfaces that can be shared are set.
-
Promise<void>
- Promise that resolves tovoid
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
let displayOptions: DisplayOptions = {allowedDisplayOptions: ['window', 'monitor']}
webrtcCall.on('established', _ => {
webrtcCall.startScreenShare(displayOptions)
.catch(error => console.log(`Error: ${error}`));
});
webrtcCall.on('screen-share-added', _ => {
console.log('Started sharing screen');
})
Stops sharing the screen during the call.
After one participant in the call stops sharing their screen, the screen-share-removed
event will be triggered on their side, and remote-screen-share-removed
event will be triggered on the remote side.
This method is not available in mobile versions of browsers.
Additionally, screenshare control is not available on all web browsers. Before attempting to use this feature, please consult the browser compatibility table
.
none
-
Promise<void>
- Promise that resolves tovoid
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on('screen-share-added', _ => {
webrtcCall.stopScreenShare()
.catch(error => console.log(`Error: ${error}`));
});
webrtcCall.on('screen-share-removed', _ => {
console.log('Stopped sharing screen');
})
Returns information whether screen is being shared with remote peer.
none
-
boolean
-true
if screen is being shared, otherwisefalse
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on('established', _ => {
webrtcCall.screenShare(true);
});
webrtcCall.on('screen-share-added', _ => {
if (webrtcCall.hasScreenShare()) {
console.log('Sharing screen...');
}
})
Returns information whether the remote user is sharing their screen.
none
-
boolean
-true
if screen is being shared, otherwisefalse
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on('remote-screen-share-added', _ => {
if (webrtcCall.hasRemoteScreenShare()) {
console.log('Remote user sharing screen...');
}
})
Sets the video input device with the given id to be used during the call.
-
deviceId
:string
- Video input device identifier.
-
Promise<void>
- Promise that resolves tovoid
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.Builder.setVideo(true).build());
webrtcCall.on('established', _ => {
webrtcCall.setVideoInputDevice('videoDeviceId')
.catch(error => console.log(`Error: ${error}`));
});
Returns current camera orientation.
none
-
CameraOrientation
- Enum value which corresponds to the camera orientation.
let videoOptions = VideoOptions.builder().setCameraOrientation(CameraOrientation.BACK).build();
let webrtcCallOptions = WebrtcCallOptions.builder().setVideo(true).setVideoOptions(videoOptions).build();
let webrtcCall = infobipRTC.callWebrtc('alice', webrtcCallOptions);
console.log(`Camera orientation is: ${webrtcCall.cameraOrientation()}`);
Sets a local camera orientation to the given enum value.
-
CameraOrientation
- Enum value which corresponds to the camera orientation.
-
Promise<void>
- Promise that resolves tovoid
.
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().setVideo(true).build());
webrtcCall.on('established', _ => {
webrtcCall.setCameraOrientation(CameraOrientation.BACK)
.catch(error => console.log(`Error: ${error}`));
});
Sets the video filter to be used during the video call.
Passing null
will remove and release any already existing video filter.
-
videoFilter
:VideoFilter
- An object instance which implements theVideoFilter
interface.
-
Promise<void>
- Promise that resolves once the filter has been applied to the current video stream.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().setVideo(true).build());
let videoFilter = createVideoFilterImplementation();
webrtcCall.setVideoFilter(videoFilter);
Gets the video filter that has been set for the video call.
none
-
VideoFilter
- An object instance which implements theVideoFilter
interface.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().setVideo(true).build());
let videoFilter = createVideoFilterImplementation();
webrtcCall.setVideoFilter(videoFilter);
let currentVideoFilter = webrtcCall.videoFilter();
Convenience method that is used to remove the video filter if it is present.
none
-
Promise<void>
- Promise that resolves once the filter has been removed.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().setVideo(true).build());
let videoFilter = createVideoFilterImplementation();
webrtcCall.setVideoFilter(videoFilter);
webrtcCall.clearVideoFilter();
Gets an instance of LocalWebrtcCapturer
, which can be used to take screenshots of current user's or remote's videos.
none
-
LocalWebrtcCapturer
- Returns an instance of a capturer used for storing screenshots locally.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().setVideo(true).build());
let videoType = VideoType.CAMERA;
// we take a screenshot of the current user's camera, and download it to the local machine as a `.png` file
webrtcCall.localCapturer().takeLocalScreenshot(videoType)
.then(url => {
const link = document.createElement('a');
link.download = `local_${videoType.toString().toLowerCase()}.png`;
link.href = url;
link.click();
link.remove();
});
Gets an instance of ServerCapturer
, which is used to upload screenshots of current user's or remote's videos to the cloud.
These screenshots can subsequently be retrieved using the WebRTC Files API.
none
-
ServerCapturer
- Returns an instance of a capturer used to upload screenshots to the cloud.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().setVideo(true).build());
let videoType = VideoType.SCREENSHARE;
// take a screenshot of the remote user's screen share, which is directly uploaded to the server (cloud)
webrtcCall.serverlCapturer().takeRemoteScreenshot(videoType)
.then(fileResponse => {
console.log(`Screenshot uploaded to the server with id: ${fileResponse.id}, and name: ${fileResponse.name}`);
}).catch(err => {
console.log('There was an error uploading a screenshot to the server!');
});
Gets an instance of DataChannel
, that should be used to send and receive data during the current
call.
none
-
DataChannel
- Returns an instance of a data channel.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().setDataChannel(true).build());
webrtcCall.dataChannel().send('Hello world!', webrtcCall.counterpart())
.then(id => {
console.log(`Sent text with id: ${id} to ${webrtcCall.counterpart().identifier}`)
});
Configures the event handler for call events.
-
eventName
:CallsApiEvent
- Name of the application call event. Allowed values are a subset ofCallsApiEvent
. -
eventHandler
:CallsEventHandlers
- Function that will be called when specified event occurs, with exactly one parameter being passed to the function containing event information. Depending on the event, the passed parameter will contain a set of fields that will describe the event, namely:-
RINGING
- No additional data is provided in the event object.event = {}
-
EARLY_MEDIA
- AMediaStream
object representing the media being played is received in the event object.event = { stream: MediaStream }
-
ESTABLISHED
- AMediaStream
object representing the media in the call is received in the event object.event = { stream: MediaStream }
-
HANGUP
- A receivedErrorCode
object provides details about the reason for the call hang-up, along with aTotalMediaStats
object that offers a comprehensive summary of the call's audio statistics.event = { errorCode: ErrorCode, totalMediaStats: TotalMediaStats }
-
ERROR
- A receivedErrorCode
object provides details about the reason for the error occurrence.event = { errorCode: ErrorCode }
-
CAMERA_VIDEO_ADDED
- AMediaStream
object representing the media in the call is received in the event object.event = { stream: MediaStream }
-
CAMERA_VIDEO_UPDATED
- AMediaStream
object representing the media in the call is received in the event object.event = { stream: MediaStream }
-
CAMERA_VIDEO_REMOVED
- No additional data is provided in the event object.event = {}
-
SCREEN_SHARE_ADDED
- AMediaStream
object representing the media in the call is received in the event object.event = { stream: MediaStream }
-
SCREEN_SHARE_REMOVED
- AVideoRemovalReason
enum value giving additional info on the reason for removing the screen share.event = { reason: VideoRemovalReason }
-
REMOTE_MUTED
- No additional data is provided in the event object.event = {}
-
REMOTE_UNMUTED
- No additional data is provided in the event object.event = {}
-
REMOTE_CAMERA_VIDEO_ADDED
- AMediaStream
object representing the remote user's camera video stream.event = { stream: MediaStream }
-
REMOTE_CAMERA_VIDEO_REMOVED
- No additional data is provided in the event object.event = {}
-
REMOTE_SCREEN_SHARE_ADDED
- AMediaStream
object representing the remote user's screen share stream.event = { stream: MediaStream }
-
REMOTE_SCREEN_SHARE_REMOVED
- No additional data is provided in the event object.event = {}
-
NETWORK_QUALITY_CHANGED
- An event containing a NetworkQuality and a CurrentMediaStats objects that provides details on the network quality of a local participant and its corresponding media stats.event = { networkQuality: NetworkQuality, currentMediaStats: CurrentMediaStats }
-
REMOTE_NETWORK_QUALITY_CHANGED
- An event containing a NetworkQuality object that provides details on the network quality of a remote participantevent = { networkQuality: NetworkQuality }
-
CALL_RECORDING_STARTED
- An event that is triggered once a call recording starts. It includes RecordingType object which details the type of recording initiated.event = { recordingType: RecordingType }
-
N/A
Let's assume you have an audio HTML element with the id callAudio
and video HTML elements with the ids cameraVideo
, remoteCameraVideo
,
screenShareVideo
, and remoteScreenShareVideo
.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.RINGING, () => {
console.log('Ringing...');
});
webrtcCall.on(CallsApiEvent.EARLY_MEDIA, (event) => {
console.log('Ringtone playing...');
$('#callAudio').srcObject = event.stream;
});
webrtcCall.on(CallsApiEvent.ESTABLISHED, (event) => {
$('#callAudio').srcObject = event.stream;
});
webrtcCall.on(CallsApiEvent.HANGUP, (event) => {
console.log(`Call finished. Status: ${event.errorCode.name}`);
});
webrtcCall.on(CallsApiEvent.ERROR, (event) => {
console.log(`An error has occurred. Error: ${event.errorCode.name}`);
});
webrtcCall.on(CallsApiEvent.CAMERA_VIDEO_ADDED, (event) => {
$('#cameraVideo').srcObject = event.stream;
});
webrtcCall.on(CallsApiEvent.REMOTE_CAMERA_VIDEO_ADDED, (event) => {
$('#remoteCameraVideo').srcObject = event.stream;
});
webrtcCall.on(CallsApiEvent.SCREEN_SHARE_ADDED, (event) => {
$('#screenShareVideo').srcObject = event.stream;
});
webrtcCall.on(CallsApiEvent.REMOTE_SCREEN_SHARE_ADDED, (event) => {
$('#remoteScreenShareVideo').srcObject = event.stream;
});
webrtcCall.on(CallsApiEvent.REMOTE_MUTED, (event) => {
console.log(`Remote user is muted`);
});
webrtcCall.on(CallsApiEvent.REMOTE_UNMUTED, (event) => _ => {
console.log(`Remote user is unmuted`);
});
webrtcCall.on(CallsApiEvent.NETWORK_QUALITY_CHANGED, (event) => {
console.log(`Local network quality is: ${NetworkQuality[event.networkQuality]}`);
});
webrtcCall.on(CallsApiEvent.REMOTE_NETWORK_QUALITY_CHANGED, (event) => {
console.log(`Remote network quality is: ${NetworkQuality[event.networkQuality]}`);
});
webrtcCall.on(CallsApiEvent.CALL_RECORDING_STARTED, (event) => {
console.log(`Call recording started with type ${event.recordingType}`);
});