agora-rte-sdk 3.8.2 → 3.9.0-alpha

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.
Files changed (266) hide show
  1. package/lib/constant.d.ts +9 -0
  2. package/lib/constant.js +13 -2
  3. package/lib/core/engine/ap-detector.d.ts +4 -4
  4. package/lib/core/engine/ap-detector.js +33 -20
  5. package/lib/core/engine/index.d.ts +19 -11
  6. package/lib/core/engine/index.js +132 -48
  7. package/lib/core/engine/plugin.js +2 -2
  8. package/lib/core/engine/type.d.ts +29 -0
  9. package/lib/core/engine/type.js +6 -0
  10. package/lib/core/media/camera.d.ts +8 -8
  11. package/lib/core/media/camera.js +38 -21
  12. package/lib/core/media/effect-enhancer.d.ts +5 -6
  13. package/lib/core/media/effect-enhancer.js +6 -16
  14. package/lib/core/media/index.d.ts +1 -155
  15. package/lib/core/media/index.js +44 -15
  16. package/lib/core/media/loopback.d.ts +3 -3
  17. package/lib/core/media/loopback.js +18 -11
  18. package/lib/core/media/microphone.d.ts +6 -6
  19. package/lib/core/media/microphone.js +32 -16
  20. package/lib/core/media/screen.d.ts +13 -5
  21. package/lib/core/media/screen.js +46 -16
  22. package/lib/core/media/type.d.ts +159 -2
  23. package/lib/core/media/type.js +4 -1
  24. package/lib/core/processor/message-handler.d.ts +4 -4
  25. package/lib/core/processor/message-handler.js +66 -28
  26. package/lib/core/processor/sequence-msg/data.d.ts +9 -7
  27. package/lib/core/processor/sequence-msg/data.js +26 -3
  28. package/lib/core/processor/struct.js +2 -2
  29. package/lib/core/processor/synchronizer/synchronizer-manager.d.ts +10 -0
  30. package/lib/core/processor/synchronizer/synchronizer-manager.js +43 -4
  31. package/lib/core/rtc/capture-enhancement.d.ts +4 -14
  32. package/lib/core/rtc/channel.d.ts +4 -4
  33. package/lib/core/rtc/constant.d.ts +1 -5
  34. package/lib/core/rtc/constant.js +2 -8
  35. package/lib/core/rtc/publish-pool.d.ts +20 -8
  36. package/lib/core/rtc/publish-pool.js +272 -3
  37. package/lib/core/rtc/publisher.d.ts +20 -14
  38. package/lib/core/rtc/publisher.js +151 -7
  39. package/lib/core/rtc/source-manager.d.ts +12 -2
  40. package/lib/core/rtc/subscriber.d.ts +14 -6
  41. package/lib/core/rtc/subscriber.js +171 -4
  42. package/lib/core/rtc/type.d.ts +6 -17
  43. package/lib/core/rtc/type.js +10 -26
  44. package/lib/core/rtm/channel.d.ts +3 -3
  45. package/lib/core/rtm/client.d.ts +4 -4
  46. package/lib/core/rtm/type.d.ts +1 -2
  47. package/lib/core/scene/helpers/ap-detect.d.ts +5 -0
  48. package/lib/core/scene/helpers/ap-detect.js +153 -0
  49. package/lib/core/scene/helpers/join.d.ts +8 -0
  50. package/lib/core/scene/helpers/join.js +105 -0
  51. package/lib/core/scene/helpers/rtc-event.d.ts +4 -0
  52. package/lib/core/scene/helpers/rtc-event.js +36 -0
  53. package/lib/core/scene/helpers/stream-publish-handlers.d.ts +15 -0
  54. package/lib/core/scene/helpers/stream-publish-handlers.js +121 -0
  55. package/lib/core/scene/helpers/stream-type.d.ts +7 -0
  56. package/lib/core/scene/{helper.js → helpers/stream-type.js} +3 -32
  57. package/lib/core/scene/index.d.ts +69 -187
  58. package/lib/core/scene/index.js +813 -1368
  59. package/lib/core/scene/local-user.d.ts +19 -85
  60. package/lib/core/scene/local-user.js +151 -152
  61. package/lib/core/scene/state-sync.d.ts +5 -7
  62. package/lib/core/scene/state-sync.js +20 -43
  63. package/lib/core/scene/stream-player.d.ts +9 -8
  64. package/lib/core/scene/stream-player.js +13 -10
  65. package/lib/core/scene/type.d.ts +359 -9
  66. package/lib/core/services/api.d.ts +9 -0
  67. package/lib/core/services/api.js +96 -58
  68. package/lib/core/services/auth-headers.d.ts +1 -0
  69. package/lib/core/services/auth-headers.js +5 -2
  70. package/lib/core/services/client.d.ts +3 -0
  71. package/lib/core/services/client.js +14 -2
  72. package/lib/core/services/type.d.ts +1 -0
  73. package/lib/core/type.d.ts +1 -0
  74. package/lib/core/type.js +6 -0
  75. package/lib/core/utilities/abort-manager.d.ts +18 -0
  76. package/lib/core/utilities/abort-manager.js +154 -0
  77. package/lib/core/utilities/error.d.ts +5 -36
  78. package/lib/core/utilities/error.js +23 -92
  79. package/lib/core/utilities/join-manager.d.ts +54 -0
  80. package/lib/core/utilities/join-manager.js +198 -0
  81. package/lib/core/utilities/logger.d.ts +2 -0
  82. package/lib/core/utilities/logger.js +8 -13
  83. package/lib/core/utilities/package-info.d.ts +1 -0
  84. package/lib/core/utilities/package-info.js +6 -4
  85. package/lib/core/utilities/property-extract.d.ts +2 -0
  86. package/lib/core/utilities/property-extract.js +79 -0
  87. package/lib/core/utilities/weak-invoker.d.ts +11 -0
  88. package/lib/core/utilities/weak-invoker.js +121 -0
  89. package/lib/imports.d.ts +6 -4
  90. package/lib/imports.js +42 -17
  91. package/lib/index.d.ts +7 -5
  92. package/lib/index.js +6 -5
  93. package/lib/plugin/restful-client/index.d.ts +1 -1
  94. package/lib/plugin/restful-client/index.js +11 -10
  95. package/lib/plugin/rtc/electron/camera-preview-task-manager.d.ts +14 -0
  96. package/lib/plugin/rtc/electron/camera-preview-task-manager.js +125 -0
  97. package/lib/plugin/rtc/electron/canvas-helper.d.ts +2 -2
  98. package/lib/plugin/rtc/electron/canvas-helper.js +15 -12
  99. package/lib/plugin/rtc/electron/canvas-tag-pool.d.ts +4 -4
  100. package/lib/plugin/rtc/electron/canvas-tag-pool.js +21 -13
  101. package/lib/plugin/rtc/electron/capture-enhancement.d.ts +3 -5
  102. package/lib/plugin/rtc/electron/capture-enhancement.js +45 -29
  103. package/lib/plugin/rtc/electron/channel.d.ts +13 -16
  104. package/lib/plugin/rtc/electron/channel.js +48 -57
  105. package/lib/plugin/rtc/electron/client.d.ts +8 -4
  106. package/lib/plugin/rtc/electron/client.js +107 -72
  107. package/lib/plugin/rtc/electron/constants.d.ts +12 -1
  108. package/lib/plugin/rtc/electron/constants.js +94 -26
  109. package/lib/plugin/rtc/electron/desc-type.js +1 -1
  110. package/lib/plugin/rtc/electron/downloadALD.js +9 -7
  111. package/lib/plugin/rtc/electron/publish-pool.d.ts +9 -17
  112. package/lib/plugin/rtc/electron/publish-pool.js +110 -256
  113. package/lib/plugin/rtc/electron/publisher.d.ts +9 -21
  114. package/lib/plugin/rtc/electron/publisher.js +80 -254
  115. package/lib/plugin/rtc/electron/source-manager.d.ts +22 -16
  116. package/lib/plugin/rtc/electron/source-manager.js +345 -215
  117. package/lib/plugin/rtc/electron/source-state-control/loopback-state-control.d.ts +1 -5
  118. package/lib/plugin/rtc/electron/source-state-control/loopback-state-control.js +2 -18
  119. package/lib/plugin/rtc/electron/source-state-control/media-state-control.d.ts +18 -0
  120. package/lib/plugin/rtc/electron/source-state-control/{camera-state-control.js → media-state-control.js} +50 -104
  121. package/lib/plugin/rtc/electron/source-state-control/microphone-state-control.d.ts +4 -10
  122. package/lib/plugin/rtc/electron/source-state-control/microphone-state-control.js +5 -26
  123. package/lib/plugin/rtc/electron/source-state-control/source-state-control.d.ts +30 -26
  124. package/lib/plugin/rtc/electron/source-state-control/source-state-control.js +68 -110
  125. package/lib/plugin/rtc/electron/subscriber.d.ts +7 -16
  126. package/lib/plugin/rtc/electron/subscriber.js +34 -112
  127. package/lib/plugin/rtc/electron/type.d.ts +7 -3
  128. package/lib/plugin/rtc/electron/type.js +8 -2
  129. package/lib/plugin/rtc/electron/utils.d.ts +9 -6
  130. package/lib/plugin/rtc/electron/utils.js +37 -9
  131. package/lib/plugin/rtc/web/assembler.d.ts +2 -1
  132. package/lib/plugin/rtc/web/assembler.js +9 -2
  133. package/lib/plugin/rtc/web/audio-player.d.ts +1 -1
  134. package/lib/plugin/rtc/web/audio-player.js +13 -8
  135. package/lib/plugin/rtc/web/canvas-helper.d.ts +1 -1
  136. package/lib/plugin/rtc/web/canvas-helper.js +3 -1
  137. package/lib/plugin/rtc/web/capture-enhancement.d.ts +3 -5
  138. package/lib/plugin/rtc/web/capture-enhancement.js +14 -20
  139. package/lib/plugin/rtc/web/channel.d.ts +17 -13
  140. package/lib/plugin/rtc/web/channel.js +221 -124
  141. package/lib/plugin/rtc/web/client.d.ts +5 -3
  142. package/lib/plugin/rtc/web/client.js +49 -21
  143. package/lib/plugin/rtc/web/convert-type.d.ts +3 -0
  144. package/lib/plugin/rtc/web/convert-type.js +22 -0
  145. package/lib/plugin/rtc/web/device.js +2 -3
  146. package/lib/plugin/rtc/web/effect-enabler.js +3 -3
  147. package/lib/plugin/rtc/web/extension.d.ts +1 -1
  148. package/lib/plugin/rtc/web/extension.js +4 -1
  149. package/lib/plugin/rtc/web/publish-pool.d.ts +4 -17
  150. package/lib/plugin/rtc/web/publish-pool.js +41 -194
  151. package/lib/plugin/rtc/web/publish.d.ts +9 -8
  152. package/lib/plugin/rtc/web/publish.js +71 -27
  153. package/lib/plugin/rtc/web/publisher.d.ts +20 -12
  154. package/lib/plugin/rtc/web/publisher.js +118 -69
  155. package/lib/plugin/rtc/web/source-manager.d.ts +1 -0
  156. package/lib/plugin/rtc/web/source-manager.js +15 -9
  157. package/lib/plugin/rtc/web/subscribe.d.ts +10 -10
  158. package/lib/plugin/rtc/web/subscribe.js +26 -14
  159. package/lib/plugin/rtc/web/subscriber.d.ts +5 -10
  160. package/lib/plugin/rtc/web/subscriber.js +21 -82
  161. package/lib/plugin/rtc/web/track-control/camera.d.ts +1 -1
  162. package/lib/plugin/rtc/web/track-control/camera.js +4 -1
  163. package/lib/plugin/rtc/web/track-control/screen.d.ts +1 -1
  164. package/lib/plugin/rtc/web/track-control/screen.js +4 -1
  165. package/lib/plugin/rtm/channel.d.ts +8 -5
  166. package/lib/plugin/rtm/channel.js +113 -49
  167. package/lib/plugin/rtm/client.d.ts +10 -5
  168. package/lib/plugin/rtm/client.js +120 -61
  169. package/lib/plugin/rtm/utils.js +1 -1
  170. package/lib/plugin/synchronizer-worker/worker.js +71 -7
  171. package/lib/type.d.ts +0 -5
  172. package/lib-es/constant.js +12 -1
  173. package/lib-es/core/engine/ap-detector.js +36 -22
  174. package/lib-es/core/engine/index.js +134 -50
  175. package/lib-es/core/engine/plugin.js +1 -1
  176. package/lib-es/core/engine/type.js +1 -0
  177. package/lib-es/core/media/camera.js +38 -22
  178. package/lib-es/core/media/effect-enhancer.js +6 -16
  179. package/lib-es/core/media/index.js +44 -17
  180. package/lib-es/core/media/loopback.js +18 -12
  181. package/lib-es/core/media/microphone.js +32 -17
  182. package/lib-es/core/media/screen.js +46 -17
  183. package/lib-es/core/media/type.js +5 -1
  184. package/lib-es/core/processor/message-handler.js +44 -6
  185. package/lib-es/core/processor/sequence-msg/data.js +27 -4
  186. package/lib-es/core/processor/struct.js +1 -1
  187. package/lib-es/core/processor/synchronizer/synchronizer-manager.js +43 -4
  188. package/lib-es/core/rtc/constant.js +1 -7
  189. package/lib-es/core/rtc/publish-pool.js +274 -4
  190. package/lib-es/core/rtc/publisher.js +153 -9
  191. package/lib-es/core/rtc/subscriber.js +172 -4
  192. package/lib-es/core/rtc/type.js +9 -25
  193. package/lib-es/core/scene/helpers/ap-detect.js +143 -0
  194. package/lib-es/core/scene/helpers/join.js +97 -0
  195. package/lib-es/core/scene/helpers/rtc-event.js +29 -0
  196. package/lib-es/core/scene/helpers/stream-publish-handlers.js +112 -0
  197. package/lib-es/core/scene/helpers/stream-type.js +43 -0
  198. package/lib-es/core/scene/index.js +817 -1373
  199. package/lib-es/core/scene/local-user.js +144 -146
  200. package/lib-es/core/scene/state-sync.js +19 -42
  201. package/lib-es/core/scene/stream-player.js +13 -10
  202. package/lib-es/core/services/api.js +97 -59
  203. package/lib-es/core/services/auth-headers.js +4 -1
  204. package/lib-es/core/services/client.js +13 -1
  205. package/lib-es/core/type.js +1 -0
  206. package/lib-es/core/utilities/abort-manager.js +146 -0
  207. package/lib-es/core/utilities/error.js +22 -91
  208. package/lib-es/core/utilities/join-manager.js +190 -0
  209. package/lib-es/core/utilities/logger.js +8 -13
  210. package/lib-es/core/utilities/package-info.js +5 -3
  211. package/lib-es/core/utilities/property-extract.js +71 -0
  212. package/lib-es/core/utilities/weak-invoker.js +113 -0
  213. package/lib-es/imports.js +9 -5
  214. package/lib-es/index.js +3 -2
  215. package/lib-es/plugin/restful-client/index.js +5 -4
  216. package/lib-es/plugin/rtc/electron/camera-preview-task-manager.js +117 -0
  217. package/lib-es/plugin/rtc/electron/canvas-helper.js +15 -12
  218. package/lib-es/plugin/rtc/electron/canvas-tag-pool.js +21 -13
  219. package/lib-es/plugin/rtc/electron/capture-enhancement.js +46 -30
  220. package/lib-es/plugin/rtc/electron/channel.js +49 -58
  221. package/lib-es/plugin/rtc/electron/client.js +107 -72
  222. package/lib-es/plugin/rtc/electron/constants.js +93 -25
  223. package/lib-es/plugin/rtc/electron/desc-type.js +1 -1
  224. package/lib-es/plugin/rtc/electron/downloadALD.js +10 -8
  225. package/lib-es/plugin/rtc/electron/publish-pool.js +111 -257
  226. package/lib-es/plugin/rtc/electron/publisher.js +51 -226
  227. package/lib-es/plugin/rtc/electron/source-manager.js +348 -218
  228. package/lib-es/plugin/rtc/electron/source-state-control/loopback-state-control.js +2 -18
  229. package/lib-es/plugin/rtc/electron/source-state-control/{camera-state-control.js → media-state-control.js} +64 -118
  230. package/lib-es/plugin/rtc/electron/source-state-control/microphone-state-control.js +5 -26
  231. package/lib-es/plugin/rtc/electron/source-state-control/source-state-control.js +69 -109
  232. package/lib-es/plugin/rtc/electron/subscriber.js +38 -116
  233. package/lib-es/plugin/rtc/electron/type.js +7 -1
  234. package/lib-es/plugin/rtc/electron/utils.js +37 -9
  235. package/lib-es/plugin/rtc/web/assembler.js +9 -2
  236. package/lib-es/plugin/rtc/web/audio-player.js +14 -9
  237. package/lib-es/plugin/rtc/web/canvas-helper.js +3 -1
  238. package/lib-es/plugin/rtc/web/capture-enhancement.js +14 -20
  239. package/lib-es/plugin/rtc/web/channel.js +234 -137
  240. package/lib-es/plugin/rtc/web/client.js +50 -22
  241. package/lib-es/plugin/rtc/web/convert-type.js +15 -0
  242. package/lib-es/plugin/rtc/web/device.js +3 -4
  243. package/lib-es/plugin/rtc/web/effect-enabler.js +3 -3
  244. package/lib-es/plugin/rtc/web/extension.js +4 -1
  245. package/lib-es/plugin/rtc/web/publish-pool.js +45 -198
  246. package/lib-es/plugin/rtc/web/publish.js +71 -27
  247. package/lib-es/plugin/rtc/web/publisher.js +122 -72
  248. package/lib-es/plugin/rtc/web/source-manager.js +16 -10
  249. package/lib-es/plugin/rtc/web/subscribe.js +26 -14
  250. package/lib-es/plugin/rtc/web/subscriber.js +25 -86
  251. package/lib-es/plugin/rtc/web/track-control/camera.js +4 -1
  252. package/lib-es/plugin/rtc/web/track-control/screen.js +4 -1
  253. package/lib-es/plugin/rtm/channel.js +112 -48
  254. package/lib-es/plugin/rtm/client.js +116 -57
  255. package/lib-es/plugin/rtm/utils.js +1 -1
  256. package/lib-es/plugin/synchronizer-worker/worker.js +71 -7
  257. package/package.json +4 -4
  258. package/lib/core/scene/helper.d.ts +0 -10
  259. package/lib/plugin/rtc/electron/source-state-control/camera-state-control.d.ts +0 -28
  260. package/lib/plugin/rtc/electron/source-state-control/screen-state-control.d.ts +0 -31
  261. package/lib/plugin/rtc/electron/source-state-control/screen-state-control.js +0 -213
  262. package/lib/plugin/rtc/electron/source-state-control/window-state-control.d.ts +0 -31
  263. package/lib/plugin/rtc/electron/source-state-control/window-state-control.js +0 -213
  264. package/lib-es/core/scene/helper.js +0 -72
  265. package/lib-es/plugin/rtc/electron/source-state-control/screen-state-control.js +0 -206
  266. package/lib-es/plugin/rtc/electron/source-state-control/window-state-control.js +0 -206
