agora-rte-sdk 2.8.21 → 2.8.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/lib/configs/index.d.ts +8 -6
- package/lib/configs/index.js +8 -6
- package/lib/core/engine/index.js +1 -7
- package/lib/core/logger/index.d.ts +1 -0
- package/lib/core/logger/index.js +22 -2
- package/lib/core/logger/log.worker.js +4 -2
- package/lib/core/media/control.d.ts +11 -8
- package/lib/core/media/control.js +42 -32
- package/lib/core/media/player.d.ts +9 -0
- package/lib/core/media/player.js +36 -0
- package/lib/core/media/track.d.ts +8 -1
- package/lib/core/media/track.js +18 -0
- package/lib/core/media/type.d.ts +113 -0
- package/lib/core/media/type.js +31 -0
- package/lib/core/processor/channel-msg/data.d.ts +1 -0
- package/lib/core/processor/channel-msg/data.js +5 -0
- package/lib/core/processor/channel-msg/handler.d.ts +1 -3
- package/lib/core/processor/channel-msg/handler.js +20 -21
- package/lib/core/processor/channel-msg/message-parser.d.ts +6 -0
- package/lib/core/processor/channel-msg/message-parser.js +57 -0
- package/lib/core/processor/channel-msg/struct.d.ts +5 -0
- package/lib/core/processor/channel-msg/synchronizer.d.ts +7 -14
- package/lib/core/processor/channel-msg/synchronizer.js +33 -48
- package/lib/core/processor/peer-msg/handler.d.ts +16 -0
- package/lib/core/processor/peer-msg/handler.js +57 -0
- package/lib/core/processor/peer-msg/struct.d.ts +4 -0
- package/lib/core/processor/type.d.ts +200 -0
- package/lib/core/rc/index.js +6 -2
- package/lib/core/rtc/adapter/base.d.ts +6 -7
- package/lib/core/rtc/adapter/electron/device.d.ts +0 -1
- package/lib/core/rtc/adapter/electron/device.js +0 -5
- package/lib/core/rtc/adapter/electron/index.d.ts +6 -7
- package/lib/core/rtc/adapter/electron/index.js +22 -24
- package/lib/core/rtc/adapter/web/client.d.ts +11 -9
- package/lib/core/rtc/adapter/web/client.js +40 -38
- package/lib/core/rtc/adapter/web/device.d.ts +0 -1
- package/lib/core/rtc/adapter/web/device.js +0 -5
- package/lib/core/rtc/adapter/web/dispatcher.d.ts +61 -0
- package/lib/core/rtc/adapter/web/dispatcher.js +166 -0
- package/lib/core/rtc/adapter/web/index.d.ts +11 -7
- package/lib/core/rtc/adapter/web/index.js +25 -16
- package/lib/core/rtc/adapter/web/thread.d.ts +18 -11
- package/lib/core/rtc/adapter/web/thread.js +241 -133
- package/lib/core/rtc/channel.d.ts +2 -3
- package/lib/core/rtc/index.d.ts +5 -4
- package/lib/core/rtc/index.js +12 -12
- package/lib/core/rtc/type.d.ts +0 -4
- package/lib/core/services/api.d.ts +15 -0
- package/lib/core/services/api.js +36 -1
- package/lib/core/utils/events.d.ts +0 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +24 -17
- package/lib/scene/index.d.ts +1 -5
- package/lib/scene/index.js +88 -66
- package/lib/scene/state-sync.d.ts +21 -0
- package/lib/scene/state-sync.js +169 -0
- package/package.json +1 -1
package/lib/scene/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
require("core-js/modules/es.reflect.construct.js");
|
|
4
4
|
require("core-js/modules/es.object.keys.js");
|
|
5
5
|
require("core-js/modules/es.symbol.js");
|
|
6
|
-
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
7
6
|
require("core-js/modules/es.object.get-own-property-descriptors.js");
|
|
8
7
|
require("core-js/modules/es.object.define-properties.js");
|
|
9
8
|
require("core-js/modules/es.object.define-property.js");
|
|
@@ -26,7 +25,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
26
25
|
value: true
|
|
27
26
|
});
|
|
28
27
|
exports.AgoraRteScene = void 0;
|
|
29
|
-
require("core-js/modules/es.function.bind.js");
|
|
30
28
|
require("core-js/modules/es.array.join.js");
|
|
31
29
|
require("core-js/modules/es.array.map.js");
|
|
32
30
|
require("core-js/modules/es.array.find.js");
|
|
@@ -39,15 +37,16 @@ require("core-js/modules/es.string.iterator.js");
|
|
|
39
37
|
require("core-js/modules/es.array.iterator.js");
|
|
40
38
|
require("core-js/modules/es.object.to-string.js");
|
|
41
39
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
42
|
-
|
|
40
|
+
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
43
41
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
42
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
44
43
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
45
44
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
46
45
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
47
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
48
46
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
49
47
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
50
48
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
49
|
+
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
|
51
50
|
var _synchronizer = require("../core/processor/channel-msg/synchronizer");
|
|
52
51
|
var _struct = require("../core/processor/channel-msg/struct");
|
|
53
52
|
var _rtm = require("../core/rtm");
|
|
@@ -62,7 +61,10 @@ var _configs = require("../configs");
|
|
|
62
61
|
var _log = require("../core/decorator/log");
|
|
63
62
|
var _type = require("../type");
|
|
64
63
|
var _api = require("../core/services/api");
|
|
65
|
-
var
|
|
64
|
+
var _stateSync = require("./state-sync");
|
|
65
|
+
var _handler2 = require("../core/processor/peer-msg/handler");
|
|
66
|
+
var _decorator = require("../core/decorator");
|
|
67
|
+
var _dec, _class, _class2;
|
|
66
68
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
67
69
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
68
70
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -70,7 +72,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
70
72
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
71
73
|
var AgoraRteScene = (_dec = _log.Log.attach({
|
|
72
74
|
proxyMethods: false
|
|
73
|
-
}), _dec(_class = /*#__PURE__*/function (_EventEmitter) {
|
|
75
|
+
}), _dec(_class = (_class2 = /*#__PURE__*/function (_EventEmitter) {
|
|
74
76
|
(0, _inherits2["default"])(AgoraRteScene, _EventEmitter);
|
|
75
77
|
var _super = _createSuper(AgoraRteScene);
|
|
76
78
|
function AgoraRteScene(sceneId, options) {
|
|
@@ -87,9 +89,8 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
87
89
|
_this.dataStore = void 0;
|
|
88
90
|
_this._rtmManager = void 0;
|
|
89
91
|
_this._rtcManager = void 0;
|
|
90
|
-
_this._rtmChannel = void 0;
|
|
91
92
|
_this._rtcChannel = void 0;
|
|
92
|
-
_this.
|
|
93
|
+
_this._stateSynchronizer = void 0;
|
|
93
94
|
_this._synchronizer = void 0;
|
|
94
95
|
_this._timestampGap = 0;
|
|
95
96
|
_this.createTs = void 0;
|
|
@@ -97,10 +98,9 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
97
98
|
_this._engine = options.engine;
|
|
98
99
|
_this._rtmManager = options.rtm;
|
|
99
100
|
_this._rtcManager = options.rtc;
|
|
100
|
-
_this._rtmChannel = options.rtmChannel;
|
|
101
|
-
_this._rtmChannelObserver = options.rtmChannelObserver;
|
|
102
101
|
_this._rtcChannel = options.rtcChannel;
|
|
103
102
|
_this._apiService = new _api.AgoraRteService();
|
|
103
|
+
_this._stateSynchronizer = new _stateSync.AGOnlineStateSynchronizer(_this._apiService, sceneId);
|
|
104
104
|
_this._apiService.pathPrefix = options.engine.apiServicePathPrefix;
|
|
105
105
|
_this.dataStore = new _data.AgoraRteSyncDataStore();
|
|
106
106
|
|
|
@@ -116,7 +116,7 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
116
116
|
channel.onConnectionStageChanged(function (state, connectionType) {
|
|
117
117
|
_this.emit(_handler.AgoraRteEventType.RtcConnectionStateChanged, state, connectionType);
|
|
118
118
|
});
|
|
119
|
-
rtmManager.on(_handler.AgoraRteEventType.RtmConnectionStateChanged, _this._handleRtmStateChange
|
|
119
|
+
rtmManager.on(_handler.AgoraRteEventType.RtmConnectionStateChanged, _this._handleRtmStateChange);
|
|
120
120
|
return _this;
|
|
121
121
|
}
|
|
122
122
|
(0, _createClass2["default"])(AgoraRteScene, [{
|
|
@@ -173,7 +173,7 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
173
173
|
key: "joinScene",
|
|
174
174
|
value: function () {
|
|
175
175
|
var _joinScene = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
176
|
-
var mediaControl, _yield$this$getApiSer, user, room, streamUuid, userName, userUuid, role, rtcToken, _user$streams, streams, userProperties, agStreams, stream, snapshotData;
|
|
176
|
+
var mediaControl, sequenceVersion, _yield$this$getApiSer, user, room, sysConfig, _sysConfig$rtmChannel, roomChannelName, _this$_rtmManager$cre, _this$_rtmManager$cre2, rtmChannel, rtmChannelObserver, streamUuid, userName, userUuid, role, rtcToken, _user$streams, streams, userProperties, agStreams, stream, peerMessageHandler, snapshotData;
|
|
177
177
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
178
178
|
while (1) {
|
|
179
179
|
switch (_context.prev = _context.next) {
|
|
@@ -189,7 +189,8 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
189
189
|
// 1. entry
|
|
190
190
|
this._setRteConnectionState(_type.AgoraRteConnectionState.Connecting);
|
|
191
191
|
mediaControl = this._engine.getAgoraMediaControl();
|
|
192
|
-
|
|
192
|
+
sequenceVersion = _configs.AgoraRteEngineConfig.sequenceVersion;
|
|
193
|
+
_context.next = 9;
|
|
193
194
|
return this.getApiService().entryRoom({
|
|
194
195
|
userUuid: _configs.AgoraRteEngineConfig.shared.userId,
|
|
195
196
|
roomUuid: this.sceneId,
|
|
@@ -199,12 +200,20 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
199
200
|
stream: {
|
|
200
201
|
videoSourceState: mediaControl.createCameraVideoTrack().state,
|
|
201
202
|
audioSourceState: mediaControl.createMicrophoneAudioTrack().state
|
|
202
|
-
}
|
|
203
|
+
},
|
|
204
|
+
sequenceVersion: sequenceVersion
|
|
203
205
|
});
|
|
204
|
-
case
|
|
206
|
+
case 9:
|
|
205
207
|
_yield$this$getApiSer = _context.sent;
|
|
206
208
|
user = _yield$this$getApiSer.user;
|
|
207
209
|
room = _yield$this$getApiSer.room;
|
|
210
|
+
sysConfig = _yield$this$getApiSer.sysConfig;
|
|
211
|
+
_sysConfig$rtmChannel = (0, _slicedToArray2["default"])(sysConfig.rtmChannels, 1), roomChannelName = _sysConfig$rtmChannel[0];
|
|
212
|
+
_this$_rtmManager$cre = this._rtmManager.createObserverChannel(roomChannelName), _this$_rtmManager$cre2 = (0, _slicedToArray2["default"])(_this$_rtmManager$cre, 2), rtmChannel = _this$_rtmManager$cre2[0], rtmChannelObserver = _this$_rtmManager$cre2[1];
|
|
213
|
+
if (user.subscribe === 1) {
|
|
214
|
+
this._stateSynchronizer.setSyncDelay(sysConfig.onlineStateEnsureDelay || 5000);
|
|
215
|
+
}
|
|
216
|
+
this._stateSynchronizer.addConnectionStateListeners(this);
|
|
208
217
|
this.createTs = room.roomState.createTime;
|
|
209
218
|
|
|
210
219
|
// Object.assign(AgoraRteEngineConfig.shared.service.headers, { token: user.userToken });
|
|
@@ -214,9 +223,9 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
214
223
|
});
|
|
215
224
|
|
|
216
225
|
// 2. rtm join
|
|
217
|
-
_context.next =
|
|
218
|
-
return this._rtmManager.join(
|
|
219
|
-
case
|
|
226
|
+
_context.next = 21;
|
|
227
|
+
return this._rtmManager.join(rtmChannel, rtmChannelObserver, this.sceneId);
|
|
228
|
+
case 21:
|
|
220
229
|
// 3. initialize object models
|
|
221
230
|
streamUuid = user.streamUuid, userName = user.userName, userUuid = user.userUuid, role = user.role, rtcToken = user.rtcToken, _user$streams = user.streams, streams = _user$streams === void 0 ? [] : _user$streams, userProperties = user.userProperties;
|
|
222
231
|
agStreams = streams.map(function (s) {
|
|
@@ -262,31 +271,34 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
262
271
|
scene: this,
|
|
263
272
|
userUuid: _configs.AgoraRteEngineConfig.shared.userId,
|
|
264
273
|
streamUuid: streamUuid,
|
|
265
|
-
channelObserver:
|
|
266
|
-
|
|
274
|
+
channelObserver: rtmChannelObserver,
|
|
275
|
+
sequenceVersion: sequenceVersion
|
|
267
276
|
});
|
|
268
|
-
|
|
277
|
+
peerMessageHandler = new _handler2.AgoraRtePeerMessageHandle({
|
|
278
|
+
dataStore: this.dataStore
|
|
279
|
+
});
|
|
280
|
+
this._addEventListeners(this._synchronizer.handle, peerMessageHandler);
|
|
269
281
|
|
|
270
282
|
// 4. sync/get snapshot
|
|
271
|
-
_context.next =
|
|
283
|
+
_context.next = 31;
|
|
272
284
|
return this.getApiService().syncSnapShot(this.sceneId);
|
|
273
|
-
case
|
|
285
|
+
case 31:
|
|
274
286
|
snapshotData = _context.sent;
|
|
275
287
|
this._synchronizer.syncSnapshot(_struct.AgoraRteSyncSnapshotData.fromData(snapshotData));
|
|
276
|
-
_context.next =
|
|
288
|
+
_context.next = 39;
|
|
277
289
|
break;
|
|
278
|
-
case
|
|
279
|
-
_context.prev =
|
|
290
|
+
case 35:
|
|
291
|
+
_context.prev = 35;
|
|
280
292
|
_context.t0 = _context["catch"](3);
|
|
281
293
|
// cleanup
|
|
282
294
|
this._cleanup();
|
|
283
295
|
return _context.abrupt("return", _error.RteErrorCenter.shared.handleThrowableError(_error.AGRteErrorCode.RTE_ERR_JOIN_SCENE_FAILED, _context.t0));
|
|
284
|
-
case
|
|
296
|
+
case 39:
|
|
285
297
|
case "end":
|
|
286
298
|
return _context.stop();
|
|
287
299
|
}
|
|
288
300
|
}
|
|
289
|
-
}, _callee, this, [[3,
|
|
301
|
+
}, _callee, this, [[3, 35]]);
|
|
290
302
|
}));
|
|
291
303
|
function joinScene(_x) {
|
|
292
304
|
return _joinScene.apply(this, arguments);
|
|
@@ -302,16 +314,17 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
302
314
|
while (1) {
|
|
303
315
|
switch (_context2.prev = _context2.next) {
|
|
304
316
|
case 0:
|
|
305
|
-
|
|
317
|
+
this._stateSynchronizer.stop();
|
|
318
|
+
_context2.next = 3;
|
|
306
319
|
return (0, _awaitToJs["default"])(this._rtmManager.leave(this.sceneId));
|
|
307
|
-
case
|
|
320
|
+
case 3:
|
|
308
321
|
_yield$to = _context2.sent;
|
|
309
322
|
_yield$to2 = (0, _slicedToArray2["default"])(_yield$to, 1);
|
|
310
323
|
err = _yield$to2[0];
|
|
311
324
|
err && _error.RteErrorCenter.shared.handleNonThrowableError(_error.AGRteErrorCode.RTE_ERR_LEAVE_SCENE_FAIL, err);
|
|
312
325
|
this._rtmManager.off(_handler.AgoraRteEventType.RtmConnectionStateChanged, this._handleRtmStateChange);
|
|
313
326
|
this._cleanup();
|
|
314
|
-
case
|
|
327
|
+
case 9:
|
|
315
328
|
case "end":
|
|
316
329
|
return _context2.stop();
|
|
317
330
|
}
|
|
@@ -495,24 +508,18 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
495
508
|
}
|
|
496
509
|
}, {
|
|
497
510
|
key: "_handleUserRemoved",
|
|
498
|
-
value: function _handleUserRemoved(users, type) {
|
|
511
|
+
value: function _handleUserRemoved(users, removedStreams, type) {
|
|
499
512
|
var _this3 = this;
|
|
500
513
|
var removedLocalStreams = [];
|
|
501
514
|
var removedRemoteStreams = [];
|
|
502
|
-
|
|
515
|
+
|
|
516
|
+
// split streams into local and remote lists
|
|
517
|
+
removedStreams.forEach(function (stream) {
|
|
503
518
|
var _this3$localUser;
|
|
504
|
-
if (((_this3$localUser = _this3.localUser) === null || _this3$localUser === void 0 ? void 0 : _this3$localUser.userUuid) ===
|
|
505
|
-
|
|
506
|
-
var streams = _this3.dataStore.findUserStreams(u.userUuid);
|
|
507
|
-
if (streams.length) {
|
|
508
|
-
removedLocalStreams = removedLocalStreams.concat(streams);
|
|
509
|
-
}
|
|
519
|
+
if (((_this3$localUser = _this3.localUser) === null || _this3$localUser === void 0 ? void 0 : _this3$localUser.userUuid) === stream.fromUser.userUuid) {
|
|
520
|
+
removedLocalStreams.push(stream);
|
|
510
521
|
} else {
|
|
511
|
-
|
|
512
|
-
var _streams2 = _this3.dataStore.findUserStreams(u.userUuid);
|
|
513
|
-
if (_streams2.length) {
|
|
514
|
-
removedRemoteStreams = removedRemoteStreams.concat(_streams2);
|
|
515
|
-
}
|
|
522
|
+
removedRemoteStreams.push(stream);
|
|
516
523
|
}
|
|
517
524
|
});
|
|
518
525
|
this._handleLocalStreamRemoved(removedLocalStreams);
|
|
@@ -537,9 +544,9 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
537
544
|
}
|
|
538
545
|
}, {
|
|
539
546
|
key: "_addEventListeners",
|
|
540
|
-
value: function _addEventListeners(
|
|
547
|
+
value: function _addEventListeners(channelMessageHandler, peerMessageHandler) {
|
|
541
548
|
var _this4 = this;
|
|
542
|
-
|
|
549
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.SnapshotUpdated, function (snapshot) {
|
|
543
550
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " snapshot updated"));
|
|
544
551
|
_this4._setInitialSnapshotSync(true);
|
|
545
552
|
if (!_this4.localUser) {
|
|
@@ -561,84 +568,99 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
561
568
|
_this4.emit(_handler.AgoraRteEventType.UserCountUpdated, snapshot.roomState.total);
|
|
562
569
|
}
|
|
563
570
|
});
|
|
564
|
-
|
|
571
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.ChatReceived, function (message) {
|
|
565
572
|
_this4.emit(_handler.AgoraRteEventType.ChatReceived, message);
|
|
566
573
|
});
|
|
567
|
-
|
|
574
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.UserCountUpdated, function (count) {
|
|
568
575
|
_this4.emit(_handler.AgoraRteEventType.UserCountUpdated, count);
|
|
569
576
|
});
|
|
570
|
-
|
|
577
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.UserAdded, function (users) {
|
|
571
578
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " user-added [").concat(users.join(','), "]"));
|
|
572
579
|
_this4._handleUserAdded(users);
|
|
573
580
|
});
|
|
574
|
-
|
|
581
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.UserUpdated, function (user) {
|
|
575
582
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " user-updated ").concat(user));
|
|
576
583
|
});
|
|
577
|
-
|
|
584
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.UserRemoved, function (users, removedStreams, type) {
|
|
578
585
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " user-removed [").concat(users.join(','), "]"));
|
|
579
|
-
_this4._handleUserRemoved(users, type);
|
|
586
|
+
_this4._handleUserRemoved(users, removedStreams, type);
|
|
580
587
|
});
|
|
581
|
-
|
|
588
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.RoomPropertyUpdated, function (changedKeys, roomProperties, operator, cause) {
|
|
582
589
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " room-property-updated ").concat((0, _utils.jsonstring)(roomProperties), " ").concat((0, _utils.jsonstring)(operator), " ").concat((0, _utils.jsonstring)(cause)));
|
|
583
590
|
_this4._handleRoomPropertyChange(changedKeys, roomProperties, operator, cause);
|
|
584
591
|
});
|
|
585
|
-
|
|
592
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.UserPropertyUpdated, function (userUuid, userProperties, operator, cause) {
|
|
586
593
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " user-property-updated ").concat(userUuid, " ").concat((0, _utils.jsonstring)(userProperties), " ").concat((0, _utils.jsonstring)(operator), " ").concat((0, _utils.jsonstring)(cause)));
|
|
587
594
|
_this4.emit(_handler.AgoraRteEventType.UserPropertyUpdated, userUuid, userProperties, operator, cause);
|
|
588
595
|
});
|
|
589
|
-
|
|
596
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.UserPropertyListUpdated, function (users, batch, operator, cause) {
|
|
590
597
|
_this4.logger.info("user-property-list-updated ".concat((0, _utils.jsonstring)(users), " ").concat((0, _utils.jsonstring)(batch), " ").concat((0, _utils.jsonstring)(operator), " ").concat((0, _utils.jsonstring)(cause)));
|
|
591
598
|
_this4.emit(_handler.AgoraRteEventType.UserPropertyListUpdated, users, batch, operator, cause);
|
|
592
599
|
});
|
|
593
|
-
|
|
600
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.LocalStreamAdded, function (streams, operator) {
|
|
594
601
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " local-stream-added [").concat(streams.join(','), "]"));
|
|
595
602
|
if (streams.length === 0) {
|
|
596
603
|
return;
|
|
597
604
|
}
|
|
598
605
|
_this4.emit(_handler.AgoraRteEventType.LocalStreamAdded, streams, operator);
|
|
599
606
|
});
|
|
600
|
-
|
|
607
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.LocalStreamUpdate, function (streams, operator) {
|
|
601
608
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " local-stream-upsert [").concat(streams.join(','), "]"));
|
|
602
609
|
if (streams.length === 0) {
|
|
603
610
|
return;
|
|
604
611
|
}
|
|
605
612
|
_this4.emit(_handler.AgoraRteEventType.LocalStreamUpdate, streams, operator);
|
|
606
613
|
});
|
|
607
|
-
|
|
614
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.LocalStreamRemove, function (streams, operator) {
|
|
608
615
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " local-stream-removed [").concat(streams.join(','), "]"));
|
|
609
616
|
if (streams.length === 0) {
|
|
610
617
|
return;
|
|
611
618
|
}
|
|
612
619
|
_this4.emit(_handler.AgoraRteEventType.LocalStreamRemove, streams, operator);
|
|
613
620
|
});
|
|
614
|
-
|
|
621
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.RemoteStreamAdded, function (streams, operator) {
|
|
615
622
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " remote-stream-added [").concat(streams.join(','), "]"));
|
|
616
623
|
if (streams.length === 0) {
|
|
617
624
|
return;
|
|
618
625
|
}
|
|
619
626
|
_this4.emit(_handler.AgoraRteEventType.RemoteStreamAdded, streams, operator);
|
|
620
627
|
});
|
|
621
|
-
|
|
628
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.RemoteStreamUpdate, function (streams, operator) {
|
|
622
629
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " remote-stream-upsert [").concat(streams.join(','), "]"));
|
|
623
630
|
if (streams.length === 0) {
|
|
624
631
|
return;
|
|
625
632
|
}
|
|
626
633
|
_this4.emit(_handler.AgoraRteEventType.RemoteStreamUpdate, streams, operator);
|
|
627
634
|
});
|
|
628
|
-
|
|
635
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.RemoteStreamRemove, function (streams, operator) {
|
|
629
636
|
_this4.logger.info("sceneId:".concat(_this4.sceneId, " remote-stream-removed [").concat(streams.join(','), "]"));
|
|
630
637
|
if (streams.length === 0) {
|
|
631
638
|
return;
|
|
632
639
|
}
|
|
633
640
|
_this4.emit(_handler.AgoraRteEventType.RemoteStreamRemove, streams, operator);
|
|
634
641
|
});
|
|
635
|
-
|
|
636
|
-
_this4.emit(_handler.AgoraRteEventType.ChatUserMessage, message);
|
|
637
|
-
});
|
|
638
|
-
handler.on(_handler.AgoraRteEventType.TimeStampGapUpdate, function (timestamp) {
|
|
642
|
+
channelMessageHandler.on(_handler.AgoraRteEventType.TimeStampGapUpdate, function (timestamp) {
|
|
639
643
|
_this4._timestampGap = timestamp;
|
|
640
644
|
_this4.emit(_handler.AgoraRteEventType.TimeStampGapUpdate, timestamp);
|
|
641
645
|
});
|
|
646
|
+
peerMessageHandler.on(_handler.AgoraRteEventType.ChatUserMessage, function (message) {
|
|
647
|
+
_this4.emit(_handler.AgoraRteEventType.ChatUserMessage, message);
|
|
648
|
+
});
|
|
649
|
+
this._rtmManager.on('MessageFromPeer', function (_ref) {
|
|
650
|
+
var message = _ref.message,
|
|
651
|
+
peerId = _ref.peerId;
|
|
652
|
+
// only process channel message from server
|
|
653
|
+
_this4.logger.info("peer message from [".concat(_this4.sceneId, "]: ").concat(message, ", peerId: ").concat(peerId));
|
|
654
|
+
if (peerId === 'server') {
|
|
655
|
+
try {
|
|
656
|
+
var task = JSON.parse(message);
|
|
657
|
+
peerMessageHandler.handlePeerMessage(task);
|
|
658
|
+
} catch (e) {
|
|
659
|
+
_this4.logger.error("".concat(e.message, " original: ").concat(message));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
this._stateSynchronizer.addMessageEventListeners(channelMessageHandler);
|
|
642
664
|
}
|
|
643
665
|
}, {
|
|
644
666
|
key: "_handleRoomPropertyChange",
|
|
@@ -652,5 +674,5 @@ var AgoraRteScene = (_dec = _log.Log.attach({
|
|
|
652
674
|
}
|
|
653
675
|
}]);
|
|
654
676
|
return AgoraRteScene;
|
|
655
|
-
}(_events.EventEmitter)) || _class);
|
|
677
|
+
}(_events.EventEmitter), ((0, _applyDecoratedDescriptor2["default"])(_class2.prototype, "_handleRtmStateChange", [_decorator.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "_handleRtmStateChange"), _class2.prototype)), _class2)) || _class);
|
|
656
678
|
exports.AgoraRteScene = AgoraRteScene;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AgoraRteScene } from '.';
|
|
2
|
+
import { Logger } from '../core/logger';
|
|
3
|
+
import { AgoraRteChannelMessageHandle } from '../core/processor/channel-msg/handler';
|
|
4
|
+
import { AgoraRteService } from '../core/services/api';
|
|
5
|
+
export declare class AGOnlineStateSynchronizer {
|
|
6
|
+
logger: Logger;
|
|
7
|
+
private _task?;
|
|
8
|
+
private _api;
|
|
9
|
+
private _sceneId;
|
|
10
|
+
private _delay;
|
|
11
|
+
private _connState;
|
|
12
|
+
private _isOnline;
|
|
13
|
+
constructor(api: AgoraRteService, sceneId: string);
|
|
14
|
+
setSyncDelay(delay: number): void;
|
|
15
|
+
addMessageEventListeners(handle: AgoraRteChannelMessageHandle): void;
|
|
16
|
+
addConnectionStateListeners(scene: AgoraRteScene): void;
|
|
17
|
+
start(): void;
|
|
18
|
+
stop(): void;
|
|
19
|
+
get isStateNotInSync(): boolean;
|
|
20
|
+
private _notifyServerStateOnline;
|
|
21
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
require("core-js/modules/es.symbol.js");
|
|
5
|
+
require("core-js/modules/es.symbol.description.js");
|
|
6
|
+
require("core-js/modules/es.object.to-string.js");
|
|
7
|
+
require("core-js/modules/es.symbol.iterator.js");
|
|
8
|
+
require("core-js/modules/es.array.iterator.js");
|
|
9
|
+
require("core-js/modules/es.string.iterator.js");
|
|
10
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
11
|
+
require("core-js/modules/es.symbol.async-iterator.js");
|
|
12
|
+
require("core-js/modules/es.symbol.to-string-tag.js");
|
|
13
|
+
require("core-js/modules/es.json.to-string-tag.js");
|
|
14
|
+
require("core-js/modules/es.math.to-string-tag.js");
|
|
15
|
+
require("core-js/modules/es.object.create.js");
|
|
16
|
+
require("core-js/modules/es.object.get-prototype-of.js");
|
|
17
|
+
require("core-js/modules/es.array.for-each.js");
|
|
18
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
19
|
+
require("core-js/modules/es.function.name.js");
|
|
20
|
+
require("core-js/modules/es.object.set-prototype-of.js");
|
|
21
|
+
require("core-js/modules/es.promise.js");
|
|
22
|
+
require("core-js/modules/es.array.reverse.js");
|
|
23
|
+
require("core-js/modules/es.array.slice.js");
|
|
24
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
25
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
26
|
+
Object.defineProperty(exports, "__esModule", {
|
|
27
|
+
value: true
|
|
28
|
+
});
|
|
29
|
+
exports.AGOnlineStateSynchronizer = void 0;
|
|
30
|
+
require("core-js/modules/es.array.some.js");
|
|
31
|
+
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
32
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
33
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
34
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
35
|
+
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
|
36
|
+
var _configs = require("../configs");
|
|
37
|
+
var _decorator = require("../core/decorator");
|
|
38
|
+
var _handler = require("../core/processor/channel-msg/handler");
|
|
39
|
+
var _schedule = require("../core/schedule");
|
|
40
|
+
var _type = require("../type");
|
|
41
|
+
var _dec, _class, _class2;
|
|
42
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
43
|
+
var AGOnlineStateSynchronizer = (_dec = _decorator.Log.attach({
|
|
44
|
+
proxyMethods: false
|
|
45
|
+
}), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
46
|
+
function AGOnlineStateSynchronizer(api, sceneId) {
|
|
47
|
+
(0, _classCallCheck2["default"])(this, AGOnlineStateSynchronizer);
|
|
48
|
+
this.logger = void 0;
|
|
49
|
+
this._task = void 0;
|
|
50
|
+
this._api = void 0;
|
|
51
|
+
this._sceneId = void 0;
|
|
52
|
+
this._delay = 0;
|
|
53
|
+
this._connState = _type.AgoraRteConnectionState.Idle;
|
|
54
|
+
this._isOnline = false;
|
|
55
|
+
this._api = api;
|
|
56
|
+
this._sceneId = sceneId;
|
|
57
|
+
}
|
|
58
|
+
(0, _createClass2["default"])(AGOnlineStateSynchronizer, [{
|
|
59
|
+
key: "setSyncDelay",
|
|
60
|
+
value: function setSyncDelay(delay) {
|
|
61
|
+
this._delay = delay;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "addMessageEventListeners",
|
|
65
|
+
value: function addMessageEventListeners(handle) {
|
|
66
|
+
var _this = this;
|
|
67
|
+
var userId = _configs.AgoraRteEngineConfig.shared.userId;
|
|
68
|
+
handle.on(_handler.AgoraRteEventType.SnapshotUpdated, function (snapshot) {
|
|
69
|
+
if (snapshot.users.has(userId)) {
|
|
70
|
+
_this._isOnline = true;
|
|
71
|
+
} else {
|
|
72
|
+
_this._isOnline = false;
|
|
73
|
+
}
|
|
74
|
+
if (!_this._isOnline) {
|
|
75
|
+
_this.start();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
handle.on(_handler.AgoraRteEventType.UserAdded, function (users) {
|
|
79
|
+
var isLocalAdded = users.some(function (user) {
|
|
80
|
+
return user.userUuid === userId;
|
|
81
|
+
});
|
|
82
|
+
_this._isOnline = isLocalAdded;
|
|
83
|
+
if (!_this._isOnline) {
|
|
84
|
+
_this.start();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
handle.on(_handler.AgoraRteEventType.UserRemoved, function (users) {
|
|
88
|
+
var isLocalRemoved = users.some(function (user) {
|
|
89
|
+
return user.userUuid === userId;
|
|
90
|
+
});
|
|
91
|
+
_this._isOnline = !isLocalRemoved;
|
|
92
|
+
if (!_this._isOnline) {
|
|
93
|
+
_this.start();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
key: "addConnectionStateListeners",
|
|
99
|
+
value: function addConnectionStateListeners(scene) {
|
|
100
|
+
var _this2 = this;
|
|
101
|
+
scene.on(_handler.AgoraRteEventType.RteConnectionStateChanged, function (state) {
|
|
102
|
+
_this2._connState = state;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "start",
|
|
107
|
+
value: function start() {
|
|
108
|
+
if (!this._task) {
|
|
109
|
+
this.logger.info("state syncing will occur in ".concat(this._delay, "ms"));
|
|
110
|
+
this._task = _schedule.Scheduler.shared.addDelayTask(this._notifyServerStateOnline, this._delay);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "stop",
|
|
115
|
+
value: function stop() {
|
|
116
|
+
var _this$_task;
|
|
117
|
+
(_this$_task = this._task) === null || _this$_task === void 0 ? void 0 : _this$_task.stop();
|
|
118
|
+
this._task = undefined;
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "isStateNotInSync",
|
|
122
|
+
get: function get() {
|
|
123
|
+
return !this._isOnline && this._connState === _type.AgoraRteConnectionState.Connected;
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "_notifyServerStateOnline",
|
|
127
|
+
value: function () {
|
|
128
|
+
var _notifyServerStateOnline2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
129
|
+
var userId;
|
|
130
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
131
|
+
while (1) {
|
|
132
|
+
switch (_context.prev = _context.next) {
|
|
133
|
+
case 0:
|
|
134
|
+
if (!this.isStateNotInSync) {
|
|
135
|
+
_context.next = 10;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
userId = _configs.AgoraRteEngineConfig.shared.userId;
|
|
139
|
+
_context.prev = 2;
|
|
140
|
+
_context.next = 5;
|
|
141
|
+
return this._api.updateOnlineState({
|
|
142
|
+
userUuid: userId,
|
|
143
|
+
roomUuid: this._sceneId
|
|
144
|
+
});
|
|
145
|
+
case 5:
|
|
146
|
+
_context.next = 10;
|
|
147
|
+
break;
|
|
148
|
+
case 7:
|
|
149
|
+
_context.prev = 7;
|
|
150
|
+
_context.t0 = _context["catch"](2);
|
|
151
|
+
this.logger.error('failed to sync online state with server', _context.t0);
|
|
152
|
+
case 10:
|
|
153
|
+
this._task = undefined;
|
|
154
|
+
case 11:
|
|
155
|
+
case "end":
|
|
156
|
+
return _context.stop();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}, _callee, this, [[2, 7]]);
|
|
160
|
+
}));
|
|
161
|
+
function _notifyServerStateOnline() {
|
|
162
|
+
return _notifyServerStateOnline2.apply(this, arguments);
|
|
163
|
+
}
|
|
164
|
+
return _notifyServerStateOnline;
|
|
165
|
+
}()
|
|
166
|
+
}]);
|
|
167
|
+
return AGOnlineStateSynchronizer;
|
|
168
|
+
}(), ((0, _applyDecoratedDescriptor2["default"])(_class2.prototype, "_notifyServerStateOnline", [_decorator.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "_notifyServerStateOnline"), _class2.prototype)), _class2)) || _class);
|
|
169
|
+
exports.AGOnlineStateSynchronizer = AGOnlineStateSynchronizer;
|