infobip-rtc
Version:
Infobip RTC JavaScript SDK - Infobip WebRTC API Implementation
61 lines • 5.25 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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) {
var _a, _b;
super(eventEmitter, gateway, logger, rtcConfig, device, callsConfigurationId, options, currentUserIdentity, token, apiUrl);
this.localAudio = { active: (_a = options === null || options === void 0 ? void 0 : options.audio) !== null && _a !== void 0 ? _a : true };
this.localCameraVideo = { active: (_b = options === null || options === void 0 ? void 0 : options.video) !== null && _b !== void 0 ? _b : false };
this.createAudioPeerConnection();
this.negotiateAudio(options);
}
negotiateAudio(options) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
const stream = yield this.getLocalAudioStream(options === null || options === void 0 ? void 0 : options.audio, options === null || options === void 0 ? void 0 : options.video, (_a = options === null || options === void 0 ? void 0 : options.videoOptions) === null || _a === void 0 ? void 0 : _a.cameraOrientation, (_b = options === null || options === void 0 ? void 0 : options.videoOptions) === null || _b === void 0 ? void 0 : _b.cameraVideoFrameRate);
if (this.isFinished()) {
this.logger.warn(`Call is no longer connecting, aborting audio negotiation`, this.callId);
stream === null || stream === void 0 ? void 0 : stream.getAudioTracks().forEach((track) => track.stop());
return;
}
this.setLocalAudioStream(stream);
this.createAudioTransceiver();
let offer = yield this.audioPC.peerConnection.createOffer();
offer = yield this.setLocalDescription(this.audioPC.peerConnection, offer);
this.sendOffer(offer, options);
}
catch (error) {
this.handleCallFlowError(error);
}
});
}
sendOffer(offer, options) {
var _a, _b, _c, _d, _e, _f;
const isInternal = options instanceof InternalApplicationCallOptions;
let customData = options === null || options === void 0 ? void 0 : options.customData;
let callsConfigurationId = isInternal ? DefaultOutgoingApplicationCall.WEBRTC_CALLS_CONFIGURATION_ID : this._callsConfigurationId;
this.callStatus = CallStatus.CALLING;
this.gateway.send(Object.assign(Object.assign(Object.assign(Object.assign({ action: WsAction.APPLICATION_CALL, callId: this.callId, destination: this._callsConfigurationId, applicationId: callsConfigurationId, callsConfigurationId: callsConfigurationId, platform: Object.assign(Object.assign({}, (((_a = options === null || options === void 0 ? void 0 : options.platformOptions) === null || _a === void 0 ? void 0 : _a.applicationId) && { applicationId: (_b = options === null || options === void 0 ? void 0 : options.platformOptions) === null || _b === void 0 ? void 0 : _b.applicationId })), (((_c = options === null || options === void 0 ? void 0 : options.platformOptions) === null || _c === void 0 ? void 0 : _c.entityId) && { entityId: (_d = options === null || options === void 0 ? void 0 : options.platformOptions) === null || _d === void 0 ? void 0 : _d.entityId })) }, (((_e = options === null || options === void 0 ? void 0 : options.videoOptions) === null || _e === void 0 ? void 0 : _e.videoMode) && { videoMode: (_f = options === null || options === void 0 ? void 0 : options.videoOptions) === null || _f === void 0 ? void 0 : _f.videoMode })), { description: offer, customData: customData }), isInternal && { internalCustomData: options === null || options === void 0 ? void 0 : options.internalCustomData() }), { media: {
audio: {
muted: !this.localAudio.active,
},
video: {
camera: this.localCameraVideo.active
}
}, autoReconnect: options === null || options === void 0 ? void 0 : options.autoReconnect }));
}
}
DefaultOutgoingApplicationCall.WEBRTC_CALLS_CONFIGURATION_ID = "WEBRTC";
//# sourceMappingURL=DefaultOutgoingApplicationCall.js.map