UNPKG

sinch-rtc

Version:

RTC JavaScript/Web SDK

105 lines 3.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FsmState = void 0; const jsep_1 = require("../jsep"); const TerminationCause_1 = require("../TerminationCause"); const SessionState_1 = require("../SessionState"); const models_1 = require("../../mxp/models"); const Errors_1 = require("../../utils/Errors"); const TransitionSource_1 = require("./TransitionSource"); const TimerEventType_1 = require("./TimerEventType"); class FsmState { constructor(fsmSessionState, transitions) { this.fsmSessionState = fsmSessionState; this.transitions = transitions; this.callTerminationCause = TerminationCause_1.TerminationCause.None; } get terminationCause() { return this.callTerminationCause; } set terminationCause(terminationCause) { this.callTerminationCause = terminationCause; } get sessionState() { return this.fsmSessionState; } get stateName() { return this.constructor.name; } onInboundMessage(m) { if (!this.handleInboundMessage(m)) { console.error(`Received unexpected message: ${models_1.Method[m.method]} when in ${this.stateName} state. Ignoring...`); } } onSessionDescription(source, sd) { if (jsep_1.Source.Local == source) this.onLocalSessionDescription(sd); } onCandidate(source, candidates) { if (jsep_1.Source.Local == source) { this.onLocalCandidate(candidates); } } onStateTimeout(t) { if (t.type != TimerEventType_1.TimerEventType.Termination) { return; } this.onTimeout(t); this.transition(SessionState_1.SessionState.Terminated, TransitionSource_1.TransitionSource.LocalAction); } onTimeout(_) { // do nothing } onException(e) { console.log(`FsmState exception: ${e}`); this.transition(SessionState_1.SessionState.Terminated, TransitionSource_1.TransitionSource.LocalAction); } terminate(e, source) { if (e) this.callTerminationCause = TerminationCause_1.TerminationCause.Error; this.transition(SessionState_1.SessionState.Terminated, source !== null && source !== void 0 ? source : TransitionSource_1.TransitionSource.LocalAction); } terminateWithCause(cause, source) { this.callTerminationCause = cause; this.terminate(undefined, source); } accept() { this.onAccept(); } enter(previous, source) { this.callTerminationCause = previous.callTerminationCause; this.onEnter(source); } exit(previous, source) { if (previous.sessionState == SessionState_1.SessionState.Terminated) this.onWillTerminate(source); this.onExit(source); } transition(to, source) { var _a; (_a = this.transitions) === null || _a === void 0 ? void 0 : _a.transition(this, to, source); } onEnter(_) { // do nothing } onExit(_) { // do nothing } onWillTerminate(_) { // do nothing } handleInboundMessage(_) { return false; } onAccept() { throw new Errors_1.InvalidOperationError(`Accept() is not a valid action for current state (${this.stateName})`); } onLocalSessionDescription(_) { // do nothing } onLocalCandidate(_) { // do nothing } } exports.FsmState = FsmState; //# sourceMappingURL=FsmState.js.map