-
Notifications
You must be signed in to change notification settings - Fork 2
WebrtcCall
extends Call
options(): WebrtcCallOptionspauseIncomingVideo(): voidresumeIncomingVideo(): voidcameraVideo(cameraVideo: boolean): Promise<void>hasCameraVideo(): booleanhasRemoteCameraVideo(): booleanscreenShare(screenShare: boolean): Promise<void>startScreenShare(displayOptions?: DisplayOptions): Promise<void>stopScreenShare(): Promise<void>hasScreenShare(): booleanhasRemoteScreenShare(): booleansetVideoInputDevice(deviceId: string): Promise<void>cameraOrientation(): CameraOrientationsetCameraOrientation(cameraOrientation: CameraOrientation): Promise<void>setVideoFilter(videoFilter: VideoFilter): Promise<void>videoFilter(): VideoFilterclearVideoFilter(): Promise<void>localCapturer(): LocalWebrtcCapturerserverCapturer(): ServerWebrtcCapturerdataChannel(): DataChannelon(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())}`);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()
.catch(error => console.log(`Error: ${error}`));
}
});
});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()
.catch(error => console.log(`Error: ${error}`));
}
});
});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-trueif 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-trueif 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
startScreenShareandstopScreenSharemethods.
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-trueif 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)
.catch(error => console.log(`Error: ${error}`));
});
webrtcCall.on('screen-share-added', _ => {
if (webrtcCall.hasScreenShare()) {
console.log('Sharing screen...');
}
})Returns information whether the remote user is sharing their screen.
none
-
boolean-trueif 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 theVideoFilterinterface.
-
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 theVideoFilterinterface.
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- AMediaStreamobject representing the media being played is received in the event object.event = { stream: MediaStream }
-
ESTABLISHED- AMediaStreamobject representing the media in the call is received in the event object.event = { stream: MediaStream }
-
HANGUP- A receivedErrorCodeobject provides details about the reason for the call hang-up, along with aTotalMediaStatsobject that offers a comprehensive summary of the call's audio statistics.event = { errorCode: ErrorCode, totalMediaStats: TotalMediaStats }
-
ERROR- A receivedErrorCodeobject provides details about the reason for the error occurrence.event = { errorCode: ErrorCode }
-
CAMERA_VIDEO_ADDED- AMediaStreamobject representing the media in the call is received in the event object.event = { stream: MediaStream }
-
CAMERA_VIDEO_UPDATED- AMediaStreamobject 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- AMediaStreamobject representing the media in the call is received in the event object.event = { stream: MediaStream }
-
SCREEN_SHARE_REMOVED- AVideoRemovalReasonenum 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 = {}
-
TALKING_WHILE_MUTED- No additional data is provided in the event object.event = {}
-
REMOTE_DISCONNECTED- No additional data is provided in the event object.event = {}
-
REMOTE_RECONNECTED- No additional data is provided in the event object.event = {}
-
REMOTE_CAMERA_VIDEO_ADDED- AMediaStreamobject 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- AMediaStreamobject 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 enum value which corresponds to the type of recording initiated.event = { recordingType: RecordingType }
-
RECONNECTING- No additional data is provided in the event object.event = {}
-
RECONNECTED- No additional data is provided in the event object.event = {}
-
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', WebrtcCallOptions.builder()
.setAutoReconnect(true) // Required in order to receive RECONNECTING and RECONNECTED events
.build());
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.REMOTE_DISCONNECTED, (event) => {
console.log('Remote user has been disconnected!');
});
webrtcCall.on(CallsApiEvent.REMOTE_RECONNECTED, (event) => {
console.log('Remote user has been reconnected!');
});
webrtcCall.on(CallsApiEvent.DISCONNECTED, (event) => {
console.log('Call disconnected!');
});
webrtcCall.on(CallsApiEvent.RECONNECTED, (event) => {
console.log('Call reconnected!');
});
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.TALKING_WHILE_MUTED, (event) => {
console.log(`You are talking while muted. Do you want to unmute?`);
});
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}`);
});