Skip to content

WebrtcCall

Adnan Elezović edited this page Mar 30, 2023 · 15 revisions

extends Call



options()

Description

Returns the call options this call was started with.

Arguments

  • none

Returns



customData()

Description

Getter for the customData field.

Arguments

  • none

Returns

  • CustomData - Value of the customData field that is defined as an object of key-value string pairs.

Example

let webrtcCallOptions = WebrtcCallOptions.builder().setCustomData({"city": "New York"}).build();
console.log(`WebRTC call with customData options: ${JSON.stringify(webrtcCallOptions.customData)}`);



pauseIncomingVideo()

Description

Stop receiving the video media of the remote participant.

Arguments

  • none

Returns

  • N/A

Example

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();
        }
    });
});



resumeIncomingVideo()

Description

Start receiving the video media of the remote participant.

Arguments

  • none

Returns

  • N/A

Example

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();
        }
    });
});



cameraVideo(cameraVideo)

Description

Controls whether the local camera video should be enabled. For video calls it is enabled by default.

Arguments

  • cameraVideo: boolean - Whether local camera video should be enabled.

Returns

Example

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));
});



hasCameraVideo()

Description

Returns information whether the current call has local camera video.

Arguments

  • none

Returns

  • boolean - true if the call has local camera video, otherwise false.

Example

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.`);



hasRemoteCameraVideo()

Description

Returns information whether the current call has remote video.

Arguments

  • none

Returns

  • boolean - true if the call has remote video, otherwise false.

Example

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}.`);
});



screenShare(screenShare)

Description

Toggles sharing the screen during the call.

This method is not available in mobile versions of browsers.

Arguments

  • screenShare: boolean - Controls whether the screen sharing should be started or stopped.

Returns

Example

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');
})



hasScreenShare()

Description

Returns information whether screen is being shared with remote peer.

Arguments

  • none

Returns

  • boolean - true if screen is being shared, otherwise false.

Example

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...');
    }
})



hasRemoteScreenShare()

Description

Returns information whether the remote user is sharing their screen.

Arguments

  • none

Returns

  • boolean - true if screen is being shared, otherwise false.

Example

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...');
    }
})



setVideoInputDevice(deviceId)

Description

Sets the video input device with the given id to be used during the call.

Arguments

  • deviceId: string - Video input device identifier.

Returns

Example

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));
});



cameraOrientation()

Description

Returns current camera orientation.

Arguments

  • none

Returns

Example

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()}`);



setCameraOrientation(cameraOrientation)

Description

Sets a local camera orientation to the given enum value.

Arguments

Returns

Example

let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().setVideo(true).build());
webrtcCall.on('established', _ => {
    webrtcCall.setCameraOrientation(CameraOrientation.BACK)
        .catch(error => console.log("Error: {}", error));
});



setVideoFilter(videoFilter)

Description

Sets the video filter to be used during the video call. Passing null will remove and release any already existing video filter.

Arguments

  • videoFilter: VideoFilter - An object instance which implements the VideoFilter interface.

Returns

  • Promise<void> - Promise that resolves once the filter has been applied to the current video stream.

Example

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);



videoFilter()

Description

Gets the video filter that has been set for the video call.

Arguments

  • none

Returns

  • VideoFilter - An object instance which implements the VideoFilter interface.

Example

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();



on(eventName, eventHandler)

Description

Configures the event handler for call events.

Arguments

  • eventName: CallsApiEvent - Name of the application call event. Allowed values are a subset of CallsApiEvent.

  • 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 - A MediaStream object representing the media being played is received in the event object.

      event = {stream: MediaStream}
    • ESTABLISHED - A MediaStream object representing the media in the call is received in the event object.

      event = {stream: MediaStream}
    • HANGUP - Error code data is received in the event object containing three string values that describe why the call hung up.

      event = {id: string, name: string, description: string}
    • ERROR - Error code data is received in the event object containing three string values that describe what caused the error.

      event = {id: string, name: string, description: string}
    • CAMERA_VIDEO_ADDED - A MediaStream object representing the media in the call is received in the event object.

      event = {stream: MediaStream}
    • CAMERA_VIDEO_UPDATED - A MediaStream 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 - A MediaStream object representing the media in the call is received in the event object.

      event = {stream: MediaStream}
    • SCREEN_SHARE_REMOVED - No additional data is provided in the event object.

      event = {}
    • 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 - A MediaStream 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 - A MediaStream 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 = {}

Returns

  • N/A

Example

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.name}`);
});
webrtcCall.on(CallsApiEvent.ERROR, (event) => {
    console.log(`An error has occurred. Error: ${event.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`);
});

Tutorials

Migration guides

Reference documentation

Clone this wiki locally