@webex/internal-media-core 0.0.6-beta → 0.0.8-beta

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/cjs/index.js CHANGED
@@ -4292,7 +4292,70 @@ function appendToH264fmtpParams(sdp, paramsToAppend) {
4292
4292
  }
4293
4293
 
4294
4294
  function setH264MaxFs(sdp, maxFsValue) {
4295
- appendToH264fmtpParams(sdp, "max-fs=".concat(maxFsValue));
4295
+ var maxFsForProfileLevel = {
4296
+ 10: 99,
4297
+ 11: 396,
4298
+ 12: 396,
4299
+ 13: 396,
4300
+ 20: 396,
4301
+ 21: 792,
4302
+ 22: 1620,
4303
+ 30: 1620,
4304
+ 31: 3600,
4305
+ 32: 5120,
4306
+ 40: 8192,
4307
+ 41: 8192,
4308
+ 42: 8704,
4309
+ 50: 22080,
4310
+ 51: 36864,
4311
+ 52: 36864,
4312
+ 60: 139264,
4313
+ 61: 139264,
4314
+ 62: 139264
4315
+ };
4316
+ sdp.avMedia.forEach(media => {
4317
+ if (media.type === 'video') {
4318
+ media.codecs.forEach(codec => {
4319
+ var _codec$name3;
4320
+
4321
+ if (((_codec$name3 = codec.name) === null || _codec$name3 === void 0 ? void 0 : _codec$name3.toUpperCase()) === 'H264') {
4322
+ codec.fmtParams = codec.fmtParams.map(fmtp => {
4323
+ var parsedRegex = fmtp.match(/(.*)profile-level-id=(\w{4})(\w{2})(.*)/);
4324
+
4325
+ if (parsedRegex && parsedRegex.length === 5) {
4326
+ var stuffBeforeProfileLevelId = parsedRegex[1];
4327
+ var profile = parsedRegex[2].toLowerCase();
4328
+ var levelId = parseInt(parsedRegex[3], 16);
4329
+ var stuffAfterProfileLevelId = parsedRegex[4];
4330
+
4331
+ if (!maxFsForProfileLevel[levelId]) {
4332
+ throw new Error("found unsupported h264 profile level id value in the SDP: ".concat(levelId));
4333
+ }
4334
+
4335
+ if (maxFsForProfileLevel[levelId] === maxFsValue) {
4336
+ return fmtp;
4337
+ }
4338
+
4339
+ if (maxFsForProfileLevel[levelId] < maxFsValue) {
4340
+ return "".concat(fmtp, ";max-fs=").concat(maxFsValue);
4341
+ }
4342
+
4343
+ var newLevelId = Object.keys(maxFsForProfileLevel).reverse().find(key => maxFsForProfileLevel[key] === maxFsValue);
4344
+
4345
+ if (newLevelId) {
4346
+ var newLevelIdHex = parseInt(newLevelId, 10).toString(16);
4347
+ return "".concat(stuffBeforeProfileLevelId, "profile-level-id=").concat(profile).concat(newLevelIdHex).concat(stuffAfterProfileLevelId);
4348
+ }
4349
+
4350
+ throw new Error("unsupported maxFsValue: ".concat(maxFsValue));
4351
+ }
4352
+
4353
+ return fmtp;
4354
+ });
4355
+ }
4356
+ });
4357
+ }
4358
+ });
4296
4359
  }
4297
4360
 
