sinch-rtc
Version:
RTC JavaScript/Web SDK
122 lines • 6.08 kB
JavaScript
"use strict";
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutboundCall = void 0;
const mxp_1 = require("../mxp");
const api_1 = require("../ocra/api");
const DefaultCall_1 = require("./DefaultCall");
const Sdp_1 = require("../session/jsep/Sdp");
const constants_1 = require("../constants");
const PushPayload_1 = require("../push/PushPayload");
const ClientEvent_1 = require("./reporting/ClientEvent");
const SinchError_1 = require("../SinchError");
class OutboundCall extends DefaultCall_1.DefaultCall {
constructor(destination, video, session, mxpChannel, pushSender, media, callInitiator, useRelayIceCandidatesOnly, features, clientEventsCollector, callQualityCollector, warningControllerFactory, iceServers) {
super(video, session, mxpChannel, media, useRelayIceCandidatesOnly, clientEventsCollector, callQualityCollector, warningControllerFactory, iceServers);
this.destination = destination;
this.pushSender = pushSender;
this.callInitiator = callInitiator;
this.features = features;
this.callInitiated = false;
this.generatePushPayload = () => (0, PushPayload_1.generatePushPayload)(this);
this.onLocalDescription = (message) => {
if (this.callInitiated) {
this.withSession((s) => s.setLocalSessionDescription(message));
}
else
this.initiateCall(message.data);
};
}
initiateCall(offer) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
const isTurnEnabled = this.features.getFeatureFlag(constants_1.FeatureFlag.UseTurn);
this.callInitiated = true;
this.clientEventsCollector.addEvent(ClientEvent_1.ClientEvent.createClientEventType(ClientEvent_1.ClientEventName.OCRA_CALL_INIT_REQUEST));
const response = yield this.callInitiator.initiateCall({
callInitiationRequest: {
callId: this.id,
destination: this.destination,
requestedAudio: true,
requestedVideo: this.requestedVideo,
rtcOffer: { type: "offer", sdp: offer },
publicCallHeaders: this.headers,
legacyMediaProxyEngage: !isTurnEnabled,
mxpInstanceId: this.localPeer.instanceId,
cli: this.localPeer.cli,
},
});
this.clientEventsCollector.addEvent(ClientEvent_1.ClientEvent.createClientEventType(ClientEvent_1.ClientEventName.OCRA_CALL_INIT_REQUEST_COMPLETE));
if (response.publicCallHeaders != null) {
this.setHeaders(response.publicCallHeaders);
}
this.setMxpSignalingConfiguration(new mxp_1.SymmetricKey(response.mxpEncryptionKey), response.mxpSignalChannel);
if (response.legacyRelayIceCandidates) {
this.setLegacyRelayCandidates(response.legacyRelayIceCandidates
.map((c) => this.mapLegacyRelayCandidates(offer, c))
.filter((c) => c != undefined));
}
if ((_a = response.instances) === null || _a === void 0 ? void 0 : _a.length) {
this.sendPushNotifications(response.instances);
this.setPushNotificationRequestSent();
}
this.withSession((s) => {
s.instancesToACK = this.pushSender.getManagedPushRecipients(response.instances);
});
}
catch (error) {
if (error instanceof SinchError_1.SinchError) {
this.clientEventsCollector.addEvent(ClientEvent_1.ClientEvent.createClientEventType(ClientEvent_1.ClientEventName.OCRA_CALL_INIT_REQUEST_COMPLETE, {
type: api_1.EventResultTypeEnum.Failure,
errorCode: error.code,
errorDomain: api_1.ClientErrorDomain.Http,
}));
this.hangup(error);
}
else {
this.hangup(new SinchError_1.SinchError(error.message, SinchError_1.ErrorCode.Generic, SinchError_1.ErrorType.Http));
}
}
});
}
sendPushNotifications(instances) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield this.pushSender.sendPush(this, instances);
}
catch (error) {
console.error("Failed to send push notification:", error);
}
});
}
mapLegacyRelayCandidates(offer, candidate) {
const sdp = Sdp_1.Sdp.parse(offer);
if (sdp.description.media.length > 0) {
return JSON.stringify({
cand: candidate,
sdpMLI: 0,
sdpMid: sdp.description.media[0].mid,
});
}
else {
console.error(`Invalid legacy relay candidate: ${candidate}`);
}
}
get remoteUserId() {
return this.destination.identity;
}
get remoteDomain() {
return this.destination.domain;
}
}
exports.OutboundCall = OutboundCall;
//# sourceMappingURL=OutboundCall.js.map