@@ -39,7 +39,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
39
39
  import _createClass from "@babel/runtime/helpers/createClass";
40
40
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
41
41
  var _AgoraRteStreamPlayer;
42
- var _initProto;
42
+ var _initProto, _subscribeRemoteVideoStreamDecs, _unsubscribeRemoteVideoStreamDecs, _startRenderRemoteVideoStreamDecs, _stopRenderRemoteVideoStreamDecs, _startPlayRemoteAudioStreamDecs, _stopPlayRemoteAudioStreamDecs, _setAudioRawDataConfigDecs, _adjustRemoteAudioStreamVolumeDecs, _takeSnapshotDecs, _ref;
43
43
  import _regeneratorRuntime from "@babel/runtime/regenerator";
44
44
  import "core-js/modules/es.object.to-string.js";
45
45
  import "core-js/modules/es.promise.js";
@@ -48,12 +48,14 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
48
48
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
49
49
  function _setFunctionName(e, t, n) { "symbol" == _typeof(t) && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
50
50
  function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? _typeof(e) : "null")); return e; }
51
+ import { AgoraRteReturnCode } from '../../constant';
51
52
  import { AgoraObservable, trace } from '../../imports';
52
53
  import { createLogger } from '../utilities/logger';
54
+ _ref = (_subscribeRemoteVideoStreamDecs = trace(['streamId', 'type']), _unsubscribeRemoteVideoStreamDecs = trace(['streamId']), _startRenderRemoteVideoStreamDecs = trace(['streamId', 'renderMode', 'isMirror', 'view']), _stopRenderRemoteVideoStreamDecs = trace(['streamId', 'view']), _startPlayRemoteAudioStreamDecs = trace(['streamId']), _stopPlayRemoteAudioStreamDecs = trace(['streamId']), _setAudioRawDataConfigDecs = trace(['config']), _adjustRemoteAudioStreamVolumeDecs = trace(['streamId', 'volume']), _takeSnapshotDecs = trace(['streamId', 'filePath']), "logger");
53
55
  export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
