@webex/internal-media-core 0.0.7-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/esm/index.js CHANGED
@@ -4281,7 +4281,70 @@ function appendToH264fmtpParams(sdp, paramsToAppend) {
4281
4281
  }
4282
4282
 
4283
4283
  function setH264MaxFs(sdp, maxFsValue) {
4284
- appendToH264fmtpParams(sdp, "max-fs=".concat(maxFsValue));
4284
+ var maxFsForProfileLevel = {
4285
+ 10: 99,
4286
+ 11: 396,
4287
+ 12: 396,
4288
+ 13: 396,
4289
+ 20: 396,
4290
+ 21: 792,
4291
+ 22: 1620,
4292
+ 30: 1620,
4293
+ 31: 3600,
4294
+ 32: 5120,
4295
+ 40: 8192,
4296
+ 41: 8192,
4297
+ 42: 8704,
4298
+ 50: 22080,
4299
+ 51: 36864,
4300
+ 52: 36864,
4301
+ 60: 139264,
4302
+ 61: 139264,
4303
+ 62: 139264
4304
+ };
4305
+ sdp.avMedia.forEach(media => {
4306
+ if (media.type === 'video') {
4307
+ media.codecs.forEach(codec => {
4308
+ var _codec$name3;
4309
+
4310
+ if (((_codec$name3 = codec.name) === null || _codec$name3 === void 0 ? void 0 : _codec$name3.toUpperCase()) === 'H264') {
4311
+ codec.fmtParams = codec.fmtParams.map(fmtp => {
4312
+ var parsedRegex = fmtp.match(/(.*)profile-level-id=(\w{4})(\w{2})(.*)/);
4313
+
4314
+ if (parsedRegex && parsedRegex.length === 5) {
4315
+ var stuffBeforeProfileLevelId = parsedRegex[1];
4316
+ var profile = parsedRegex[2].toLowerCase();
4317
+ var levelId = parseInt(parsedRegex[3], 16);
4318
+ var stuffAfterProfileLevelId = parsedRegex[4];
4319
+
4320
+ if (!maxFsForProfileLevel[levelId]) {
4321
+ throw new Error("found unsupported h264 profile level id value in the SDP: ".concat(levelId));
4322
+ }
4323
+
4324
+ if (maxFsForProfileLevel[levelId] === maxFsValue) {
4325
+ return fmtp;
4326
+ }
4327
+
4328
+ if (maxFsForProfileLevel[levelId] < maxFsValue) {
4329
+ return "".concat(fmtp, ";max-fs=").concat(maxFsValue);
4330
+ }
4331
+
4332
+ var newLevelId = Object.keys(maxFsForProfileLevel).reverse().find(key => maxFsForProfileLevel[key] === maxFsValue);
4333
+
4334
+ if (newLevelId) {
4335
+ var newLevelIdHex = parseInt(newLevelId, 10).toString(16);
4336
+ return "".concat(stuffBeforeProfileLevelId, "profile-level-id=").concat(profile).concat(newLevelIdHex).concat(stuffAfterProfileLevelId);
4337
+ }
4338
+
4339
+ throw new Error("unsupported maxFsValue: ".concat(maxFsValue));
4340
+ }
4341
+
4342
+ return fmtp;
4343
+ });
4344
+ }
4345
+ });
4346
+ }
4347
+ });
4285
4348
  }
4286
4349
 
