sinch-rtc
Version:
RTC JavaScript/Web SDK
70 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionStateBase = void 0;
const models_1 = require("../mxp/models");
const fsm_1 = require("./fsm");
const TerminationCause_1 = require("./TerminationCause");
const mxp_1 = require("../mxp");
class SessionStateBase extends fsm_1.FsmState {
get Session() {
return this.session;
}
constructor(state, session) {
super(state, session);
this.CallSetupTimeoutMs = 60000;
this.CallProgressTimeoutMs = 10000;
this.CallACKWindowTimeoutMs = 10000;
this.session = session;
}
onTimeout(_) {
this.callTerminationCause = TerminationCause_1.TerminationCause.Timeout;
}
terminateBasedOnMessage(message, defaultCause) {
var _a;
this.callTerminationCause = (_a = message.getTerminationCause()) !== null && _a !== void 0 ? _a : defaultCause;
this.session.terminate(message.getError());
}
onExit(_) {
this.Session.cancelScheduledTimeouts(this);
}
timeoutRelativeToStart(t) {
return this.Session.timeoutRelativeToStart(t);
}
sendJoined(join) {
this.sendOutboundMessage(this.Session.newMessage()
.method(models_1.Method.Joined)
.body(mxp_1.Codec.encodeClient(join.from))
.build());
}
sendError(error) {
const builder = this.Session.newMessage().method(models_1.Method.Error);
if (error) {
builder.body(models_1.Body.error(error));
}
this.sendOutboundMessage(builder.build());
}
sendOutboundMessage(m) {
this.Session.sendOutboundMessage(m);
}
hasSentOutboundMessage(method) {
return this.Session.hasSentMessage((m) => m.method == method);
}
onLocalSessionDescription(sd) {
this.sendOutboundMessage(this.Session.newMessage()
.method(models_1.Method.PeerEvent)
.body(models_1.Body.sdp(sd.asJson()))
.build());
}
onLocalCandidate(candidates) {
candidates.forEach((candidate) => {
const builder = this.Session.newMessage()
.method(models_1.Method.PeerEvent)
.body(models_1.Body.sdp(candidate.data));
if (candidate.instanceId)
builder.values({ to: candidate.instanceId });
this.sendOutboundMessage(builder.build());
});
}
}
exports.SessionStateBase = SessionStateBase;
//# sourceMappingURL=SessionStateBase.js.map