54
56
  function AgoraRteStreamPlayer(rtcChannel) {
55
57
  _classCallCheck(this, AgoraRteStreamPlayer);
56
- _defineProperty(this, "logger", (_initProto(this), createLogger({
58
+ _defineProperty(this, _ref, (_initProto(this), createLogger({
57
59
  prefix: 'AgoraRteStreamPlayer'
58
60
  })));
59
61
  _defineProperty(this, "observable", new AgoraObservable());
@@ -78,7 +80,7 @@ export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
78
80
  }, {
79
81
  key: "subscribeRemoteVideoStream",
80
82
  value: function subscribeRemoteVideoStream(streamId, type) {
81
- this._rtcChannel.subscriber.subscribeRemoteVideoStream(streamId, type);
83
+ return this._rtcChannel.subscriber.subscribeRemoteVideoStream(streamId, type);
82
84
  }
83
85
  /**
84
86
  * Unsubscribe from a remote audio stream, you will stop receiving the video data of this stream.
@@ -87,7 +89,7 @@ export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
87
89
  }, {
88
90
  key: "unsubscribeRemoteVideoStream",
89
91
  value: function unsubscribeRemoteVideoStream(streamId) {
90
- this._rtcChannel.subscriber.unsubscribeRemoteVideoStream(streamId);
92
+ return this._rtcChannel.subscriber.unsubscribeRemoteVideoStream(streamId);
91
93
  }
92
94
  /**
93
95
  * Render the video of the remote user on the canvas.
@@ -101,7 +103,7 @@ export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
101
103
  }, {
102
104
  key: "startRenderRemoteVideoStream",
103
105
  value: function startRenderRemoteVideoStream(streamId, renderMode, isMirror, view) {
104
- this._rtcChannel.startRenderRemoteVideoStream(streamId, view, renderMode, isMirror);
106
+ return this._rtcChannel.startRenderRemoteVideoStream(streamId, view, renderMode, isMirror);
105
107
  }
106
108
  /**
107
109
  * Stop rendering the video of the remote user on the canvas.
@@ -111,7 +113,7 @@ export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
111
113
  }, {
112
114
  key: "stopRenderRemoteVideoStream",
113
115
  value: function stopRenderRemoteVideoStream(streamId, view) {
114
- this._rtcChannel.stopRenderRemoteVideoStream(streamId, view);
116
+ return this._rtcChannel.stopRenderRemoteVideoStream(streamId, view);
115
117
  }
116
118
  /**
117
119
  * Subscribe to a remote audio stream, you will start receiving the audio data of this stream and play the audio.
@@ -120,7 +122,7 @@ export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
120
122
  }, {
121
123
  key: "startPlayRemoteAudioStream",
122
124
  value: function startPlayRemoteAudioStream(streamId) {
123
- this._rtcChannel.subscriber.subscribeRemoteAudioStream(streamId);
125
+ return this._rtcChannel.subscriber.subscribeRemoteAudioStream(streamId);
124
126
  }
125
127
  /**
126
128
  * Unsubscribe from a remote audio stream, you will stop receiving the audio data of this stream.
@@ -129,12 +131,13 @@ export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
129
131
  }, {
130
132
  key: "stopPlayRemoteAudioStream",
131
133
  value: function stopPlayRemoteAudioStream(streamId) {
132
- this._rtcChannel.subscriber.unsubscribeRemoteAudioStream(streamId);
134
+ return this._rtcChannel.subscriber.unsubscribeRemoteAudioStream(streamId);
133
135
  }
134
136
  }, {
135
137
  key: "setAudioRawDataConfig",
136
138
  value: function setAudioRawDataConfig(config) {
137
139
  // this._rtcClient.setAudioRawDataConfig('', config);
140
+ return AgoraRteReturnCode.SUCCESS;
138
141
  }
139
142
  /**
140
143
  * Set the volume of the remote audio stream.
@@ -144,7 +147,7 @@ export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
144
147
  }, {
145
148
  key: "adjustRemoteAudioStreamVolume",
146
149
  value: function adjustRemoteAudioStreamVolume(streamId, volume) {
147
- this._rtcChannel.adjustRemoteAudioStreamVolume(streamId, volume);
150
+ return this._rtcChannel.adjustRemoteAudioStreamVolume(streamId, volume);
148
151
  }
149
152
  }, {
150
153
  key: "takeSnapshot",
@@ -190,7 +193,7 @@ export var AgoraRteStreamPlayer = /*#__PURE__*/function () {
190
193
  }]);
191
194
  }();
192
195
  _AgoraRteStreamPlayer = AgoraRteStreamPlayer;
193
- var _applyDecs$e = _applyDecs(_AgoraRteStreamPlayer, [[trace, 2, "subscribeRemoteVideoStream"], [trace, 2, "unsubscribeRemoteVideoStream"], [trace, 2, "startRenderRemoteVideoStream"], [trace, 2, "stopRenderRemoteVideoStream"], [trace, 2, "startPlayRemoteAudioStream"], [trace, 2, "stopPlayRemoteAudioStream"], [trace, 2, "setAudioRawDataConfig"], [trace, 2, "adjustRemoteAudioStreamVolume"], [trace, 2, "takeSnapshot"]], []).e;
196
+ var _applyDecs$e = _applyDecs(_AgoraRteStreamPlayer, [[_subscribeRemoteVideoStreamDecs, 2, "subscribeRemoteVideoStream"], [_unsubscribeRemoteVideoStreamDecs, 2, "unsubscribeRemoteVideoStream"], [_startRenderRemoteVideoStreamDecs, 2, "startRenderRemoteVideoStream"], [_stopRenderRemoteVideoStreamDecs, 2, "stopRenderRemoteVideoStream"], [_startPlayRemoteAudioStreamDecs, 2, "startPlayRemoteAudioStream"], [_stopPlayRemoteAudioStreamDecs, 2, "stopPlayRemoteAudioStream"], [_setAudioRawDataConfigDecs, 2, "setAudioRawDataConfig"], [_adjustRemoteAudioStreamVolumeDecs, 2, "adjustRemoteAudioStreamVolume"], [_takeSnapshotDecs, 2, "takeSnapshot"]], []).e;
194
197
  var _applyDecs$e2 = _slicedToArray(_applyDecs$e, 1);
195
198
  _initProto = _applyDecs$e2[0];
196
199
  _applyDecs$e;
@@ -24,12 +24,14 @@ import "core-js/modules/esnext.iterator.filter.js";
24
24
  import "core-js/modules/esnext.iterator.for-each.js";
25
25
  import "core-js/modules/web.dom-collections.for-each.js";
26
26
  import { toLower } from '../../imports';
27
- import { getLogger } from '../utilities/logger';
27
+ import { createLogger } from '../utilities/logger';
28
28
  export var AgoraRteServiceApi = /*#__PURE__*/function () {
29
29
  function AgoraRteServiceApi(_client, _appId, _region) {
30
30
  var _pathIncludeRegion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
31
31
  _classCallCheck(this, AgoraRteServiceApi);
32
- _defineProperty(this, "logger", getLogger());
32
+ _defineProperty(this, "logger", createLogger({
33
+ prefix: 'AgoraRteServiceApi'
34
+ }));
33
35
  this._client = _client;
34
36
  this._appId = _appId;
35
37
  this._region = _region;
@@ -38,7 +40,7 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
38
40
  if (_pathIncludeRegion) {
39
41
  pathPrefix = "/".concat(toLower(_region)).concat(pathPrefix);
40
42
  }
41
- this.logger.info('[AgoraRteServiceApi] set path prefix for RTE Service API:', pathPrefix);
43
+ this.logger.info('set path prefix for RTE Service API:', pathPrefix);
42
44
  this._pathPrefix = pathPrefix;
43
45
  this._client.setPathPrefix(pathPrefix);
44
46
  }
@@ -599,15 +601,51 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
599
601
  return updateStream;
600
602
  }()
601
603
  }, {
602
- key: "sendRoomChatMessage",
604
+ key: "updateStreamWithToken",
603
605
  value: function () {
604
- var _sendRoomChatMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref12) {
605
- var roomUuid, message, res;
606
+ var _updateStreamWithToken = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref12, token) {
607
+ var roomUuid, userUuid, streamUuid, videoSourceState, audioSourceState, videoSourceUuid, audioSourceUuid;
606
608
  return _regeneratorRuntime.wrap(function (_context16) {
607
609
  while (1) switch (_context16.prev = _context16.next) {
608
610
  case 0:
609
- roomUuid = _ref12.roomUuid, message = _ref12.message;
611
+ roomUuid = _ref12.roomUuid, userUuid = _ref12.userUuid, streamUuid = _ref12.streamUuid, videoSourceState = _ref12.videoSourceState, audioSourceState = _ref12.audioSourceState, videoSourceUuid = _ref12.videoSourceUuid, audioSourceUuid = _ref12.audioSourceUuid;
610
612
  _context16.next = 1;
613
+ return this._client.fetch({
614
+ path: "/v1/rooms/".concat(roomUuid, "/users/").concat(userUuid, "/streams/").concat(streamUuid),
615
+ method: 'PATCH',
616
+ data: {
617
+ videoSourceState: videoSourceState,
618
+ audioSourceState: audioSourceState,
619
+ videoSourceUuid: videoSourceUuid,
620
+ audioSourceUuid: audioSourceUuid
621
+ },
622
+ headers: {
623
+ token: token
624
+ }
625
+ });
626
+ case 1:
627
+ return _context16.abrupt("return", _context16.sent);
628
+ case 2:
629
+ case "end":
630
+ return _context16.stop();
631
+ }
632
+ }, _callee16, this);
633
+ }));
634
+ function updateStreamWithToken(_x20, _x21) {
635
+ return _updateStreamWithToken.apply(this, arguments);
636
+ }
637
+ return updateStreamWithToken;
638
+ }()
639
+ }, {
640
+ key: "sendRoomChatMessage",
641
+ value: function () {
642
+ var _sendRoomChatMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref13) {
643
+ var roomUuid, message, res;
644
+ return _regeneratorRuntime.wrap(function (_context17) {
645
+ while (1) switch (_context17.prev = _context17.next) {
646
+ case 0:
647
+ roomUuid = _ref13.roomUuid, message = _ref13.message;
648
+ _context17.next = 1;
611
649
  return this._client.fetch({
612
650
  path: "/v1/rooms/".concat(roomUuid, "/chat/channel"),
613
651
  method: 'POST',
@@ -617,15 +655,15 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
617
655
  }
618
656
  });
619
657
  case 1:
620
- res = _context16.sent;
621
- return _context16.abrupt("return", res.data);
658
+ res = _context17.sent;
659
+ return _context17.abrupt("return", res.data);
622
660
  case 2:
623
661
  case "end":
624
- return _context16.stop();
662
+ return _context17.stop();
625
663
  }
626
- }, _callee16, this);
664
+ }, _callee17, this);
627
665
  }));