4287
4350
  function disableRtx(sdp) {
@@ -4437,8 +4500,8 @@ class MediaConnection$1 extends EventEmitter {
4437
4500
  _defineProperty(this, "lastEmittedMediaConnectionState", void 0);
4438
4501
 
4439
4502
  this.config = mediaConnectionConfig;
4440
- this.receiveOptions = options.receive;
4441
- this.localTracks = options.send;
4503
+ this.receiveOptions = _objectSpread$1({}, options.receive);
4504
+ this.localTracks = _objectSpread$1({}, options.send);
4442
4505
  this.id = debugId || 'MediaConnection';
4443
4506
  this.transceivers = {};
4444
4507
  this.mediaConnectionState = ConnectionState.NEW;
@@ -4455,6 +4518,10 @@ class MediaConnection$1 extends EventEmitter {
4455
4518
  getLogger().info("".concat(this.id, ":").concat(action, " ").concat(description));
4456
4519
  }
4457
4520
 
4521
+ warn(action, description) {
4522
+ getLogger().warn("".concat(this.id, ":").concat(action, " ").concat(description));
4523
+ }
4524
+
4458
4525
  error(action, description, error) {
4459
4526
  getLogger().error("".concat(this.id, ":").concat(action, " ").concat(description, " ").concat(getErrorDescription(error)));
4460
4527
  }
@@ -4512,9 +4579,20 @@ class MediaConnection$1 extends EventEmitter {
4512
4579
  };
4513
4580
  }
4514
4581
 
4582
+ updateRemoteQualityLevel(newValue) {
4583
+ if (newValue !== this.receiveOptions.remoteQualityLevel) {
4584
+ this.receiveOptions.remoteQualityLevel = newValue;
4585
+ return true;
4586
+ }
4587
+
4588
+ return false;
4589
+ }
4590
+
4515
4591
  updateTransceivers(options) {
4516
4592
  var newOfferNeeded = false;
4517
- this.receiveOptions = options.receive;
4593
+ this.receiveOptions.audio = options.receive.audio;
4594
+ this.receiveOptions.video = options.receive.video;
4595
+ this.receiveOptions.screenShareVideo = options.receive.screenShareVideo;
4518
4596
  this.identifyTransceivers();
4519
4597
  localTrackTypes.forEach(_ref2 => {
4520
4598
  var {
@@ -4556,14 +4634,34 @@ class MediaConnection$1 extends EventEmitter {
4556
4634
  }
4557
4635
 
4558
4636
  updateReceiveOptions(options) {
4559
- return this.updateTransceivers({
4637
+ var sdpNegotiationNeeded = false;
4638
+
4639
+ if (this.updateRemoteQualityLevel(options.remoteQualityLevel)) {
4640
+ sdpNegotiationNeeded = true;
4641
+ }
4642
+
4643
+ if (this.updateTransceivers({
4560
4644
  send: this.localTracks,
4561
4645
  receive: options
4562
- });
4646
+ })) {
4647
+ sdpNegotiationNeeded = true;
4648
+ }
4649
+
4650
+ return sdpNegotiationNeeded;
4563
4651
  }
4564
4652
 
4565
4653
  updateSendReceiveOptions(options) {
4566
- return this.updateTransceivers(options);
4654
+ var sdpNegotiationNeeded = false;
4655
+
4656
+ if (this.updateRemoteQualityLevel(options.receive.remoteQualityLevel)) {
4657
+ sdpNegotiationNeeded = true;
4658
+ }
4659
+
4660
+ if (this.updateTransceivers(options)) {
4661
+ sdpNegotiationNeeded = true;
4662
+ }
4663
+
4664
+ return sdpNegotiationNeeded;
4567
4665
  }
4568
4666
 
4569
4667
  getConnectionState() {
@@ -4779,18 +4877,43 @@ class MediaConnection$1 extends EventEmitter {
4779
4877
  }
4780
4878
  }
4781
4879
 
4880
+ createSdpMungingConfig() {
4881
+ if (this.receiveOptions.remoteQualityLevel) {
4882
+ var maxFsValues = {
4883
+ LOW: 1620,
4884
+ MEDIUM: 3600,
4885
+ HIGH: 8192
4886
+ };
4887
+
4888
+ if (!maxFsValues[this.receiveOptions.remoteQualityLevel]) {
4889
+ throw new Error("invalid value for receiveOptions.remoteQualityLevel: ".concat(this.receiveOptions.remoteQualityLevel));
4890
+ }
4891
+
4892
+ if (this.config.sdpMunging.h264MaxFs) {
4893
+ this.warn('createSdpMungingConfig', 'conflict: both config.sdpMunging.h264MaxFs and receiveOptions.remoteQualityLevel are set, remoteQualityLevel will override the config');
4894
+ }
4895
+
4896
+ return _objectSpread$1(_objectSpread$1({}, this.config.sdpMunging), {}, {
4897
+ h264MaxFs: maxFsValues[this.receiveOptions.remoteQualityLevel]
4898
+ });
4899
+ }
4900
+
4901
+ return this.config.sdpMunging;
4902
+ }
4903
+
4782
4904
  createLocalOffer() {
4905
+ var sdpMungingConfig = this.createSdpMungingConfig();
4783
4906
  return this.pc.createOffer().then(description => {
4784
4907
  this.log('createLocalOffer', 'local SDP offer created');
4785
4908
  var mungedDescription = {
4786
4909
  type: description.type,
4787
- sdp: mungeLocalSdpForBrowser(this.config.sdpMunging, (description === null || description === void 0 ? void 0 : description.sdp) || '')
4910
+ sdp: mungeLocalSdpForBrowser(sdpMungingConfig, (description === null || description === void 0 ? void 0 : description.sdp) || '')
4788
4911
  };
4789
4912
  return this.pc.setLocalDescription(mungedDescription);
4790
4913
  }).then(() => this.waitForIceCandidates()).then(() => {
4791
4914
  var _this$pc$localDescrip;
4792
4915
 
4793
- var mungedSdp = mungeLocalSdp(this.config.sdpMunging, ((_this$pc$localDescrip = this.pc.localDescription) === null || _this$pc$localDescrip === void 0 ? void 0 : _this$pc$localDescrip.sdp) || '');
4916
+ var mungedSdp = mungeLocalSdp(sdpMungingConfig, ((_this$pc$localDescrip = this.pc.localDescription) === null || _this$pc$localDescrip === void 0 ? void 0 : _this$pc$localDescrip.sdp) || '');
4794
4917
  return {
4795
4918
  sdp: mungedSdp
4796
4919
  };
@@ -4805,19 +4928,20 @@ class MediaConnection$1 extends EventEmitter {
4805
4928
  }
4806
4929
 
4807
4930
  var mungedRemoteSdp = mungeRemoteSdp(this.config.sdpMunging, sdp);
4931
+ var sdpMungingConfig = this.createSdpMungingConfig();
4808
4932
  return this.pc.setRemoteDescription(new window.RTCSessionDescription({
4809
4933
  type: 'offer',
4810
4934
  sdp: mungedRemoteSdp
4811
4935
  })).then(() => this.pc.createAnswer()).then(answer => {
4812
4936
  var mungedAnswer = {
4813
4937
  type: answer.type,
4814
- sdp: mungeLocalSdpForBrowser(this.config.sdpMunging, (answer === null || answer === void 0 ? void 0 : answer.sdp) || '')
4938
+ sdp: mungeLocalSdpForBrowser(sdpMungingConfig, (answer === null || answer === void 0 ? void 0 : answer.sdp) || '')
4815
4939
  };
4816
4940
  return this.pc.setLocalDescription(mungedAnswer);
4817
4941
  }).then(() => this.waitForIceCandidates()).then(() => {
4818
4942
  var _this$pc$localDescrip2;
4819
4943
 
4820
- var mungedLocalSdp = mungeLocalSdp(this.config.sdpMunging, ((_this$pc$localDescrip2 = this.pc.localDescription) === null || _this$pc$localDescrip2 === void 0 ? void 0 : _this$pc$localDescrip2.sdp) || '');
4944
+ var mungedLocalSdp = mungeLocalSdp(sdpMungingConfig, ((_this$pc$localDescrip2 = this.pc.localDescription) === null || _this$pc$localDescrip2 === void 0 ? void 0 : _this$pc$localDescrip2.sdp) || '');
4821
4945
  return {
4822
4946
  sdp: mungedLocalSdp
4823
4947
  };
@@ -5085,7 +5209,7 @@ function detectBrowser(window) {
5085
5209
  // Firefox.
5086
5210
  result.browser = 'firefox';
5087
5211
  result.version = extractVersion(navigator.userAgent, /Firefox\/(\d+)\./, 1);
5088
- } else if (navigator.webkitGetUserMedia || window.isSecureContext === false && window.webkitRTCPeerConnection && !window.RTCIceGatherer) {
5212
+ } else if (navigator.webkitGetUserMedia || window.isSecureContext === false && window.webkitRTCPeerConnection) {
5089
5213
  // Chrome, Chromium, Webview, Opera.
5090
5214
  // Version matches Chrome/WebRTC version.
5091
5215
  // Chrome 74 removed webkitGetUserMedia on http as well so we need the
@@ -6445,13 +6569,20 @@ function shimAddTransceiver(window) {
6445
6569
 
6446
6570
  if (origAddTransceiver) {
6447
6571
  window.RTCPeerConnection.prototype.addTransceiver = function addTransceiver() {
6448
- this.setParametersPromises = [];
6449
- var initParameters = arguments[1];
6450
- var shouldPerformCheck = initParameters && 'sendEncodings' in initParameters;
6572
+ this.setParametersPromises = []; // WebIDL input coercion and validation
6573
+
6574
+ var sendEncodings = arguments[1] && arguments[1].sendEncodings;
6575
+
6576
+ if (sendEncodings === undefined) {
6577
+ sendEncodings = [];
6578
+ }
6579
+
6580
+ sendEncodings = [...sendEncodings];
6581
+ var shouldPerformCheck = sendEncodings.length > 0;
6451
6582
 
6452
6583
  if (shouldPerformCheck) {
6453
6584
  // If sendEncodings params are provided, validate grammar
6454
- initParameters.sendEncodings.forEach(encodingParam => {
6585
+ sendEncodings.forEach(encodingParam => {
6455
6586
  if ('rid' in encodingParam) {
6456
6587
  var ridRegex = /^[a-z0-9]{0,16}$/i;
6457
6588
 
@@ -6491,8 +6622,8 @@ function shimAddTransceiver(window) {
6491
6622
 
6492
6623
  if (!('encodings' in params) || // Avoid being fooled by patched getParameters() below.
6493
6624
  params.encodings.length === 1 && Object.keys(params.encodings[0]).length === 0) {
6494
- params.encodings = initParameters.sendEncodings;
6495
- sender.sendEncodings = initParameters.sendEncodings;
6625
+ params.encodings = sendEncodings;
6626
+ sender.sendEncodings = sendEncodings;
6496
6627
  this.setParametersPromises.push(sender.setParameters(params).then(() => {
6497
6628
  delete sender.sendEncodings;
6498
6629
  }).catch(() => {
@@ -9444,20 +9575,52 @@ function error(id, data) {
9444
9575
  return eventObject;
9445
9576
  }
9446
9577
 
9447
- function resolveActions(machine, currentState, currentContext, _event, actions, predictableExec, preserveActionOrder) {
9578
+ var pluckAssigns = function pluckAssigns(actionBlocks) {
9579
+ var e_1, _a;
9580
+
9581
+ var assignActions = [];
9582
+
9583
+ try {
9584
+ for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
9585
+ var block = actionBlocks_1_1.value;
9586
+ var i = 0;
9587
+
9588
+ while (i < block.length) {
9589
+ if (block[i].type === assign$2) {
9590
+ assignActions.push(block[i]);
9591
+ block.splice(i, 1);
9592
+ continue;
9593
+ }
9594
+
9595
+ i++;
9596
+ }
9597
+ }
9598
+ } catch (e_1_1) {
9599
+ e_1 = {
9600
+ error: e_1_1
9601
+ };
9602
+ } finally {
9603
+ try {
9604
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
9605
+ } finally {
9606
+ if (e_1) throw e_1.error;
9607
+ }
9608
+ }
9609
+
9610
+ return assignActions;
9611
+ };
9612
+
9613
+ function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
9448
9614
  if (preserveActionOrder === void 0) {
9449
9615
  preserveActionOrder = false;
9450
9616
  }
9451
9617
 
9452
- var _a = __read(preserveActionOrder ? [[], actions] : partition(actions, function (action) {
9453
- return action.type === assign$2;
9454
- }), 2),
9455
- assignActions = _a[0],
9456
- otherActions = _a[1];
9457
-
9618
+ var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
9458
9619
  var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
9459
9620
  var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
9460
- var resolvedActions = flatten(otherActions.map(function (actionObject) {
9621
+ var deferredToBlockEnd = [];
9622
+
9623
+ function handleAction(actionObject) {
9461
9624
  var _a;
9462
9625
 
9463
9626
  switch (actionObject.type) {
@@ -9475,8 +9638,8 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9475
9638
  "No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
9476
9639
  }
9477
9640
 
9478
- if (sendAction.to !== SpecialTargets.Internal) {
9479
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
9641
+ if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
9642
+ deferredToBlockEnd.push(sendAction);
9480
9643
  }
9481
9644
 
9482
9645
  return sendAction;
@@ -9500,7 +9663,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9500
9663
  return [];
9501
9664
  }
9502
9665
 
9503
- var _b = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
9666
+ var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
9504
9667
  resolvedActionsFromChoose = _b[0],
9505
9668
  resolvedContextFromChoose = _b[1];
9506
9669
 
@@ -9517,7 +9680,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9517
9680
  return [];
9518
9681
  }
9519
9682
 
9520
- var _c = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
9683
+ var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
9521
9684
  resolvedActionsFromPure = _c[0],
9522
9685
  resolvedContext = _c[1];
9523
9686
 
@@ -9529,7 +9692,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9529
9692
  case stop$1:
9530
9693
  {
9531
9694
  var resolved = resolveStop(actionObject, updatedContext, _event);
9532
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
9695
+ predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
9533
9696
  return resolved;
9534
9697
  }
9535
9698
 
@@ -9563,9 +9726,42 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
9563
9726
 
9564
9727
  return resolvedActionObject;
9565
9728
  }
9566
- }).filter(function (a) {
9567
- return !!a;
9568
- }));
9729
+ }
9730
+
9731
+ function processBlock(block) {
9732
+ var e_2, _a;
9733
+
9734
+ var resolvedActions = [];
9735
+
9736
+ try {
9737
+ for (var block_1 = __values(block), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
9738
+ var action = block_1_1.value;
9739
+ var resolved = handleAction(action);
9740
+
9741
+ if (resolved) {
9742
+ resolvedActions = resolvedActions.concat(resolved);
9743
+ }
9744
+ }
9745
+ } catch (e_2_1) {
9746
+ e_2 = {
9747
+ error: e_2_1
9748
+ };
9749
+ } finally {
9750
+ try {
9751
+ if (block_1_1 && !block_1_1.done && (_a = block_1.return)) _a.call(block_1);
9752
+ } finally {
9753
+ if (e_2) throw e_2.error;
9754
+ }
9755
+ }
9756
+
9757
+ deferredToBlockEnd.forEach(function (action) {
9758
+ predictableExec(action, updatedContext, _event);
9759
+ });
9760
+ deferredToBlockEnd.length = 0;
9761
+ return resolvedActions;
9762
+ }
9763
+
9764
+ var resolvedActions = flatten(actionBlocks.map(processBlock));
9569
9765
  return [resolvedActions, updatedContext];
9570
9766
  }
9571
9767
 
@@ -10431,12 +10627,12 @@ function () {
10431
10627
  * @param options Interpreter options
10432
10628
  */
10433
10629
  function Interpreter(machine, options) {
10434
- var _this = this;
10435
-
10436
10630
  if (options === void 0) {
10437
10631
  options = Interpreter.defaultOptions;
10438
10632
  }
10439
10633
 
10634
+ var _this = this;
10635
+
10440
10636
  this.machine = machine;
10441
10637
  this.delayedEventsMap = {};
10442
10638
  this.listeners = new Set();
@@ -10453,6 +10649,7 @@ function () {
10453
10649
  this.status = InterpreterStatus.NotStarted;
10454
10650
  this.children = new Map();
10455
10651
  this.forwardTo = new Set();
10652
+ this._outgoingQueue = [];
10456
10653
  /**
10457
10654
  * Alias for Interpreter.prototype.start
10458
10655
  */
@@ -10495,7 +10692,7 @@ function () {
10495
10692
  // Forward copy of event to child actors
10496
10693
  _this.forward(_event);
10497
10694
 
10498
- var nextState = _this.nextState(_event);
10695
+ var nextState = _this._nextState(_event);
10499
10696
 
10500
10697
  _this.update(nextState, _event);
10501
10698
  });
@@ -10504,7 +10701,7 @@ function () {
10504
10701
  // tslint:disable-next-line:semicolon
10505
10702
  };
10506
10703
 
10507
- this.sendTo = function (event, to) {
10704
+ this.sendTo = function (event, to, immediate) {
10508
10705
  var isParent = _this.parent && (to === SpecialTargets.Parent || _this.parent.id === to);
10509
10706
  var target = isParent ? _this.parent : isString(to) ? _this.children.get(to) || registry.get(to) : isActor$1(to) ? to : undefined;
10510
10707
 
@@ -10527,14 +10724,24 @@ function () {
10527
10724
  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
10528
10725
  _this.state.done) {
10529
10726
  // Send SCXML events to machines
10530
- target.send(_assign(_assign({}, event), {
10727
+ var scxmlEvent = _assign(_assign({}, event), {
10531
10728
  name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
10532
10729
  origin: _this.sessionId
10533
- }));
10730
+ });
10731
+
10732
+ if (!immediate && _this.machine.config.predictableActionArguments) {
10733
+ _this._outgoingQueue.push([target, scxmlEvent]);
10734
+ } else {
10735
+ target.send(scxmlEvent);
10736
+ }
10534
10737
  }
10535
10738
  } else {
10536
10739
  // Send normal events to other targets
10537
- target.send(event.data);
10740
+ if (!immediate && _this.machine.config.predictableActionArguments) {
10741
+ _this._outgoingQueue.push([target, event.data]);
10742
+ } else {
10743
+ target.send(event.data);
10744
+ }
10538
10745
  }
10539
10746
  };
10540
10747
 
@@ -10578,7 +10785,7 @@ function () {
10578
10785
  return;
10579
10786
  } else {
10580
10787
  if (sendAction.to) {
10581
- _this.sendTo(sendAction._event, sendAction.to);
10788
+ _this.sendTo(sendAction._event, sendAction.to, _event === initEvent);
10582
10789
  } else {
10583
10790
  _this.send(sendAction._event);
10584
10791
  }
@@ -10727,6 +10934,9 @@ function () {
10727
10934
  configurable: true
10728
10935
  });
10729
10936
  Object.defineProperty(Interpreter.prototype, "state", {
10937
+ /**
10938
+ * @deprecated Use `.getSnapshot()` instead.
10939
+ */
10730
10940
  get: function get() {
10731
10941
  if (!IS_PRODUCTION) {
10732
10942
  warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
@@ -10779,6 +10989,12 @@ function () {
10779
10989
  // we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
10780
10990
  _event === initEvent) && this.options.execute) {
10781
10991
  this.execute(this.state);
10992
+ } else {
10993
+ var item = void 0;
10994
+
10995
+ while (item = this._outgoingQueue.shift()) {
10996
+ item[0].send(item[1]);
10997
+ }
10782
10998
  } // Update children
10783
10999
 
10784
11000
 
@@ -10869,6 +11085,8 @@ function () {
10869
11085
  }
10870
11086
 
10871
11087
  this._stop();
11088
+
11089
+ this._stopChildren();
10872
11090
  }
10873
11091
  };
10874
11092
  /*
@@ -11027,6 +11245,16 @@ function () {
11027
11245
  return this;
11028
11246
  };
11029
11247
 
11248
+ Interpreter.prototype._stopChildren = function () {
11249
+ // TODO: think about converting those to actions
11250
+ this.children.forEach(function (child) {
11251
+ if (isFunction(child.stop)) {
11252
+ child.stop();
11253
+ }
11254
+ });
11255
+ this.children.clear();
11256
+ };
11257
+
11030
11258
  Interpreter.prototype._stop = function () {
11031
11259
  var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
11032
11260
 
@@ -11164,7 +11392,7 @@ function () {
11164
11392
  return toActionObjects(stateNode.onExit, _this.machine.options.actions);
11165
11393
  }));
11166
11394
 
11167
- 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),
11395
+ 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),
11168
11396
  resolvedActions = _a[0],
11169
11397
  updatedContext = _a[1];
11170
11398
 
@@ -11191,17 +11419,9 @@ function () {
11191
11419
  return newState;
11192
11420
  });
11193
11421
 
11194
- _this.update(nextState, _event); // TODO: think about converting those to actions
11195
- // Stop all children
11422
+ _this.update(nextState, _event);
11196
11423
 
11197
-
11198
- _this.children.forEach(function (child) {
11199
- if (isFunction(child.stop)) {
11200
- child.stop();
11201
- }
11202
- });
11203
-
11204
- _this.children.clear();
11424
+ _this._stopChildren();
11205
11425
 
11206
11426
  registry.free(_this.sessionId);
11207
11427
  });
@@ -11221,6 +11441,11 @@ function () {
11221
11441
  "".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."));
11222
11442
  }
11223
11443
 
11444
+ if (!events.length) {
11445
+ return;
11446
+ }
11447
+
11448
+ var exec = !!this.machine.config.predictableActionArguments && this._exec;
11224
11449
  this.scheduler.schedule(function () {
11225
11450
  var e_11, _a;
11226
11451
 
@@ -11234,9 +11459,9 @@ function () {
11234
11459
  _this.forward(_event);
11235
11460
 
11236
11461
  nextState = provide(_this, function () {
11237
- return _this.machine.transition(nextState, _event);
11462
+ return _this.machine.transition(nextState, _event, undefined, exec || undefined);
11238
11463
  });
11239
- batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
11464
+ batchedActions.push.apply(batchedActions, __spreadArray([], __read(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
11240
11465
  return bindActionToState(a, nextState);
11241
11466
  })), false));
11242
11467
  batchChanged = batchChanged || !!nextState.changed;
@@ -11277,9 +11502,13 @@ function () {
11277
11502
  return this.send.bind(this, event);
11278
11503
  };
11279
11504
 
11280
- Interpreter.prototype._nextState = function (event) {
11505
+ Interpreter.prototype._nextState = function (event, exec) {
11281
11506
  var _this = this;
11282
11507
 
11508
+ if (exec === void 0) {
11509
+ exec = !!this.machine.config.predictableActionArguments && this._exec;
11510
+ }
11511
+
11283
11512
  var _event = toSCXMLEvent(event);
11284
11513
 
11285
11514
  if (_event.name.indexOf(errorPlatform) === 0 && !this.state.nextEvents.some(function (nextEvent) {
@@ -11289,7 +11518,7 @@ function () {
11289
11518
  }
11290
11519
 
11291
11520
  var nextState = provide(this, function () {
11292
- return _this.machine.transition(_this.state, _event, undefined, _this.machine.config.predictableActionArguments ? _this._exec : undefined);
11521
+ return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
11293
11522
  });
11294
11523
  return nextState;
11295
11524
  };
@@ -11303,7 +11532,7 @@ function () {
11303
11532
 
11304
11533
 
11305
11534
  Interpreter.prototype.nextState = function (event) {
11306
- return this._nextState(event);
11535
+ return this._nextState(event, false);
11307
11536
  };
11308
11537
 
11309
11538
  Interpreter.prototype.forward = function (event) {
@@ -11338,7 +11567,7 @@ function () {
11338
11567
 
11339
11568
  this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
11340
11569
  if (sendAction.to) {
11341
- _this.sendTo(sendAction._event, sendAction.to);
11570
+ _this.sendTo(sendAction._event, sendAction.to, true);
11342
11571
  } else {
11343
11572
  _this.send(sendAction._event);
11344
11573
  }
@@ -11914,12 +12143,12 @@ function () {
11914
12143
  */
11915
12144
  _context, // TODO: this is unsafe, but we're removing it in v5 anyway
11916
12145
  _stateInfo) {
11917
- var _this = this;
11918
-
11919
12146
  if (_context === void 0) {
11920
12147
  _context = 'context' in config ? config.context : undefined;
11921
12148
  }
11922
12149
 
12150
+ var _this = this;
12151
+
11923
12152
  var _a;
11924
12153
 
11925
12154
  this.config = config;
@@ -12529,9 +12758,11 @@ function () {
12529
12758
  return nodes;
12530
12759
  };
12531
12760
 
12532
- StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState) {
12761
+ StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
12533
12762
  var e_4, _a, e_5, _b;
12534
12763
 
12764
+ var _this = this;
12765
+
12535
12766
  var prevConfig = getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
12536
12767
 
12537
12768
  try {
@@ -12609,20 +12840,19 @@ function () {
12609
12840
  });
12610
12841
  var entryStates = new Set(transition.entrySet);
12611
12842
  var exitStates = new Set(transition.exitSet);
12612
-
12613
- var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
12614
- return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) {
12843
+ var entryActions = Array.from(entryStates).map(function (stateNode) {
12844
+ var entryActions = stateNode.onEntry;
12845
+ var invokeActions = stateNode.activities.map(function (activity) {
12615
12846
  return start(activity);
12616
- })), false), __read(stateNode.onEntry), false);
12617
- })).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
12618
- return __spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
12847
+ });
12848
+ return toActionObjects(predictableExec ? __spreadArray(__spreadArray([], __read(entryActions), false), __read(invokeActions), false) : __spreadArray(__spreadArray([], __read(invokeActions), false), __read(entryActions), false), _this.machine.options.actions);
12849
+ }).concat([doneEvents.map(raise)]);
12850
+ var exitActions = Array.from(exitStates).map(function (stateNode) {
12851
+ return toActionObjects(__spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
12619
12852
  return stop(activity);
12620
- })), false);
12621
- }))], 2),
12622
- entryActions = _c[0],
12623
- exitActions = _c[1];
12624
-
12625
- var actions = toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
12853
+ })), false), _this.machine.options.actions);
12854
+ });
12855
+ var actions = exitActions.concat([toActionObjects(transition.actions, this.machine.options.actions)]).concat(entryActions);
12626
12856
 
12627
12857
  if (isDone) {
12628
12858
  var stopActions = toActionObjects(flatten(__spreadArray([], __read(resolvedConfig), false).sort(function (a, b) {
@@ -12632,7 +12862,7 @@ function () {
12632
12862
  })), this.machine.options.actions).filter(function (action) {
12633
12863
  return action.type !== raise$1 && (action.type !== send$1 || !!action.to && action.to !== SpecialTargets.Internal);
12634
12864
  });
12635
- return actions.concat(stopActions);
12865
+ return actions.concat([stopActions]);
12636
12866
  }
12637
12867
 
12638
12868
  return actions;
@@ -12703,7 +12933,7 @@ function () {
12703
12933
  };
12704
12934
 
12705
12935
  StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
12706
- var e_6, _a;
12936
+ var e_6, _a, e_7, _b;
12707
12937
 
12708
12938
  var _this = this;
12709
12939
 
@@ -12720,17 +12950,33 @@ function () {
12720
12950
  var isDone = isInFinalState(resolvedConfiguration, this);
12721
12951
  var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
12722
12952
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
12723
- var actions = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState);
12953
+ var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
12724
12954
  var activities = currentState ? _assign({}, currentState.activities) : {};
12725
12955
 
12726
12956
  try {
12727
- for (var actions_1 = __values(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
12728
- var action = actions_1_1.value;
12957
+ for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
12958
+ var block = actionBlocks_1_1.value;
12959
+
12960
+ try {
12961
+ 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()) {
12962
+ var action = block_1_1.value;
12729
12963
 
12730
- if (action.type === start$1) {
12731
- activities[action.activity.id || action.activity.type] = action;
12732
- } else if (action.type === stop$1) {
12733
- activities[action.activity.id || action.activity.type] = false;
12964
+ if (action.type === start$1) {
12965
+ activities[action.activity.id || action.activity.type] = action;
12966
+ } else if (action.type === stop$1) {
12967
+ activities[action.activity.id || action.activity.type] = false;
12968
+ }
12969
+ }
12970
+ } catch (e_7_1) {
12971
+ e_7 = {
12972
+ error: e_7_1
12973
+ };
12974
+ } finally {
12975
+ try {
12976
+ if (block_1_1 && !block_1_1.done && (_b = block_1.return)) _b.call(block_1);
12977
+ } finally {
12978
+ if (e_7) throw e_7.error;
12979
+ }
12734
12980
  }
12735
12981
  }
12736
12982
  } catch (e_6_1) {
@@ -12739,21 +12985,21 @@ function () {
12739
12985
  };
12740
12986
  } finally {
12741
12987
  try {
12742
- if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
12988
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
12743
12989
  } finally {
12744
12990
  if (e_6) throw e_6.error;
12745
12991
  }
12746
12992
  }
12747
12993
 
12748
- var _b = __read(resolveActions(this, currentState, context, _event, actions, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
12749
- resolvedActions = _b[0],
12750
- updatedContext = _b[1];
12994
+ var _c = __read(resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
12995
+ resolvedActions = _c[0],
12996
+ updatedContext = _c[1];
12751
12997
 
12752
- var _c = __read(partition(resolvedActions, function (action) {
12998
+ var _d = __read(partition(resolvedActions, function (action) {
12753
12999
  return action.type === raise$1 || action.type === send$1 && action.to === SpecialTargets.Internal;
12754
13000
  }), 2),
12755
- raisedEvents = _c[0],
12756
- nonRaisedActions = _c[1];
13001
+ raisedEvents = _d[0],
13002
+ nonRaisedActions = _d[1];
12757
13003
 
12758
13004
  var invokeActions = resolvedActions.filter(function (action) {
12759
13005
  var _a;
@@ -13202,7 +13448,7 @@ function () {
13202
13448
  * All the event types accepted by this state node and its descendants.
13203
13449
  */
13204
13450
  get: function get() {
13205
- var e_7, _a, e_8, _b;
13451
+ var e_8, _a, e_9, _b;
13206
13452
 
13207
13453
  if (this.__cache.events) {
13208
13454
  return this.__cache.events;
@@ -13219,32 +13465,32 @@ function () {
13219
13465
 
13220
13466
  if (state.states) {
13221
13467
  try {
13222
- for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
13468
+ for (var _e = (e_9 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
13223
13469
  var event_1 = _f.value;
13224
13470
  events.add("".concat(event_1));
13225
13471
  }
13226
- } catch (e_8_1) {
13227
- e_8 = {
13228
- error: e_8_1
13472
+ } catch (e_9_1) {
13473
+ e_9 = {
13474
+ error: e_9_1
13229
13475
  };
13230
13476
  } finally {
13231
13477
  try {
13232
13478
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
13233
13479
  } finally {
13234
- if (e_8) throw e_8.error;
13480
+ if (e_9) throw e_9.error;
13235
13481
  }
13236
13482
  }
13237
13483
  }
13238
13484
  }
13239
- } catch (e_7_1) {
13240
- e_7 = {
13241
- error: e_7_1
13485
+ } catch (e_8_1) {
13486
+ e_8 = {
13487
+ error: e_8_1
13242
13488
  };
13243
13489
  } finally {
13244
13490
  try {
13245
13491
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
13246
13492
  } finally {
13247
- if (e_7) throw e_7.error;
13493
+ if (e_8) throw e_8.error;
13248
13494
  }
13249
13495
  }
13250
13496
  }
@@ -13339,7 +13585,7 @@ function () {
13339
13585
  };
13340
13586
 
13341
13587
  StateNode.prototype.formatTransitions = function () {
13342
- var e_9, _a;
13588
+ var e_10, _a;
13343
13589
 
13344
13590
  var _this = this;
13345
13591
 
@@ -13403,15 +13649,15 @@ function () {
13403
13649
  var delayedTransition = delayedTransitions_1_1.value;
13404
13650
  formattedTransitions.push(delayedTransition);
13405
13651
  }
13406
- } catch (e_9_1) {
13407
- e_9 = {
13408
- error: e_9_1
13652
+ } catch (e_10_1) {
13653
+ e_10 = {
13654
+ error: e_10_1
13409
13655
  };
13410
13656
  } finally {
13411
13657
  try {
13412
13658
  if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
13413
13659
  } finally {
13414
- if (e_9) throw e_9.error;
13660
+ if (e_10) throw e_10.error;
13415
13661
  }
13416
13662
  }
13417
13663