infobip-rtc
Version:
Infobip RTC JavaScript SDK - Infobip WebRTC API Implementation
75 lines • 3.82 kB
JavaScript
import { DefaultApplicationCall } from "./DefaultApplicationCall";
import { CallStatus } from "../CallStatus";
import { InternalApplicationCallOptions } from "../options/InternalApplicationCallOptions";
import { WsAction } from "../ws/WsAction";
export class DefaultOutgoingApplicationCall extends DefaultApplicationCall {
constructor(eventEmitter, gateway, logger, rtcConfig, device, callsConfigurationId, options, currentUserIdentity, token, apiUrl) {
super(eventEmitter, gateway, logger, rtcConfig, device, callsConfigurationId, options, currentUserIdentity, token, apiUrl);
this.localAudio = { active: options.audio };
this.localCameraVideo = { active: options.video };
this.createAudioPeerConnection();
let deviceId = options.videoOptions?.deviceId;
if (deviceId) {
this.setVideoInputDevice(deviceId);
}
this.negotiateAudio(options);
}
async negotiateAudio(options) {
try {
let audio = options.audio || options.audioOptions?.detectTalkingWhileMuted;
const mediaStream = await this.getLocalMediaStream(audio, options.video, options.videoOptions?.cameraOrientation, options.videoOptions?.cameraVideoFrameRate);
if (this.isFinished()) {
this.logger.warn(`Call is no longer connecting, aborting audio negotiation`, this.callId);
this.stopAllTracks(mediaStream);
return;
}
if (options.video && mediaStream.getVideoTracks().length > 0) {
let videoStream = new MediaStream([mediaStream.getVideoTracks()[0]]);
await this.setLocalVideoStream(videoStream);
}
let audioStream = audio ? new MediaStream([mediaStream.getAudioTracks()[0]]) : new MediaStream();
this.setLocalAudioStream(audioStream);
this.createAudioTransceiver();
let offer = await this.audioPC.peerConnection.createOffer();
offer = await this.setLocalDescription(this.audioPC.peerConnection, offer);
this.sendOffer(offer, options);
}
catch (error) {
this.handleCallFlowError(error);
}
}
sendOffer(offer, options) {
const isInternal = options instanceof InternalApplicationCallOptions;
let customData = options.customData;
let callsConfigurationId = isInternal ?
(options.callsConfigurationId() ?? DefaultOutgoingApplicationCall.WEBRTC_CALLS_CONFIGURATION_ID) :
this._callsConfigurationId;
this.callStatus = CallStatus.CALLING;
this.gateway.send({
action: WsAction.APPLICATION_CALL,
callId: this.callId,
destination: this._callsConfigurationId,
applicationId: callsConfigurationId,
callsConfigurationId: callsConfigurationId,
platform: {
...(options.platformOptions?.applicationId && { applicationId: options.platformOptions?.applicationId }),
...(options.platformOptions?.entityId && { entityId: options.platformOptions?.entityId }),
},
...(options.videoOptions?.videoMode && { videoMode: options.videoOptions?.videoMode }),
description: offer,
customData: customData,
...isInternal && { internalCustomData: options.internalCustomData() },
media: {
audio: {
muted: !this.localAudio.active,
},
video: {
camera: this.localCameraVideo.active
}
},
autoReconnect: options.autoReconnect
});
}
}
DefaultOutgoingApplicationCall.WEBRTC_CALLS_CONFIGURATION_ID = "WEBRTC";
//# sourceMappingURL=DefaultOutgoingApplicationCall.js.map