628
- function sendRoomChatMessage(_x20) {
666
+ function sendRoomChatMessage(_x22) {
629
667
  return _sendRoomChatMessage.apply(this, arguments);
630
668
  }
631
669
  return sendRoomChatMessage;
@@ -633,13 +671,13 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
633
671
  }, {
634
672
  key: "sendCustomChannelMessage",
635
673
  value: function () {
636
- var _sendCustomChannelMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref13) {
637
- var roomUuid, payload, cmd, _ref13$sync, sync;
638
- return _regeneratorRuntime.wrap(function (_context17) {
639
- while (1) switch (_context17.prev = _context17.next) {
674
+ var _sendCustomChannelMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref14) {
675
+ var roomUuid, payload, cmd, _ref14$sync, sync;
676
+ return _regeneratorRuntime.wrap(function (_context18) {
677
+ while (1) switch (_context18.prev = _context18.next) {
640
678
  case 0:
641
- roomUuid = _ref13.roomUuid, payload = _ref13.payload, cmd = _ref13.cmd, _ref13$sync = _ref13.sync, sync = _ref13$sync === void 0 ? false : _ref13$sync;
642
- _context17.next = 1;
679
+ roomUuid = _ref14.roomUuid, payload = _ref14.payload, cmd = _ref14.cmd, _ref14$sync = _ref14.sync, sync = _ref14$sync === void 0 ? false : _ref14$sync;
680
+ _context18.next = 1;
643
681
  return this._client.fetch({
644
682
  path: "/v1/rooms/".concat(roomUuid, "/message/channel"),
645
683
  method: 'POST',
@@ -652,14 +690,14 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
652
690
  }
653
691
  });
654
692
  case 1:
655
- return _context17.abrupt("return", _context17.sent);
693
+ return _context18.abrupt("return", _context18.sent);
656
694
  case 2:
657
695
  case "end":
658
- return _context17.stop();
696
+ return _context18.stop();
659
697
  }
660
- }, _callee17, this);
698
+ }, _callee18, this);
661
699
  }));
