sinch-rtc
Version:
RTC JavaScript/Web SDK
116 lines • 4.66 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultCallDetails = void 0;
const Direction_1 = require("../session/Direction");
const TerminationCause_1 = require("../session/TerminationCause");
const SinchError_1 = require("../SinchError");
const CallEndCause_1 = require("./CallEndCause");
class DefaultCallDetails {
constructor(call, session) {
this.call = call;
this.session = session;
this.hadVideoStream = false;
this.hadAudioStream = false;
this.requestedVideo = false;
this.requestedAudio = true;
this.startedTime = call.createdAt;
this.requestedVideo = call.requestedVideo;
this.direction = call.direction;
call.addInternalListener(this);
}
get duration() {
return this.calculateDurationMs(this.establishedTime, this.endedTime);
}
get setupDuration() {
return this.calculateDurationMs(this.startedTime, this.progressTime);
}
get notifyingDuration() {
return this.calculateDurationMs(this.progressTime, this.rungTime);
}
get ringingDuration() {
var _a, _b, _c;
const start = this.direction === Direction_1.Direction.Inbound ? this.startedTime : this.rungTime;
const end = this.direction === Direction_1.Direction.Outbound
? (_a = this.answeredTime) !== null && _a !== void 0 ? _a : this.endedTime
: (_c = (_b = this.acceptedTime) !== null && _b !== void 0 ? _b : this.answeredTime) !== null && _c !== void 0 ? _c : this.endedTime;
return this.calculateDurationMs(start, end);
}
get acceptingDuration() {
return this.calculateDurationMs(this.acceptedTime, this.answeredTime);
}
get connectingDuration() {
var _a;
const start = this.direction === Direction_1.Direction.Inbound
? (_a = this.acceptedTime) !== null && _a !== void 0 ? _a : this.answeredTime
: this.answeredTime;
return this.calculateDurationMs(start, this.establishedTime);
}
get error() {
return this.inferCallError();
}
get endCause() {
return this.mapCallEndCause(this.session.terminationCause);
}
onCallEnded(_) {
this.endedTime = new Date();
this.call.removeInternalListener(this);
}
onCallProgressing(_) {
this.progressTime = new Date();
}
onCallRinging(_) {
this.rungTime = new Date();
}
onCallAccepted(_) {
this.acceptedTime = new Date();
}
onCallAnswered(_) {
this.answeredTime = new Date();
}
onCallEstablished(_) {
this.establishedTime = new Date();
}
onRemoteTrack(_, track) {
if (track.kind == "video")
this.hadVideoStream = true;
else if (track.kind == "audio")
this.hadAudioStream = true;
}
mapCallEndCause(terminationCause) {
switch (terminationCause) {
case TerminationCause_1.TerminationCause.Canceled:
return CallEndCause_1.CallEndCause.Canceled;
case TerminationCause_1.TerminationCause.Denied:
return CallEndCause_1.CallEndCause.Denied;
case TerminationCause_1.TerminationCause.Error:
case TerminationCause_1.TerminationCause.IceFailedToConnect:
return CallEndCause_1.CallEndCause.Failure;
case TerminationCause_1.TerminationCause.HungUp:
return CallEndCause_1.CallEndCause.HungUp;
case TerminationCause_1.TerminationCause.None:
return CallEndCause_1.CallEndCause.None;
case TerminationCause_1.TerminationCause.Timeout:
return CallEndCause_1.CallEndCause.NoAnswer;
case TerminationCause_1.TerminationCause.OtherPeerAccepted:
return CallEndCause_1.CallEndCause.OtherDeviceAnswered;
case TerminationCause_1.TerminationCause.Inactive:
return CallEndCause_1.CallEndCause.Inactive;
}
}
inferCallError() {
if (this.session.terminationCause === TerminationCause_1.TerminationCause.IceFailedToConnect) {
return new SinchError_1.SinchError(SinchError_1.ErrorMessage.ICE_FAILED_TO_CONNECT, SinchError_1.ErrorCode.CallFailedToConnectIce, SinchError_1.ErrorType.Network);
}
return this.session.error;
}
calculateDurationMs(start, end) {
if (!start || !end) {
return 0;
}
else {
return end.getTime() - start.getTime();
}
}
}
exports.DefaultCallDetails = DefaultCallDetails;
//# sourceMappingURL=DefaultCallDetails.js.map