4298
4361
  function disableRtx(sdp) {
@@ -4448,8 +4511,8 @@ class MediaConnection$1 extends EventEmitter {
4448
4511
  _defineProperty__default["default"](this, "lastEmittedMediaConnectionState", void 0);
4449
4512
 
4450
4513
  this.config = mediaConnectionConfig;
4451
- this.receiveOptions = options.receive;
4452
- this.localTracks = options.send;
4514
+ this.receiveOptions = _objectSpread$1({}, options.receive);
4515
+ this.localTracks = _objectSpread$1({}, options.send);
4453
4516
  this.id = debugId || 'MediaConnection';
4454
4517
  this.transceivers = {};
4455
4518
  this.mediaConnectionState = ConnectionState.NEW;
@@ -4466,6 +4529,10 @@ class MediaConnection$1 extends EventEmitter {
4466
4529
  getLogger().info("".concat(this.id, ":").concat(action, " ").concat(description));
4467
4530
  }
4468
4531
 
4532
+ warn(action, description) {
4533
+ getLogger().warn("".concat(this.id, ":").concat(action, " ").concat(description));
4534
+ }
4535
+
4469
4536
  error(action, description, error) {
4470
4537
  getLogger().error("".concat(this.id, ":").concat(action, " ").concat(description, " ").concat(getErrorDescription(error)));
4471
4538
  }
@@ -4523,9 +4590,20 @@ class MediaConnection$1 extends EventEmitter {
4523
4590
  };
4524
4591
  }
4525
4592
 
4593
+ updateRemoteQualityLevel(newValue) {
4594
+ if (newValue !== this.receiveOptions.remoteQualityLevel) {
4595
+ this.receiveOptions.remoteQualityLevel = newValue;
4596
+ return true;
4597
+ }
4598
+
4599
+ return false;
4600
+ }
4601
+
4526
4602
  updateTransceivers(options) {
4527
4603
  var newOfferNeeded = false;
4528
- this.receiveOptions = options.receive;
4604
+ this.receiveOptions.audio = options.receive.audio;
4605
+ this.receiveOptions.video = options.receive.video;
4606
+ this.receiveOptions.screenShareVideo = options.receive.screenShareVideo;
4529
4607
  this.identifyTransceivers();
4530
4608
  localTrackTypes.forEach(_ref2 => {
4531
4609
  var {
@@ -4567,14 +4645,34 @@ class MediaConnection$1 extends EventEmitter {
4567
4645
  }
4568
4646
 
4569
4647
  updateReceiveOptions(options) {
4570
- return this.updateTransceivers({
4648
+ var sdpNegotiationNeeded = false;
4649
+
4650
+ if (this.updateRemoteQualityLevel(options.remoteQualityLevel)) {
4651
+ sdpNegotiationNeeded = true;
4652
+ }
4653
+
4654
+ if (this.updateTransceivers({
4571
4655
  send: this.localTracks,
4572
4656
  receive: options
4573
- });
4657
+ })) {
4658
+ sdpNegotiationNeeded = true;
4659
+ }
4660
+
4661
+ return sdpNegotiationNeeded;
4574
4662
  }
4575
4663
 
4576
4664
  updateSendReceiveOptions(options) {
4577
- return this.updateTransceivers(options);
4665
+ var sdpNegotiationNeeded = false;
4666
+
4667
+ if (this.updateRemoteQualityLevel(options.receive.remoteQualityLevel)) {
4668
+ sdpNegotiationNeeded = true;
4669
+ }
4670
+
4671
+ if (this.updateTransceivers(options)) {
4672
+ sdpNegotiationNeeded = true;
4673
+ }
4674
+
4675
+ return sdpNegotiationNeeded;
4578
4676
  }
4579
4677
 
4580
4678
  getConnectionState() {
@@ -4790,18 +4888,43 @@ class MediaConnection$1 extends EventEmitter {
4790
4888
  }
4791
4889
  }
4792
4890
 
4891
+ createSdpMungingConfig() {
4892
+ if (this.receiveOptions.remoteQualityLevel) {
4893
+ var maxFsValues = {
4894
+ LOW: 1620,
4895
+ MEDIUM: 3600,
4896
+ HIGH: 8192
4897
+ };
4898
+
4899
+ if (!maxFsValues[this.receiveOptions.remoteQualityLevel]) {
4900
+ throw new Error("invalid value for receiveOptions.remoteQualityLevel: ".concat(this.receiveOptions.remoteQualityLevel));
4901
+ }
4902
+
4903
+ if (this.config.sdpMunging.h264MaxFs) {
4904
+ this.warn('createSdpMungingConfig', 'conflict: both config.sdpMunging.h264MaxFs and receiveOptions.remoteQualityLevel are set, remoteQualityLevel will override the config');
4905
+ }
4906
+
4907
+ return _objectSpread$1(_objectSpread$1({}, this.config.sdpMunging), {}, {
4908
+ h264MaxFs: maxFsValues[this.receiveOptions.remoteQualityLevel]
4909
+ });
4910
+ }
4911
+
4912
+ return this.config.sdpMunging;
4913
+ }
4914
+
4793
4915
  createLocalOffer() {
4916
+ var sdpMungingConfig = this.createSdpMungingConfig();
4794
4917
  return this.pc.createOffer().then(description => {
4795
4918
  this.log('createLocalOffer', 'local SDP offer created');
4796
4919
  var mungedDescription = {
4797
4920
  type: description.type,
4798
- sdp: mungeLocalSdpForBrowser(this.config.sdpMunging, (description === null || description === void 0 ? void 0 : description.sdp) || '')
4921
+ sdp: mungeLocalSdpForBrowser(sdpMungingConfig, (description === null || description === void 0 ? void 0 : description.sdp) || '')
4799
4922
  };
4800
4923
  return this.pc.setLocalDescription(mungedDescription);
4801
4924
  }).then(() => this.waitForIceCandidates()).then(() => {
4802
4925
  var _this$pc$localDescrip;
4803
4926
 
4804
- var mungedSdp = mungeLocalSdp(this.config.sdpMunging, ((_this$pc$localDescrip = this.pc.localDescription) === null || _this$pc$localDescrip === void 0 ? void 0 : _this$pc$localDescrip.sdp) || '');
4927
+ var mungedSdp = mungeLocalSdp(sdpMungingConfig, ((_this$pc$localDescrip = this.pc.localDescription) === null || _this$pc$localDescrip === void 0 ? void 0 : _this$pc$localDescrip.sdp) || '');
4805
4928
  return {
4806
4929
  sdp: mungedSdp
4807
4930
  };
@@ -4816,19 +4939,20 @@ class MediaConnection$1 extends EventEmitter {
4816
4939
  }
4817
4940
 
4818
4941
  var mungedRemoteSdp = mungeRemoteSdp(this.config.sdpMunging, sdp);
4942
+ var sdpMungingConfig = this.createSdpMungingConfig();
4819
4943
  return this.pc.setRemoteDescription(new window.RTCSessionDescription({
4820
4944
  type: 'offer',
4821
4945
  sdp: mungedRemoteSdp
4822
4946
  })).then(() => this.pc.createAnswer()).then(answer => {
4823
4947
  var mungedAnswer = {
4824
4948
  type: answer.type,
4825
- sdp: mungeLocalSdpForBrowser(this.config.sdpMunging, (answer === null || answer === void 0 ? void 0 : answer.sdp) || '')
4949
+ sdp: mungeLocalSdpForBrowser(sdpMungingConfig, (answer === null || answer === void 0 ? void 0 : answer.sdp) || '')
4826
4950
  };
4827
4951
  return this.pc.setLocalDescription(mungedAnswer);
4828
4952
  }).then(() => this.waitForIceCandidates()).then(() => {
4829
4953
  var _this$pc$localDescrip2;
4830
4954
 
4831
- var mungedLocalSdp = mungeLocalSdp(this.config.sdpMunging, ((_this$pc$localDescrip2 = this.pc.localDescription) === null || _this$pc$localDescrip2 === void 0 ? void 0 : _this$pc$localDescrip2.sdp) || '');
4955
+ var mungedLocalSdp = mungeLocalSdp(sdpMungingConfig, ((_this$pc$localDescrip2 = this.pc.localDescription) === null || _this$pc$localDescrip2 === void 0 ? void 0 : _this$pc$localDescrip2.sdp) || '');
4832
4956
  return {
4833
4957
  sdp: mungedLocalSdp
4834
4958
  };
@@ -5096,7 +5220,7 @@ function detectBrowser(window) {
5096
5220
  // Firefox.
5097
5221
  result.browser = 'firefox';
5098
5222
  result.version = extractVersion(navigator.userAgent, /Firefox\/(\d+)\./, 1);
5099
- } else if (navigator.webkitGetUserMedia || window.isSecureContext === false && window.webkitRTCPeerConnection && !window.RTCIceGatherer) {
5223
+ } else if (navigator.webkitGetUserMedia || window.isSecureContext === false && window.webkitRTCPeerConnection) {
5100
5224
  // Chrome, Chromium, Webview, Opera.
5101
5225
  // Version matches Chrome/WebRTC version.
5102
5226
  // Chrome 74 removed webkitGetUserMedia on http as well so we need the
@@ -6456,13 +6580,20 @@ function shimAddTransceiver(window) {
6456
6580
 
6457
6581
  if (origAddTransceiver) {
6458
6582
  window.RTCPeerConnection.prototype.addTransceiver = function addTransceiver() {
6459
- this.setParametersPromises = [];
6460
- var initParameters = arguments[1];
6461
- var shouldPerformCheck = initParameters && 'sendEncodings' in initParameters;
6583
+ this.setParametersPromises = []; // WebIDL input coercion and validation
6584
+
6585
+ var sendEncodings = arguments[1] && arguments[1].sendEncodings;
6586
+
6587
+ if (sendEncodings === undefined) {
6588
+ sendEncodings = [];
6589
+ }
6590
+
6591
+ sendEncodings = [...sendEncodings];
6592
+ var shouldPerformCheck = sendEncodings.length > 0;
6462
6593
 
6463
6594
  if (shouldPerformCheck) {
6464
6595
  // If sendEncodings params are provided, validate grammar
6465
- initParameters.sendEncodings.forEach(encodingParam => {
6596
+ sendEncodings.forEach(encodingParam => {
6466
6597
  if ('rid' in encodingParam) {
6467
6598
  var ridRegex = /^[a-z0-9]{0,16}$/i;
6468
6599
 
@@ -6502,8 +6633,8 @@ function shimAddTransceiver(window) {
6502
6633
 
6503
6634
  if (!('encodings' in params) || // Avoid being fooled by patched getParameters() below.
6504
6635
  params.encodings.length === 1 && Object.keys(params.encodings[0]).length === 0) {
6505
- params.encodings = initParameters.sendEncodings;
6506
- sender.sendEncodings = initParameters.sendEncodings;
6636
+ params.encodings = sendEncodings;
6637
+ sender.sendEncodings = sendEncodings;
6507
6638
  this.setParametersPromises.push(sender.setParameters(params).then(() => {
6508
6639
  delete sender.sendEncodings;
6509
6640
  }).catch(() => {
@@ -9455,20 +9586,52 @@ function error(id, data) {
9455
9586
  return eventObject;
9456
9587
  }
9457
9588
 
9458
- function resolveActions(machine, currentState, currentContext, _event, actions, predictableExec, preserveActionOrder) {
9589
+ var pluckAssigns = function pluckAssigns(actionBlocks) {
9590
+ var e_1, _a;
9591
+
9592
+ var assignActions = [];
9593
+
9594
+ try {
9595
+ for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
9596
+ var block = actionBlocks_1_1.value;
9597
+ var i = 0;
9598
+
9599
+ while (i < block.length) {
9600
+ if (block[i].type === assign$2) {
9601
+ assignActions.push(block[i]);
9602
+ block.splice(i, 1);
9603
+ continue;
9604
+ }
9605
+
9606
+ i++;
9607
+ }
9608
+ }
9609
+ } catch (e_1_1) {
9610
+ e_1 = {
9611
+ error: e_1_1
9612
+ };
9613
+ } finally {
9614
+ try {
9615
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
9616
+ } finally {
9617
+ if (e_1) throw e_1.error;
9618
+ }
9619
+ }
9620
+
9621
+ return assignActions;
9622
+ };
9623
+
9624
+ function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
9459
9625
  if (preserveActionOrder === void 0) {
9460
9626
  preserveActionOrder = false;
9461
9627
  }
9462
9628
 
9463
- var _a = __read(preserveActionOrder ? [[], actions] : partition(actions, function (action) {
9464
- return action.type === assign$2;
9465
- }), 2),
9466
- assignActions = _a[0],
9467
- otherActions = _a[1];
9468
-
9629
+ var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
9469
9630
  var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
9470
9631
  var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
9471
- var resolvedActions = flatten(otherActions.map(function (actionObject) {
9632
+ var deferredToBlockEnd = [];
9633
+
9634
+ function handleAction(actionObject) {
9472
9635
  var _a;
9473
9636
 
9474
9637
  switch (actionObject.type) {
@@ -9486,8 +9649,8 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9486
9649
  "No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
9487
9650
  }
9488
9651
 
9489
- if (sendAction.to !== SpecialTargets.Internal) {
9490
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
9652
+ if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
9653
+ deferredToBlockEnd.push(sendAction);
9491
9654
  }
9492
9655
 
9493
9656
  return sendAction;
@@ -9511,7 +9674,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9511
9674
  return [];
9512
9675
  }
9513
9676
 
9514
- var _b = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
9677
+ var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
9515
9678
  resolvedActionsFromChoose = _b[0],
9516
9679
  resolvedContextFromChoose = _b[1];
9517
9680
 
@@ -9528,7 +9691,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9528
9691
  return [];
9529
9692
  }
9530
9693
 
9531
- var _c = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
9694
+ var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
9532
9695
  resolvedActionsFromPure = _c[0],
9533
9696
  resolvedContext = _c[1];
9534
9697
 
@@ -9540,7 +9703,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9540
9703
  case stop$1:
9541
9704
  {
9542
9705
  var resolved = resolveStop(actionObject, updatedContext, _event);
9543
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
9706
+ predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
9544
9707
  return resolved;
9545
9708
  }
9546
9709
 
@@ -9574,9 +9737,42 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9574
9737
 
9575
9738
  return resolvedActionObject;
9576
9739
  }
9577
- }).filter(function (a) {
9578
- return !!a;
9579
- }));
9740
+ }
9741
+
9742
+ function processBlock(block) {
9743
+ var e_2, _a;
9744
+
9745
+ var resolvedActions = [];
9746
+
9747
+ try {
9748
+ for (var block_1 = __values(block), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
9749
+ var action = block_1_1.value;
9750
+ var resolved = handleAction(action);
9751
+
9752
+ if (resolved) {
9753
+ resolvedActions = resolvedActions.concat(resolved);
9754
+ }
9755
+ }
9756
+ } catch (e_2_1) {
9757
+ e_2 = {
9758
+ error: e_2_1
9759
+ };
9760
+ } finally {
9761
+ try {
9762
+ if (block_1_1 && !block_1_1.done && (_a = block_1.return)) _a.call(block_1);
9763
+ } finally {
9764
+ if (e_2) throw e_2.error;
9765
+ }
9766
+ }
9767
+
9768
+ deferredToBlockEnd.forEach(function (action) {
9769
+ predictableExec(action, updatedContext, _event);
9770
+ });
9771
+ deferredToBlockEnd.length = 0;
9772
+ return resolvedActions;
9773
+ }
9774
+
9775
+ var resolvedActions = flatten(actionBlocks.map(processBlock));
9580
9776
  return [resolvedActions, updatedContext];
9581
9777
  }
9582
9778
 
@@ -10442,12 +10638,12 @@ function () {
10442
10638
  * @param options Interpreter options
10443
10639
  */
10444
10640
  function Interpreter(machine, options) {
10445
- var _this = this;
10446
-
10447
10641
  if (options === void 0) {
10448
10642
  options = Interpreter.defaultOptions;
10449
10643
  }
10450
10644
 
10645
+ var _this = this;
10646
+
10451
10647
  this.machine = machine;
10452
10648
  this.delayedEventsMap = {};
10453
10649
  this.listeners = new Set();
@@ -10464,6 +10660,7 @@ function () {
10464
10660
  this.status = InterpreterStatus.NotStarted;
10465
10661
  this.children = new Map();
10466
10662
  this.forwardTo = new Set();
10663
+ this._outgoingQueue = [];
10467
10664
  /**
10468
10665
  * Alias for Interpreter.prototype.start
10469
10666
  */
@@ -10506,7 +10703,7 @@ function () {
10506
10703
  // Forward copy of event to child actors
10507
10704
  _this.forward(_event);
10508
10705
 
10509
- var nextState = _this.nextState(_event);
10706
+ var nextState = _this._nextState(_event);
10510
10707
 
10511
10708
  _this.update(nextState, _event);
10512
10709
  });
@@ -10515,7 +10712,7 @@ function () {
10515
10712
  // tslint:disable-next-line:semicolon
10516
10713
  };
10517
10714
 
10518
- this.sendTo = function (event, to) {
10715
+ this.sendTo = function (event, to, immediate) {
10519
10716
  var isParent = _this.parent && (to === SpecialTargets.Parent || _this.parent.id === to);
10520
10717
  var target = isParent ? _this.parent : isString(to) ? _this.children.get(to) || registry.get(to) : isActor$1(to) ? to : undefined;
10521
10718
 
@@ -10538,14 +10735,24 @@ function () {
10538
10735
  if (_this.status !== InterpreterStatus.Stopped || _this.parent !== target || // we need to send events to the parent from exit handlers of a machine that reached its final state
10539
10736
  _this.state.done) {
10540
10737
  // Send SCXML events to machines
10541
- target.send(_assign(_assign({}, event), {
10738
+ var scxmlEvent = _assign(_assign({}, event), {
10542
10739
  name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
10543
10740
  origin: _this.sessionId
10544
- }));
10741
+ });
10742
+
10743
+ if (!immediate && _this.machine.config.predictableActionArguments) {
10744
+ _this._outgoingQueue.push([target, scxmlEvent]);
10745
+ } else {
10746
+ target.send(scxmlEvent);
10747
+ }
10545
10748
  }
10546
10749
  } else {
10547
10750
  // Send normal events to other targets
10548
- target.send(event.data);
10751
+ if (!immediate && _this.machine.config.predictableActionArguments) {
10752
+ _this._outgoingQueue.push([target, event.data]);
10753
+ } else {
10754
+ target.send(event.data);
10755
+ }
10549
10756
  }
10550
10757
  };
10551
10758
 
@@ -10589,7 +10796,7 @@ function () {
10589
10796
  return;
10590
10797
  } else {
10591
10798
  if (sendAction.to) {
10592
- _this.sendTo(sendAction._event, sendAction.to);
10799
+ _this.sendTo(sendAction._event, sendAction.to, _event === initEvent);
10593
10800
  } else {
10594
10801
  _this.send(sendAction._event);
10595
10802
  }
@@ -10738,6 +10945,9 @@ function () {
10738
10945
  configurable: true
10739
10946
  });
10740
10947
  Object.defineProperty(Interpreter.prototype, "state", {
10948
+ /**
10949
+ * @deprecated Use `.getSnapshot()` instead.
10950
+ */
10741
10951
  get: function get() {
10742
10952
  if (!IS_PRODUCTION) {
10743
10953
  warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
@@ -10790,6 +11000,12 @@ function () {
10790
11000
  // we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
10791
11001
  _event === initEvent) && this.options.execute) {
10792
11002
  this.execute(this.state);
11003
+ } else {
11004
+ var item = void 0;
11005
+
11006
+ while (item = this._outgoingQueue.shift()) {
11007
+ item[0].send(item[1]);
11008
+ }
10793
11009
  } // Update children
10794
11010
 
10795
11011
 
@@ -10880,6 +11096,8 @@ function () {
10880
11096
  }
10881
11097
 
10882
11098
  this._stop();
11099
+
11100
+ this._stopChildren();
10883
11101
  }
10884
11102
  };
10885
11103
  /*
@@ -11038,6 +11256,16 @@ function () {
11038
11256
  return this;
11039
11257
  };
11040
11258
 
11259
+ Interpreter.prototype._stopChildren = function () {
11260
+ // TODO: think about converting those to actions
11261
+ this.children.forEach(function (child) {
11262
+ if (isFunction(child.stop)) {
11263
+ child.stop();
11264
+ }
11265
+ });
11266
+ this.children.clear();
11267
+ };
11268
+
11041
11269
  Interpreter.prototype._stop = function () {
11042
11270
  var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
11043
11271
 
@@ -11175,7 +11403,7 @@ function () {
11175
11403
  return toActionObjects(stateNode.onExit, _this.machine.options.actions);
11176
11404
  }));
11177
11405
 
11178
- var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, exitActions, _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
11406
+ var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [exitActions], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
11179
11407
  resolvedActions = _a[0],
11180
11408
  updatedContext = _a[1];
11181
11409
 
@@ -11202,17 +11430,9 @@ function () {
11202
11430
  return newState;
11203
11431
  });
11204
11432
 
11205
- _this.update(nextState, _event); // TODO: think about converting those to actions
11206
- // Stop all children
11433
+ _this.update(nextState, _event);
11207
11434
 
11208
-
11209
- _this.children.forEach(function (child) {
11210
- if (isFunction(child.stop)) {
11211
- child.stop();
11212
- }
11213
- });
11214
-
11215
- _this.children.clear();
11435
+ _this._stopChildren();
11216
11436
 
11217
11437
  registry.free(_this.sessionId);
11218
11438
  });
@@ -11232,6 +11452,11 @@ function () {
11232
11452
  "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options."));
11233
11453
  }
11234
11454
 
11455
+ if (!events.length) {
11456
+ return;
11457
+ }
11458
+
11459
+ var exec = !!this.machine.config.predictableActionArguments && this._exec;
11235
11460
  this.scheduler.schedule(function () {
11236
11461
  var e_11, _a;
11237
11462
 
@@ -11245,9 +11470,9 @@ function () {
11245
11470
  _this.forward(_event);
11246
11471
 
11247
11472
  nextState = provide(_this, function () {
11248
- return _this.machine.transition(nextState, _event);
11473
+ return _this.machine.transition(nextState, _event, undefined, exec || undefined);
11249
11474
  });
11250
- batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
11475
+ batchedActions.push.apply(batchedActions, __spreadArray([], __read(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
11251
11476
  return bindActionToState(a, nextState);
11252
11477
  })), false));
11253
11478
  batchChanged = batchChanged || !!nextState.changed;
@@ -11288,9 +11513,13 @@ function () {
11288
11513
  return this.send.bind(this, event);
11289
11514
  };
11290
11515
 
11291
- Interpreter.prototype._nextState = function (event) {
11516
+ Interpreter.prototype._nextState = function (event, exec) {
11292
11517
  var _this = this;
11293
11518
 
11519
+ if (exec === void 0) {
11520
+ exec = !!this.machine.config.predictableActionArguments && this._exec;
11521
+ }
11522
+
11294
11523
  var _event = toSCXMLEvent(event);
11295
11524
 
11296
11525
  if (_event.name.indexOf(errorPlatform) === 0 && !this.state.nextEvents.some(function (nextEvent) {
@@ -11300,7 +11529,7 @@ function () {
11300
11529
  }
11301
11530
 
11302
11531
  var nextState = provide(this, function () {
11303
- return _this.machine.transition(_this.state, _event, undefined, _this.machine.config.predictableActionArguments ? _this._exec : undefined);
11532
+ return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
11304
11533
  });
11305
11534
  return nextState;
11306
11535
  };
@@ -11314,7 +11543,7 @@ function () {
11314
11543
 
11315
11544
 
11316
11545
  Interpreter.prototype.nextState = function (event) {
11317
- return this._nextState(event);
11546
+ return this._nextState(event, false);
11318
11547
  };
11319
11548
 
11320
11549
  Interpreter.prototype.forward = function (event) {
@@ -11349,7 +11578,7 @@ function () {
11349
11578
 
11350
11579
  this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
11351
11580
  if (sendAction.to) {
11352
- _this.sendTo(sendAction._event, sendAction.to);
11581
+ _this.sendTo(sendAction._event, sendAction.to, true);
11353
11582
  } else {
11354
11583
  _this.send(sendAction._event);
11355
11584
  }
@@ -11925,12 +12154,12 @@ function () {
11925
12154
  */
11926
12155
  _context, // TODO: this is unsafe, but we're removing it in v5 anyway
11927
12156
  _stateInfo) {
11928
- var _this = this;
11929
-
11930
12157
  if (_context === void 0) {
11931
12158
  _context = 'context' in config ? config.context : undefined;
11932
12159
  }
11933
12160
 
12161
+ var _this = this;
12162
+
11934
12163
  var _a;
11935
12164
 
11936
12165
  this.config = config;
@@ -12540,9 +12769,11 @@ function () {
12540
12769
  return nodes;
12541
12770
  };
12542
12771
 
12543
- StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState) {
12772
+ StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
12544
12773
  var e_4, _a, e_5, _b;
12545
12774
 
12775
+ var _this = this;
12776
+
12546
12777
  var prevConfig = getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
12547
12778
 
12548
12779
  try {
@@ -12620,20 +12851,19 @@ function () {
12620
12851
  });
12621
12852
  var entryStates = new Set(transition.entrySet);
12622
12853
  var exitStates = new Set(transition.exitSet);
12623
-
12624
- var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
12625
- return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) {
12854
+ var entryActions = Array.from(entryStates).map(function (stateNode) {
12855
+ var entryActions = stateNode.onEntry;
12856
+ var invokeActions = stateNode.activities.map(function (activity) {
12626
12857
  return start(activity);
12627
- })), false), __read(stateNode.onEntry), false);
12628
- })).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
12629
- return __spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
12858
+ });
12859
+ return toActionObjects(predictableExec ? __spreadArray(__spreadArray([], __read(entryActions), false), __read(invokeActions), false) : __spreadArray(__spreadArray([], __read(invokeActions), false), __read(entryActions), false), _this.machine.options.actions);
12860
+ }).concat([doneEvents.map(raise)]);
12861
+ var exitActions = Array.from(exitStates).map(function (stateNode) {
12862
+ return toActionObjects(__spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
12630
12863
  return stop(activity);
12631
- })), false);
12632
- }))], 2),
12633
- entryActions = _c[0],
12634
- exitActions = _c[1];
12635
-
12636
- var actions = toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
12864
+ })), false), _this.machine.options.actions);
12865
+ });
12866
+ var actions = exitActions.concat([toActionObjects(transition.actions, this.machine.options.actions)]).concat(entryActions);
12637
12867
 
12638
12868
  if (isDone) {
12639
12869
  var stopActions = toActionObjects(flatten(__spreadArray([], __read(resolvedConfig), false).sort(function (a, b) {
@@ -12643,7 +12873,7 @@ function () {
12643
12873
  })), this.machine.options.actions).filter(function (action) {
12644
12874
  return action.type !== raise$1 && (action.type !== send$1 || !!action.to && action.to !== SpecialTargets.Internal);
12645
12875
  });
12646
- return actions.concat(stopActions);
12876
+ return actions.concat([stopActions]);
12647
12877
  }
12648
12878
 
12649
12879
  return actions;
@@ -12714,7 +12944,7 @@ function () {
12714
12944
  };
12715
12945
 
12716
12946
  StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
12717
- var e_6, _a;
12947
+ var e_6, _a, e_7, _b;
12718
12948
 
12719
12949
  var _this = this;
12720
12950
 
@@ -12731,17 +12961,33 @@ function () {
12731
12961
  var isDone = isInFinalState(resolvedConfiguration, this);
12732
12962
  var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
12733
12963
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
12734
- var actions = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState);
12964
+ var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
12735
12965
  var activities = currentState ? _assign({}, currentState.activities) : {};
12736
12966
 
12737
12967
  try {
12738
- for (var actions_1 = __values(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
12739
- var action = actions_1_1.value;
12968
+ for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
12969
+ var block = actionBlocks_1_1.value;
12970
+
12971
+ try {
12972
+ for (var block_1 = (e_7 = void 0, __values(block)), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
12973
+ var action = block_1_1.value;
12740
12974
 
12741
- if (action.type === start$1) {
12742
- activities[action.activity.id || action.activity.type] = action;
12743
- } else if (action.type === stop$1) {
12744
- activities[action.activity.id || action.activity.type] = false;
12975
+ if (action.type === start$1) {
12976
+ activities[action.activity.id || action.activity.type] = action;
12977
+ } else if (action.type === stop$1) {
12978
+ activities[action.activity.id || action.activity.type] = false;
12979
+ }
12980
+ }
12981
+ } catch (e_7_1) {
12982
+ e_7 = {
12983
+ error: e_7_1
12984
+ };
12985
+ } finally {
12986
+ try {
12987
+ if (block_1_1 && !block_1_1.done && (_b = block_1.return)) _b.call(block_1);
12988
+ } finally {
12989
+ if (e_7) throw e_7.error;
12990
+ }
12745
12991
  }
12746
12992
  }
12747
12993
  } catch (e_6_1) {
@@ -12750,21 +12996,21 @@ function () {
12750
12996
  };
12751
12997
  } finally {
12752
12998
  try {
12753
- if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
12999
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
12754
13000
  } finally {
12755
13001
  if (e_6) throw e_6.error;
12756
13002
  }
12757
13003
  }
12758
13004
 
12759
- var _b = __read(resolveActions(this, currentState, context, _event, actions, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
12760
- resolvedActions = _b[0],
12761
- updatedContext = _b[1];
13005
+ var _c = __read(resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
13006
+ resolvedActions = _c[0],
13007
+ updatedContext = _c[1];
12762
13008
 
12763
- var _c = __read(partition(resolvedActions, function (action) {
13009
+ var _d = __read(partition(resolvedActions, function (action) {
12764
13010
  return action.type === raise$1 || action.type === send$1 && action.to === SpecialTargets.Internal;
12765
13011
  }), 2),
12766
- raisedEvents = _c[0],
12767
- nonRaisedActions = _c[1];
13012
+ raisedEvents = _d[0],
13013
+ nonRaisedActions = _d[1];
12768
13014
 
12769
13015
  var invokeActions = resolvedActions.filter(function (action) {
12770
13016
  var _a;
@@ -13213,7 +13459,7 @@ function () {
13213
13459
  * All the event types accepted by this state node and its descendants.
13214
13460
  */
13215
13461
  get: function get() {
13216
- var e_7, _a, e_8, _b;
13462
+ var e_8, _a, e_9, _b;
13217
13463
 
13218
13464
  if (this.__cache.events) {
13219
13465
  return this.__cache.events;
@@ -13230,32 +13476,32 @@ function () {
13230
13476
 
13231
13477
  if (state.states) {
13232
13478
  try {
13233
- for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
13479
+ for (var _e = (e_9 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
13234
13480
  var event_1 = _f.value;
13235
13481
  events.add("".concat(event_1));
13236
13482
  }
13237
- } catch (e_8_1) {
13238
- e_8 = {
13239
- error: e_8_1
13483
+ } catch (e_9_1) {
13484
+ e_9 = {
13485
+ error: e_9_1
13240
13486
  };
13241
13487
  } finally {
13242
13488
  try {
13243
13489
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
13244
13490
  } finally {
13245
- if (e_8) throw e_8.error;
13491
+ if (e_9) throw e_9.error;
13246
13492
  }
13247
13493
  }
13248
13494
  }
13249
13495
  }
13250
- } catch (e_7_1) {
13251
- e_7 = {
13252
- error: e_7_1
13496
+ } catch (e_8_1) {
13497
+ e_8 = {
13498
+ error: e_8_1
13253
13499
  };
13254
13500
  } finally {
13255
13501
  try {
13256
13502
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
13257
13503
  } finally {
13258
- if (e_7) throw e_7.error;
13504
+ if (e_8) throw e_8.error;
13259
13505
  }
13260
13506
  }
13261
13507
  }
@@ -13350,7 +13596,7 @@ function () {
13350
13596
  };
13351
13597
 
13352
13598
  StateNode.prototype.formatTransitions = function () {
13353
- var e_9, _a;
13599
+ var e_10, _a;
13354
13600
 
13355
13601
  var _this = this;
13356
13602
 
@@ -13414,15 +13660,15 @@ function () {
13414
13660
  var delayedTransition = delayedTransitions_1_1.value;
13415
13661
  formattedTransitions.push(delayedTransition);
13416
13662
  }
13417
- } catch (e_9_1) {
13418
- e_9 = {
13419
- error: e_9_1
13663
+ } catch (e_10_1) {
13664
+ e_10 = {
13665
+ error: e_10_1
13420
13666
  };
13421
13667
  } finally {
13422
13668
  try {
13423
13669
  if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
13424
13670
  } finally {
13425
- if (e_9) throw e_9.error;
13671
+ if (e_10) throw e_10.error;
13426
13672
  }
13427
13673
  }
13428
13674
 
@@ -14158,9 +14404,16 @@ class RoapMediaConnection extends EventEmitter {
14158
14404
  roapMessageReceived(roapMessage) {
14159
14405
  this.log('roapMessageReceived()', "called with messageType=".concat(roapMessage.messageType, ", seq=").concat(roapMessage.seq));
14160
14406
 
14161
- if (!this.sdpNegotiationStarted && roapMessage.messageType === 'OFFER') {
14162
- this.sdpNegotiationStarted = true;
14163
- this.mediaConnection.initializeTransceivers(true);
14407
+ if (!this.sdpNegotiationStarted) {
14408
+ if (roapMessage.messageType === 'OFFER') {
14409
+ this.sdpNegotiationStarted = true;
14410
+ this.mediaConnection.initializeTransceivers(true);
14411
+ }
14412
+
14413
+ if (roapMessage.messageType === 'OFFER_REQUEST') {
14414
+ this.sdpNegotiationStarted = true;
14415
+ this.mediaConnection.initializeTransceivers(false);
14416
+ }
14164
14417
  }
14165
14418
 
14166
14419
  this.roap.roapMessageReceived(roapMessage);
@@ -14283,7 +14536,6 @@ function _enableBNR() {
14283
14536
  isValidTrack(track);
14284
14537
  var streamFromTrack = new MediaStream();
14285
14538
  streamFromTrack.addTrack(track);
14286
- var audioContext;
14287
14539
  var workletNode;
14288
14540
  logger.info({
14289
14541
  ID: track.id,
@@ -14291,44 +14543,30 @@ function _enableBNR() {
14291
14543
  action: 'enableBNR()',
14292
14544
  description: 'Checking if BNR module is present already'
14293
14545
  });
14546
+ var oldDestinationTrack = bnrProcessor.destinationTrack;
14294
14547
 
14295
- if (!bnrProcessor.isModuleAdded) {
14296
- logger.debug({
14297
- ID: track.id,
14298
- mediaType: MEDIA_STREAM_TRACK,
14299
- action: 'enableBNR()',
14300
- description: 'BNR module is not present already'
14301
- });
14302
- audioContext = yield loadProcessor();
14303
- } else {
14304
- logger.debug({
14548
+ if (oldDestinationTrack && track.id === oldDestinationTrack.id) {
14549
+ var oldTrackErrorMsg = 'BNR is enabled on the track already';
14550
+ var oldTrackError = new Error(oldTrackErrorMsg);
14551
+ logger.error({
14305
14552
  ID: track.id,
14306
14553
  mediaType: MEDIA_STREAM_TRACK,
14307
14554
  action: 'enableBNR()',
14308
- description: 'BNR module is present already'
14555
+ description: oldTrackErrorMsg,
14556
+ error: oldTrackError
14309
14557
  });
14310
- var oldDestinationTrack = bnrProcessor.destinationTrack;
14311
-
14312
- if (track.id === oldDestinationTrack.id) {
14313
- var oldTrackErrorMsg = 'BNR is enabled on the track already';
14314
- var oldTrackError = new Error(oldTrackErrorMsg);
14315
- logger.error({
14316
- ID: track.id,
14317
- mediaType: MEDIA_STREAM_TRACK,
14318
- action: 'enableBNR()',
14319
- description: oldTrackErrorMsg,
14320
- error: oldTrackError
14321
- });
14322
- throw oldTrackError;
14323
- }
14558
+ throw oldTrackError;
14559
+ }
14324
14560
 
14325
- logger.info({
14561
+ if (bnrProcessor.isModuleAdded) {
14562
+ logger.debug({
14326
14563
  ID: track.id,
14327
14564
  mediaType: MEDIA_STREAM_TRACK,
14328
14565
  action: 'enableBNR()',
14329
- description: 'Using existing AudioContext'
14566
+ description: 'Disposing existing BNR module'
14330
14567
  });
14331
- audioContext = bnrProcessor.audioContext;
14568
+ workletNode = bnrProcessor.workletNode;
14569
+ workletNode.port.postMessage('DISPOSE');
14332
14570
  }
14333
14571
 
14334
14572
  logger.info({
@@ -14337,6 +14575,7 @@ function _enableBNR() {
14337
14575
  action: 'enableBNR()',
14338
14576
  description: 'Creating worklet node, connecting source and destination streams'
14339
14577
  });
14578
+ var audioContext = yield loadProcessor();
14340
14579
  workletNode = bnrProcessor.workletNode;
14341
14580
  workletNode.port.postMessage('ENABLE');
14342
14581
  bnrProcessor.sourceNode = audioContext.createMediaStreamSource(streamFromTrack);