662
- function sendCustomChannelMessage(_x21) {
700
+ function sendCustomChannelMessage(_x23) {
663
701
  return _sendCustomChannelMessage.apply(this, arguments);
664
702
  }
665
703
  return sendCustomChannelMessage;
@@ -667,13 +705,13 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
667
705
  }, {
668
706
  key: "sendCustomPeerMessage",
669
707
  value: function () {
670
- var _sendCustomPeerMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref14) {
671
- var payload, toUserUuid, _ref14$waitForAck, waitForAck;
672
- return _regeneratorRuntime.wrap(function (_context18) {
673
- while (1) switch (_context18.prev = _context18.next) {
708
+ var _sendCustomPeerMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee19(_ref15) {
709
+ var payload, toUserUuid, _ref15$waitForAck, waitForAck;
710
+ return _regeneratorRuntime.wrap(function (_context19) {
711
+ while (1) switch (_context19.prev = _context19.next) {
674
712
  case 0:
675
- payload = _ref14.payload, toUserUuid = _ref14.toUserUuid, _ref14$waitForAck = _ref14.waitForAck, waitForAck = _ref14$waitForAck === void 0 ? false : _ref14$waitForAck;
676
- _context18.next = 1;
713
+ payload = _ref15.payload, toUserUuid = _ref15.toUserUuid, _ref15$waitForAck = _ref15.waitForAck, waitForAck = _ref15$waitForAck === void 0 ? false : _ref15$waitForAck;
714
+ _context19.next = 1;
677
715
  return this._client.fetch({
678
716
  path: "/v2/users/".concat(toUserUuid, "/messages/peer"),
679
717
  method: 'POST',
@@ -683,14 +721,14 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
683
721
  }
684
722
  });
685
723
  case 1:
686
- return _context18.abrupt("return", _context18.sent);
724
+ return _context19.abrupt("return", _context19.sent);
687
725
  case 2:
688
726
  case "end":
689
- return _context18.stop();
727
+ return _context19.stop();
690
728
  }
691
- }, _callee18, this);
729
+ }, _callee19, this);
692
730
  }));
693
- function sendCustomPeerMessage(_x22) {
731
+ function sendCustomPeerMessage(_x24) {
694
732
  return _sendCustomPeerMessage.apply(this, arguments);
695
733
  }
696
734
  return sendCustomPeerMessage;
@@ -698,26 +736,26 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
698
736
  }, {
699
737
  key: "updateOnlineState",
700
738
  value: function () {
701
- var _updateOnlineState = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee19(_ref15) {
739
+ var _updateOnlineState = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee20(_ref16) {
702
740
  var userUuid, roomUuid;
703
- return _regeneratorRuntime.wrap(function (_context19) {
704
- while (1) switch (_context19.prev = _context19.next) {
741
+ return _regeneratorRuntime.wrap(function (_context20) {
742
+ while (1) switch (_context20.prev = _context20.next) {
705
743
  case 0:
706
- userUuid = _ref15.userUuid, roomUuid = _ref15.roomUuid;
707
- _context19.next = 1;
744
+ userUuid = _ref16.userUuid, roomUuid = _ref16.roomUuid;
745
+ _context20.next = 1;
708
746
  return this._client.fetch({
709
747
  path: "/v1/rooms/".concat(roomUuid, "/users/").concat(userUuid, "/states/1"),
710
748
  method: 'PUT'
711
749
  });
712
750
  case 1:
713
- return _context19.abrupt("return", _context19.sent);
751
+ return _context20.abrupt("return", _context20.sent);
714
752
  case 2:
715
753
  case "end":
716
- return _context19.stop();
754
+ return _context20.stop();
717
755
  }
718
- }, _callee19, this);
756
+ }, _callee20, this);
719
757
  }));
720
- function updateOnlineState(_x23) {
758
+ function updateOnlineState(_x25) {
721
759
  return _updateOnlineState.apply(this, arguments);
722
760
  }
723
761
  return updateOnlineState;
@@ -725,13 +763,13 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
725
763
  }, {
726
764
  key: "fetchUserList",
727
765
  value: function () {
728
- var _fetchUserList = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee20(_ref16) {
766
+ var _fetchUserList = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref17) {
729
767
  var userRole, pageIndex, pageSize, roomId, userIds, excludeResponse;
730
- return _regeneratorRuntime.wrap(function (_context20) {
731
- while (1) switch (_context20.prev = _context20.next) {
768
+ return _regeneratorRuntime.wrap(function (_context21) {
769
+ while (1) switch (_context21.prev = _context21.next) {
732
770
  case 0:
733
- userRole = _ref16.userRole, pageIndex = _ref16.pageIndex, pageSize = _ref16.pageSize, roomId = _ref16.roomId, userIds = _ref16.userIds, excludeResponse = _ref16.excludeResponse;
734
- _context20.next = 1;
771
+ userRole = _ref17.userRole, pageIndex = _ref17.pageIndex, pageSize = _ref17.pageSize, roomId = _ref17.roomId, userIds = _ref17.userIds, excludeResponse = _ref17.excludeResponse;
772
+ _context21.next = 1;
735
773
  return this._client.fetch({
736
774
  path: "/v2/rooms/".concat(roomId, "/users/page"),
737
775
  method: 'GET',
@@ -744,14 +782,14 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
744
782
  }
745
783
  });
746
784
  case 1:
747
- return _context20.abrupt("return", _context20.sent);
785
+ return _context21.abrupt("return", _context21.sent);
748
786
  case 2:
749
787
  case "end":
750
- return _context20.stop();
788
+ return _context21.stop();
751
789
  }
752
- }, _callee20, this);
790
+ }, _callee21, this);
753
791
  }));
754
- function fetchUserList(_x24) {
792
+ function fetchUserList(_x26) {
755
793
  return _fetchUserList.apply(this, arguments);
756
794
  }
757
795
  return fetchUserList;
@@ -759,13 +797,13 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
759
797
  }, {
760
798
  key: "uploadEvent",
761
799
  value: function () {
762
- var _uploadEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref17) {
800
+ var _uploadEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref18) {
763
801
  var userId, event;
764
- return _regeneratorRuntime.wrap(function (_context21) {
765
- while (1) switch (_context21.prev = _context21.next) {
802
+ return _regeneratorRuntime.wrap(function (_context22) {
803
+ while (1) switch (_context22.prev = _context22.next) {
766
804
  case 0:
767
- userId = _ref17.userId, event = _ref17.event;
768
- _context21.next = 1;
805
+ userId = _ref18.userId, event = _ref18.event;
806
+ _context22.next = 1;
769
807
  return this._client.fetch({
770
808
  path: "/v1/users/".concat(userId, "/client/events"),
771
809
  method: 'POST',
@@ -776,14 +814,14 @@ export var AgoraRteServiceApi = /*#__PURE__*/function () {
776
814
  }
777
815
  });
778
816
  case 1:
779
- return _context21.abrupt("return", _context21.sent);
817
+ return _context22.abrupt("return", _context22.sent);
780
818
  case 2:
781
819
  case "end":
782
- return _context21.stop();
820
+ return _context22.stop();
783
821
  }
784
- }, _callee21, this);
822
+ }, _callee22, this);
785
823
  }));
786
- function uploadEvent(_x25) {
824
+ function uploadEvent(_x27) {
787
825
  return _uploadEvent.apply(this, arguments);
788
826
  }
789
827
  return uploadEvent;
@@ -18,11 +18,14 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
18
18
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
19
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
20
20
  import { HTTP_HEADER_K_AGORA_TOKEN, HTTP_HEADER_K_AGORA_UID, HTTP_HEADER_K_AUTHORIZATION } from '../utilities/constants';
21
+ export var getAuthorization = function getAuthorization(token) {
22
+ return "agora token=\"".concat(token, "\"");
23
+ };
21
24
  export var AgoraHttpAuthHeadersProviderImpl = /*#__PURE__*/function () {
22
25
  function AgoraHttpAuthHeadersProviderImpl(auth) {
23
26
  _classCallCheck(this, AgoraHttpAuthHeadersProviderImpl);
24
27
  _defineProperty(this, "_headers", {});
25
- this._headers = _defineProperty(_defineProperty(_defineProperty({}, HTTP_HEADER_K_AGORA_TOKEN, auth.token), HTTP_HEADER_K_AGORA_UID, auth.userId), HTTP_HEADER_K_AUTHORIZATION, "agora token=\"".concat(auth.token, "\""));
28
+ this._headers = _defineProperty(_defineProperty(_defineProperty({}, HTTP_HEADER_K_AGORA_TOKEN, auth.token), HTTP_HEADER_K_AGORA_UID, auth.userId), HTTP_HEADER_K_AUTHORIZATION, getAuthorization(auth.token));
26
29
  }
27
30
  return _createClass(AgoraHttpAuthHeadersProviderImpl, [{
28
31
  key: "clone",
@@ -7,9 +7,12 @@ import _inherits from "@babel/runtime/helpers/inherits";
7
7
  import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
8
8
  import "core-js/modules/es.error.cause.js";
9
9
  import "core-js/modules/es.error.to-string.js";
10
+ import "core-js/modules/es.array.concat.js";
10
11
  import "core-js/modules/es.function.name.js";
11
12
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
12
13
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
+ import { DetailErrorCode, ErrorModuleCode } from '../../imports';
15
+ import { generateRteClientErrorNew, generateRteServerErrorNew } from '../utilities/error';
13
16
  export var AgoraRestfulClientError = /*#__PURE__*/function (_Error) {
14
17
  function AgoraRestfulClientError(_httpCode, _message) {
15
18
  var _this;
@@ -46,4 +49,13 @@ export var AgoraRestfulClientError = /*#__PURE__*/function (_Error) {
46
49
  return (_this$_opts2 = this._opts) === null || _this$_opts2 === void 0 ? void 0 : _this$_opts2.origin;
47
50
  }
48
51
  }]);
49
- }(/*#__PURE__*/_wrapNativeSuper(Error));
52
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
53
+ export var isRestfulError = function isRestfulError(err) {
54
+ return err instanceof AgoraRestfulClientError;
55
+ };
56
+ export var wrapRestfulErrorAsRteError = function wrapRestfulErrorAsRteError(err, prefix) {
57
+ var _err$serviceCode;
58
+ var msg = "".concat(prefix, ", ").concat(err.message);
59
+ var isLocal = err.httpCode < 100;
60
+ return isLocal ? generateRteClientErrorNew(ErrorModuleCode.RTE_ENGINE, DetailErrorCode.LOCAL_HTTP_REQUEST_FAILED, msg) : generateRteServerErrorNew((_err$serviceCode = err.serviceCode) !== null && _err$serviceCode !== void 0 ? _err$serviceCode : -1, msg);
61
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,146 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/createClass";
5
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
7
+ import "core-js/modules/es.array.for-each.js";
8
+ import "core-js/modules/es.array.iterator.js";
9
+ import "core-js/modules/es.object.to-string.js";
10
+ import "core-js/modules/es.promise.js";
11
+ import "core-js/modules/es.set.js";
12
+ import "core-js/modules/es.string.iterator.js";
13
+ import "core-js/modules/esnext.iterator.constructor.js";
14
+ import "core-js/modules/esnext.iterator.for-each.js";
15
+ import "core-js/modules/esnext.set.add-all.js";
16
+ import "core-js/modules/esnext.set.delete-all.js";
17
+ import "core-js/modules/esnext.set.difference.v2.js";
18
+ import "core-js/modules/esnext.set.difference.js";
19
+ import "core-js/modules/esnext.set.every.js";
20
+ import "core-js/modules/esnext.set.filter.js";
21
+ import "core-js/modules/esnext.set.find.js";
22
+ import "core-js/modules/esnext.set.intersection.v2.js";
23
+ import "core-js/modules/esnext.set.intersection.js";
24
+ import "core-js/modules/esnext.set.is-disjoint-from.v2.js";
25
+ import "core-js/modules/esnext.set.is-disjoint-from.js";
26
+ import "core-js/modules/esnext.set.is-subset-of.v2.js";
27
+ import "core-js/modules/esnext.set.is-subset-of.js";
28
+ import "core-js/modules/esnext.set.is-superset-of.v2.js";
29
+ import "core-js/modules/esnext.set.is-superset-of.js";
30
+ import "core-js/modules/esnext.set.join.js";
31
+ import "core-js/modules/esnext.set.map.js";
32
+ import "core-js/modules/esnext.set.reduce.js";
33
+ import "core-js/modules/esnext.set.some.js";
34
+ import "core-js/modules/esnext.set.symmetric-difference.v2.js";
35
+ import "core-js/modules/esnext.set.symmetric-difference.js";
36
+ import "core-js/modules/esnext.set.union.v2.js";
37
+ import "core-js/modules/esnext.set.union.js";
38
+ import "core-js/modules/web.dom-collections.for-each.js";
39
+ import "core-js/modules/web.dom-collections.iterator.js";
40
+ import { DetailErrorCode, ErrorModuleCode } from '../../imports';
41
+ import { AgoraRteError, generateRteClientErrorNew } from './error';
42
+
43
+ /**
44
+ * AbortManager manages abortable operations.
45
+ * 为异步函数提供中止管理功能。
46
+ */
47
+ export var AbortManager = /*#__PURE__*/function () {
48
+ function AbortManager() {
49
+ _classCallCheck(this, AbortManager);
50
+ _defineProperty(this, "_aborted", false);
51
+ _defineProperty(this, "_waiters", new Set());
52
+ }
53
+ return _createClass(AbortManager, [{
54
+ key: "isAborted",
55
+ get: function get() {
56
+ return this._aborted;
57
+ }
58
+ }, {
59
+ key: "reason",
60
+ get: function get() {
61
+ return this._reason;
62
+ }
63
+ }, {
64
+ key: "manage",
65
+ value: function manage(fn) {
66
+ var _this = this;
67
+ return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
68
+ var onAbort,
69
+ abortPromise,
70
+ _len,
71
+ args,
72
+ _key,
73
+ result,
74
+ _args = arguments;
75
+ return _regeneratorRuntime.wrap(function (_context) {
76
+ while (1) switch (_context.prev = _context.next) {
77
+ case 0:
78
+ _this.checkAborted();
79
+ abortPromise = new Promise(function (_, reject) {
80
+ onAbort = function onAbort(error) {
81
+ return reject(error);
82
+ };
83
+ _this._waiters.add(onAbort);
84
+ });
85
+ _context.prev = 1;
86
+ for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
87
+ args[_key] = _args[_key];
88
+ }
89
+ _context.next = 2;
90
+ return Promise.race([Promise.resolve(fn.apply(void 0, _toConsumableArray(args))), abortPromise]);
91
+ case 2:
92
+ result = _context.sent;
93
+ _this.checkAborted();
94
+ return _context.abrupt("return", result);
95
+ case 3:
96
+ _context.prev = 3;
97
+ if (onAbort) {
98
+ _this._waiters["delete"](onAbort);
99
+ }
100
+ return _context.finish(3);
101
+ case 4:
102
+ case "end":
103
+ return _context.stop();
104
+ }
105
+ }, _callee, null, [[1,, 3, 4]]);
106
+ }));
107
+ }
108
+ }, {
109
+ key: "abort",
110
+ value: function abort(reason) {
111
+ if (this._aborted) {
112
+ return;
113
+ }
114
+ var abortError = generateRteClientErrorNew(ErrorModuleCode.RTE_SCENE, DetailErrorCode.JOIN_FAILED, reason || 'Operation was aborted');
115
+ this._aborted = true;
116
+ this._reason = abortError;
117
+ this._waiters.forEach(function (reject) {
118
+ return reject(abortError);
119
+ });
120
+ this._waiters.clear();
121
+ }
122
+ }, {
123
+ key: "reset",
124
+ value: function reset() {
125
+ this._aborted = false;
126
+ this._reason = undefined;
127
+ this._waiters.clear();
128
+ }
129
+ }, {
130
+ key: "checkAborted",
131
+ value: function checkAborted() {
132
+ if (this._aborted && this._reason) {
133
+ throw this._reason;
134
+ }
135
+ }
136
+ }], [{
137
+ key: "create",
138
+ value: function create() {
139
+ return new AbortManager();
140
+ }
141
+ }]);
142
+ }();
143
+ export function isAbortError(error) {
144
+ var ABORT_ERROR_CODE = generateRteClientErrorNew(ErrorModuleCode.RTE_SCENE, DetailErrorCode.JOIN_FAILED, '').code;
145
+ return error instanceof AgoraRteError && error.code === ABORT_ERROR_CODE;
146
+ }