@webex/internal-media-core 0.0.12-beta → 0.0.13-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
@@ -2430,7 +2430,8 @@ var getErrorDescription = error => {
2430
2430
  };
2431
2431
 
2432
2432
  var NUM$1 = '\\d+';
2433
- var TOKEN$1 = '\\S+';
2433
+ var SDP_TOKEN = "[!#$%&'*+\\-.^_`{|}~a-zA-Z0-9]+";
2434
+ var ANY_NON_WS = '\\S+';
2434
2435
  var SP$1 = '\\s';
2435
2436
  var REST$1 = '.+';
2436
2437
  class Line$1 {}
@@ -2524,7 +2525,7 @@ class CandidateLine$1 extends Line$1 {
2524
2525
  }
2525
2526
  _a$4$1 = CandidateLine$1;
2526
2527
  CandidateLine$1.ICE_CHARS = "[a-zA-Z0-9+/]+";
2527
- CandidateLine$1.regex = new RegExp("^candidate:(".concat(_a$4$1.ICE_CHARS, ") (").concat(NUM$1, ") (").concat(TOKEN$1, ") (").concat(NUM$1, ") (").concat(TOKEN$1, ") (").concat(NUM$1, ") typ (").concat(TOKEN$1, ")(?: raddr (").concat(TOKEN$1, "))?(?: rport (").concat(NUM$1, "))?(?: (").concat(REST$1, "))?"));
2528
+ CandidateLine$1.regex = new RegExp("^candidate:(".concat(_a$4$1.ICE_CHARS, ") (").concat(NUM$1, ") (").concat(ANY_NON_WS, ") (").concat(NUM$1, ") (").concat(ANY_NON_WS, ") (").concat(NUM$1, ") typ (").concat(ANY_NON_WS, ")(?: raddr (").concat(ANY_NON_WS, "))?(?: rport (").concat(NUM$1, "))?(?: (").concat(REST$1, "))?"));
2528
2529
  class ConnectionLine$1 extends Line$1 {
2529
2530
  constructor(netType, addrType, ipAddr) {
2530
2531
  super();
@@ -2546,7 +2547,7 @@ class ConnectionLine$1 extends Line$1 {
2546
2547
  return "c=".concat(this.netType, " ").concat(this.addrType, " ").concat(this.ipAddr);
2547
2548
  }
2548
2549
  }
2549
- ConnectionLine$1.regex = new RegExp("^(".concat(TOKEN$1, ") (").concat(TOKEN$1, ") (").concat(TOKEN$1, ")"));
2550
+ ConnectionLine$1.regex = new RegExp("^(".concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ")"));
2550
2551
  class ContentLine$1 extends Line$1 {
2551
2552
  constructor(values) {
2552
2553
  super();
@@ -2618,7 +2619,7 @@ class ExtMapLine$1 extends Line$1 {
2618
2619
  }
2619
2620
  _a$3$1 = ExtMapLine$1;
2620
2621
  ExtMapLine$1.EXTMAP_DIRECTION = "sendonly|recvonly|sendrecv|inactive";
2621
- ExtMapLine$1.regex = new RegExp("^extmap:(".concat(NUM$1, ")(?:/(").concat(_a$3$1.EXTMAP_DIRECTION, "))? (").concat(TOKEN$1, ")(?: (").concat(REST$1, "))?"));
2622
+ ExtMapLine$1.regex = new RegExp("^extmap:(".concat(NUM$1, ")(?:/(").concat(_a$3$1.EXTMAP_DIRECTION, "))? (").concat(ANY_NON_WS, ")(?: (").concat(REST$1, "))?"));
2622
2623
  class FingerprintLine$1 extends Line$1 {
2623
2624
  constructor(fingerprint) {
2624
2625
  super();
@@ -2692,7 +2693,7 @@ class IcePwdLine$1 extends Line$1 {
2692
2693
  return "a=ice-pwd:".concat(this.pwd);
2693
2694
  }
2694
2695
  }
2695
- IcePwdLine$1.regex = new RegExp("^ice-pwd:(".concat(TOKEN$1, ")$"));
2696
+ IcePwdLine$1.regex = new RegExp("^ice-pwd:(".concat(ANY_NON_WS, ")$"));
2696
2697
  class IceUfragLine$1 extends Line$1 {
2697
2698
  constructor(ufrag) {
2698
2699
  super();
@@ -2710,7 +2711,7 @@ class IceUfragLine$1 extends Line$1 {
2710
2711
  return "a=ice-ufrag:".concat(this.ufrag);
2711
2712
  }
2712
2713
  }
2713
- IceUfragLine$1.regex = new RegExp("^ice-ufrag:(".concat(TOKEN$1, ")$"));
2714
+ IceUfragLine$1.regex = new RegExp("^ice-ufrag:(".concat(ANY_NON_WS, ")$"));
2714
2715
  class MaxMessageSizeLine$1 extends Line$1 {
2715
2716
  constructor(maxMessageSize) {
2716
2717
  super();
@@ -2755,7 +2756,7 @@ class MediaLine$1 extends Line$1 {
2755
2756
  }
2756
2757
  _a$2$1 = MediaLine$1;
2757
2758
  MediaLine$1.MEDIA_TYPE = 'audio|video|application';
2758
- MediaLine$1.regex = new RegExp("^(".concat(_a$2$1.MEDIA_TYPE, ") (").concat(NUM$1, ") (").concat(TOKEN$1, ") (").concat(REST$1, ")"));
2759
+ MediaLine$1.regex = new RegExp("^(".concat(_a$2$1.MEDIA_TYPE, ") (").concat(NUM$1, ") (").concat(ANY_NON_WS, ") (").concat(REST$1, ")"));
2759
2760
  class MidLine$1 extends Line$1 {
2760
2761
  constructor(mid) {
2761
2762
  super();
@@ -2773,7 +2774,7 @@ class MidLine$1 extends Line$1 {
2773
2774
  return "a=mid:".concat(this.mid);
2774
2775
  }
2775
2776
  }
2776
- MidLine$1.regex = new RegExp("^mid:(".concat(TOKEN$1, ")$"));
2777
+ MidLine$1.regex = new RegExp("^mid:(".concat(ANY_NON_WS, ")$"));
2777
2778
  class OriginLine$1 extends Line$1 {
2778
2779
  constructor(username, sessionId, sessionVersion, netType, addrType, ipAddr) {
2779
2780
  super();
@@ -2801,7 +2802,7 @@ class OriginLine$1 extends Line$1 {
2801
2802
  return "o=".concat(this.username, " ").concat(this.sessionId, " ").concat(this.sessionVersion, " ").concat(this.netType, " ").concat(this.addrType, " ").concat(this.ipAddr);
2802
2803
  }
2803
2804
  }
2804
- OriginLine$1.regex = new RegExp("^(".concat(TOKEN$1, ") (").concat(TOKEN$1, ") (").concat(NUM$1, ") (").concat(TOKEN$1, ") (").concat(TOKEN$1, ") (").concat(TOKEN$1, ")"));
2805
+ OriginLine$1.regex = new RegExp("^(".concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ") (").concat(NUM$1, ") (").concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ")"));
2805
2806
  var _a$1$1;
2806
2807
  class RidLine$1 extends Line$1 {
2807
2808
  constructor(id, direction, params) {
@@ -3069,7 +3070,60 @@ class SimulcastLine$1 extends Line$1 {
3069
3070
  return str;
3070
3071
  }
3071
3072
  }
3072
- SimulcastLine$1.regex = new RegExp("^simulcast:(send|recv) (".concat(TOKEN$1, ")(?: (send|recv) (").concat(TOKEN$1, "))?"));
3073
+ SimulcastLine$1.regex = new RegExp("^simulcast:(send|recv) (".concat(ANY_NON_WS, ")(?: (send|recv) (").concat(ANY_NON_WS, "))?"));
3074
+ class SsrcLine extends Line$1 {
3075
+ constructor(ssrcId, attribute) {
3076
+ var attributeValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
3077
+ var attributeData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
3078
+ super();
3079
+ this.ssrcId = ssrcId;
3080
+ this.attribute = attribute;
3081
+ this.attributeValue = attributeValue;
3082
+ this.attributeData = attributeData;
3083
+ }
3084
+ static fromSdpLine(line) {
3085
+ if (!SsrcLine.regex.test(line)) {
3086
+ return undefined;
3087
+ }
3088
+ var tokens = line.match(SsrcLine.regex);
3089
+ var ssrcId = parseInt(tokens[1], 10);
3090
+ var attribute = tokens[2];
3091
+ var attributeValue = tokens[3];
3092
+ var attributeData = tokens[4];
3093
+ return new SsrcLine(ssrcId, attribute, attributeValue, attributeData);
3094
+ }
3095
+ toSdpLine() {
3096
+ var str = "a=ssrc:".concat(this.ssrcId, " ").concat(this.attribute);
3097
+ if (this.attributeValue) {
3098
+ str += ":".concat(this.attributeValue);
3099
+ }
3100
+ if (this.attributeData) {
3101
+ str += " ".concat(this.attributeData);
3102
+ }
3103
+ return str;
3104
+ }
3105
+ }
3106
+ SsrcLine.regex = new RegExp("^ssrc:(".concat(NUM$1, ") (").concat(SDP_TOKEN, ")(?::(").concat(SDP_TOKEN, ")?(?: (").concat(ANY_NON_WS, "))?)?$"));
3107
+ class SsrcGroupLine extends Line$1 {
3108
+ constructor(semantics, ssrcs) {
3109
+ super();
3110
+ this.semantics = semantics;
3111
+ this.ssrcs = ssrcs;
3112
+ }
3113
+ static fromSdpLine(line) {
3114
+ if (!SsrcGroupLine.regex.test(line)) {
3115
+ return undefined;
3116
+ }
3117
+ var tokens = line.match(SsrcGroupLine.regex);
3118
+ var semantics = tokens[1];
3119
+ var ssrcs = tokens[2].split(' ').map(ssrcStr => parseInt(ssrcStr, 10));
3120
+ return new SsrcGroupLine(semantics, ssrcs);
3121
+ }
3122
+ toSdpLine() {
3123
+ return "a=ssrc-group:".concat(this.semantics, " ").concat(this.ssrcs.join(' '));
3124
+ }
3125
+ }
3126
+ SsrcGroupLine.regex = new RegExp("^ssrc-group:(SIM|FID|FEC) ((?:".concat(NUM$1).concat(SP$1, "*)+)"));
3073
3127
  class TimingLine$1 extends Line$1 {
3074
3128
  constructor(startTime, stopTime) {
3075
3129
  super();
@@ -3306,6 +3360,8 @@ class AvMediaDescription$1 extends MediaDescription$1 {
3306
3360
  this.rids = [];
3307
3361
  this.codecs = new Map();
3308
3362
  this.rtcpMux = false;
3363
+ this.ssrcs = [];
3364
+ this.ssrcGroups = [];
3309
3365
  this.pts = mediaLine.formats.map(fmt => {
3310
3366
  return parseInt(fmt, 10);
3311
3367
  });
@@ -3345,6 +3401,8 @@ class AvMediaDescription$1 extends MediaDescription$1 {
3345
3401
  lines.push(new DirectionLine$1(this.direction));
3346
3402
  }
3347
3403
  this.codecs.forEach(codec => lines.push(...codec.toLines()));
3404
+ lines.push(...this.ssrcs);
3405
+ lines.push(...this.ssrcGroups);
3348
3406
  lines.push(...this.otherLines);
3349
3407
  return lines;
3350
3408
  }
@@ -3383,6 +3441,14 @@ class AvMediaDescription$1 extends MediaDescription$1 {
3383
3441
  codec.addLine(line);
3384
3442
  return true;
3385
3443
  }
3444
+ if (line instanceof SsrcLine) {
3445
+ this.ssrcs.push(line);
3446
+ return true;
3447
+ }
3448
+ if (line instanceof SsrcGroupLine) {
3449
+ this.ssrcGroups.push(line);
3450
+ return true;
3451
+ }
3386
3452
  this.otherLines.push(line);
3387
3453
  return true;
3388
3454
  }
@@ -3527,6 +3593,8 @@ class SdpGrammar$1 extends Grammar$1 {
3527
3593
  this.addParser('a', RidLine$1.fromSdpLine);
3528
3594
  this.addParser('a', CandidateLine$1.fromSdpLine);
3529
3595
  this.addParser('a', SimulcastLine$1.fromSdpLine);
3596
+ this.addParser('a', SsrcLine.fromSdpLine);
3597
+ this.addParser('a', SsrcGroupLine.fromSdpLine);
3530
3598
  }
3531
3599
  }
3532
3600
  var DefaultSdpGrammar$1 = new SdpGrammar$1();
@@ -6910,6 +6978,29 @@ function shimRTCIceCandidate$1(window) {
6910
6978
  return e;
6911
6979
  });
6912
6980
  }
6981
+ function shimRTCIceCandidateRelayProtocol(window) {
6982
+ if (!window.RTCIceCandidate || window.RTCIceCandidate && 'relayProtocol' in window.RTCIceCandidate.prototype) {
6983
+ return;
6984
+ }
6985
+
6986
+ // Hook up the augmented candidate in onicecandidate and
6987
+ // addEventListener('icecandidate', ...)
6988
+ wrapPeerConnectionEvent$1(window, 'icecandidate', e => {
6989
+ if (e.candidate) {
6990
+ var parsedCandidate = SDPUtils$1.parseCandidate(e.candidate.candidate);
6991
+ if (parsedCandidate.type === 'relay') {
6992
+ // This is a libwebrtc-specific mapping of local type preference
6993
+ // to relayProtocol.
6994
+ e.candidate.relayProtocol = {
6995
+ 0: 'tls',
6996
+ 1: 'tcp',
6997
+ 2: 'udp'
6998
+ }[parsedCandidate.priority >> 24];
6999
+ }
7000
+ }
7001
+ return e;
7002
+ });
7003
+ }
6913
7004
  function shimMaxMessageSize$1(window, browserDetails) {
6914
7005
  if (!window.RTCPeerConnection) {
6915
7006
  return;
@@ -7246,6 +7337,7 @@ function shimParameterlessSetLocalDescription$1(window, browserDetails) {
7246
7337
  var commonShim$1 = /*#__PURE__*/Object.freeze({
7247
7338
  __proto__: null,
7248
7339
  shimRTCIceCandidate: shimRTCIceCandidate$1,
7340
+ shimRTCIceCandidateRelayProtocol: shimRTCIceCandidateRelayProtocol,
7249
7341
  shimMaxMessageSize: shimMaxMessageSize$1,
7250
7342
  shimSendThrowTypeError: shimSendThrowTypeError$1,
7251
7343
  shimConnectionState: shimConnectionState$1,
@@ -7313,6 +7405,7 @@ function adapterFactory$1() {
7313
7405
  shimSenderReceiverGetStats$1(window);
7314
7406
  fixNegotiationNeeded$1(window, browserDetails);
7315
7407
  shimRTCIceCandidate$1(window);
7408
+ shimRTCIceCandidateRelayProtocol(window);
7316
7409
  shimConnectionState$1(window);
7317
7410
  shimMaxMessageSize$1(window, browserDetails);
7318
7411
  shimSendThrowTypeError$1(window);
@@ -7367,6 +7460,7 @@ function adapterFactory$1() {
7367
7460
  shimGetUserMedia$3(window);
7368
7461
  shimAudioContext$1(window);
7369
7462
  shimRTCIceCandidate$1(window);
7463
+ shimRTCIceCandidateRelayProtocol(window);
7370
7464
  shimMaxMessageSize$1(window, browserDetails);
7371
7465
  shimSendThrowTypeError$1(window);
7372
7466
  removeExtmapAllowMixed$1(window, browserDetails);
@@ -8285,18 +8379,44 @@ function error(id, data) {
8285
8379
  };
8286
8380
  return eventObject;
8287
8381
  }
8288
- function resolveActions(machine, currentState, currentContext, _event, actions, predictableExec, preserveActionOrder) {
8382
+ var pluckAssigns = function pluckAssigns(actionBlocks) {
8383
+ var e_1, _a;
8384
+ var assignActions = [];
8385
+ try {
8386
+ for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
8387
+ var block = actionBlocks_1_1.value;
8388
+ var i = 0;
8389
+ while (i < block.length) {
8390
+ if (block[i].type === assign$2) {
8391
+ assignActions.push(block[i]);
8392
+ block.splice(i, 1);
8393
+ continue;
8394
+ }
8395
+ i++;
8396
+ }
8397
+ }
8398
+ } catch (e_1_1) {
8399
+ e_1 = {
8400
+ error: e_1_1
8401
+ };
8402
+ } finally {
8403
+ try {
8404
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
8405
+ } finally {
8406
+ if (e_1) throw e_1.error;
8407
+ }
8408
+ }
8409
+ return assignActions;
8410
+ };
8411
+ function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
8289
8412
  if (preserveActionOrder === void 0) {
8290
8413
  preserveActionOrder = false;
8291
8414
  }
8292
- var _a = __read(preserveActionOrder ? [[], actions] : partition(actions, function (action) {
8293
- return action.type === assign$2;
8294
- }), 2),
8295
- assignActions = _a[0],
8296
- otherActions = _a[1];
8415
+ var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
8297
8416
  var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
8298
8417
  var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
8299
- var resolvedActions = flatten(otherActions.map(function (actionObject) {
8418
+ var deferredToBlockEnd = [];
8419
+ function handleAction(actionObject) {
8300
8420
  var _a;
8301
8421
  switch (actionObject.type) {
8302
8422
  case raise$1:
@@ -8312,8 +8432,8 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8312
8432
  // tslint:disable-next-line:max-line-length
8313
8433
  "No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
8314
8434
  }
8315
- if (sendAction.to !== SpecialTargets.Internal) {
8316
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
8435
+ if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
8436
+ deferredToBlockEnd.push(sendAction);
8317
8437
  }
8318
8438
  return sendAction;
8319
8439
  case log$2:
@@ -8332,7 +8452,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8332
8452
  if (!matchedActions) {
8333
8453
  return [];
8334
8454
  }
8335
- var _b = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
8455
+ var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
8336
8456
  resolvedActionsFromChoose = _b[0],
8337
8457
  resolvedContextFromChoose = _b[1];
8338
8458
  updatedContext = resolvedContextFromChoose;
@@ -8345,7 +8465,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8345
8465
  if (!matchedActions) {
8346
8466
  return [];
8347
8467
  }
8348
- var _c = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
8468
+ var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
8349
8469
  resolvedActionsFromPure = _c[0],
8350
8470
  resolvedContext = _c[1];
8351
8471
  updatedContext = resolvedContext;
@@ -8355,7 +8475,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8355
8475
  case stop$1:
8356
8476
  {
8357
8477
  var resolved = resolveStop(actionObject, updatedContext, _event);
8358
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
8478
+ predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
8359
8479
  return resolved;
8360
8480
  }
8361
8481
  case assign$2:
@@ -8383,9 +8503,36 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8383
8503
  }
8384
8504
  return resolvedActionObject;
8385
8505
  }
8386
- }).filter(function (a) {
8387
- return !!a;
8388
- }));
8506
+ }
8507
+ function processBlock(block) {
8508
+ var e_2, _a;
8509
+ var resolvedActions = [];
8510
+ try {
8511
+ for (var block_1 = __values(block), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
8512
+ var action = block_1_1.value;
8513
+ var resolved = handleAction(action);
8514
+ if (resolved) {
8515
+ resolvedActions = resolvedActions.concat(resolved);
8516
+ }
8517
+ }
8518
+ } catch (e_2_1) {
8519
+ e_2 = {
8520
+ error: e_2_1
8521
+ };
8522
+ } finally {
8523
+ try {
8524
+ if (block_1_1 && !block_1_1.done && (_a = block_1.return)) _a.call(block_1);
8525
+ } finally {
8526
+ if (e_2) throw e_2.error;
8527
+ }
8528
+ }
8529
+ deferredToBlockEnd.forEach(function (action) {
8530
+ predictableExec(action, updatedContext, _event);
8531
+ });
8532
+ deferredToBlockEnd.length = 0;
8533
+ return resolvedActions;
8534
+ }
8535
+ var resolvedActions = flatten(actionBlocks.map(processBlock));
8389
8536
  return [resolvedActions, updatedContext];
8390
8537
  }
8391
8538
 
@@ -9134,10 +9281,10 @@ function () {
9134
9281
  * @param options Interpreter options
9135
9282
  */
9136
9283
  function Interpreter(machine, options) {
9137
- var _this = this;
9138
9284
  if (options === void 0) {
9139
9285
  options = Interpreter.defaultOptions;
9140
9286
  }
9287
+ var _this = this;
9141
9288
  this.machine = machine;
9142
9289
  this.delayedEventsMap = {};
9143
9290
  this.listeners = new Set();
@@ -9154,6 +9301,7 @@ function () {
9154
9301
  this.status = InterpreterStatus.NotStarted;
9155
9302
  this.children = new Map();
9156
9303
  this.forwardTo = new Set();
9304
+ this._outgoingQueue = [];
9157
9305
  /**
9158
9306
  * Alias for Interpreter.prototype.start
9159
9307
  */
@@ -9189,14 +9337,14 @@ function () {
9189
9337
  _this.scheduler.schedule(function () {
9190
9338
  // Forward copy of event to child actors
9191
9339
  _this.forward(_event);
9192
- var nextState = _this.nextState(_event);
9340
+ var nextState = _this._nextState(_event);
9193
9341
  _this.update(nextState, _event);
9194
9342
  });
9195
9343
  return _this._state; // TODO: deprecate (should return void)
9196
9344
  // tslint:disable-next-line:semicolon
9197
9345
  };
9198
9346
 
9199
- this.sendTo = function (event, to) {
9347
+ this.sendTo = function (event, to, immediate) {
9200
9348
  var isParent = _this.parent && (to === SpecialTargets.Parent || _this.parent.id === to);
9201
9349
  var target = isParent ? _this.parent : isString(to) ? _this.children.get(to) || registry.get(to) : isActor$1(to) ? to : undefined;
9202
9350
  if (!target) {
@@ -9216,14 +9364,23 @@ function () {
9216
9364
  // we need to send events to the parent from exit handlers of a machine that reached its final state
9217
9365
  _this.state.done) {
9218
9366
  // Send SCXML events to machines
9219
- target.send(_assign(_assign({}, event), {
9367
+ var scxmlEvent = _assign(_assign({}, event), {
9220
9368
  name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
9221
9369
  origin: _this.sessionId
9222
- }));
9370
+ });
9371
+ if (!immediate && _this.machine.config.predictableActionArguments) {
9372
+ _this._outgoingQueue.push([target, scxmlEvent]);
9373
+ } else {
9374
+ target.send(scxmlEvent);
9375
+ }
9223
9376
  }
9224
9377
  } else {
9225
9378
  // Send normal events to other targets
9226
- target.send(event.data);
9379
+ if (!immediate && _this.machine.config.predictableActionArguments) {
9380
+ _this._outgoingQueue.push([target, event.data]);
9381
+ } else {
9382
+ target.send(event.data);
9383
+ }
9227
9384
  }
9228
9385
  };
9229
9386
  this._exec = function (action, context, _event, actionFunctionMap) {
@@ -9260,7 +9417,7 @@ function () {
9260
9417
  return;
9261
9418
  } else {
9262
9419
  if (sendAction.to) {
9263
- _this.sendTo(sendAction._event, sendAction.to);
9420
+ _this.sendTo(sendAction._event, sendAction.to, _event === initEvent);
9264
9421
  } else {
9265
9422
  _this.send(sendAction._event);
9266
9423
  }
@@ -9381,6 +9538,9 @@ function () {
9381
9538
  configurable: true
9382
9539
  });
9383
9540
  Object.defineProperty(Interpreter.prototype, "state", {
9541
+ /**
9542
+ * @deprecated Use `.getSnapshot()` instead.
9543
+ */
9384
9544
  get: function get() {
9385
9545
  if (!IS_PRODUCTION) {
9386
9546
  warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
@@ -9429,6 +9589,11 @@ function () {
9429
9589
  // we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
9430
9590
  _event === initEvent) && this.options.execute) {
9431
9591
  this.execute(this.state);
9592
+ } else {
9593
+ var item = void 0;
9594
+ while (item = this._outgoingQueue.shift()) {
9595
+ item[0].send(item[1]);
9596
+ }
9432
9597
  } // Update children
9433
9598
 
9434
9599
  this.children.forEach(function (child) {
@@ -9512,6 +9677,7 @@ function () {
9512
9677
  }
9513
9678
  }
9514
9679
  this._stop();
9680
+ this._stopChildren();
9515
9681
  }
9516
9682
  };
9517
9683
  /*
@@ -9647,6 +9813,15 @@ function () {
9647
9813
  });
9648
9814
  return this;
9649
9815
  };
9816
+ Interpreter.prototype._stopChildren = function () {
9817
+ // TODO: think about converting those to actions
9818
+ this.children.forEach(function (child) {
9819
+ if (isFunction(child.stop)) {
9820
+ child.stop();
9821
+ }
9822
+ });
9823
+ this.children.clear();
9824
+ };
9650
9825
  Interpreter.prototype._stop = function () {
9651
9826
  var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
9652
9827
  try {
@@ -9770,7 +9945,7 @@ function () {
9770
9945
  }).map(function (stateNode) {
9771
9946
  return toActionObjects(stateNode.onExit, _this.machine.options.actions);
9772
9947
  }));
9773
- 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),
9948
+ 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),
9774
9949
  resolvedActions = _a[0],
9775
9950
  updatedContext = _a[1];
9776
9951
  var newState = new State({
@@ -9795,15 +9970,8 @@ function () {
9795
9970
  newState.changed = true;
9796
9971
  return newState;
9797
9972
  });
9798
- _this.update(nextState, _event); // TODO: think about converting those to actions
9799
- // Stop all children
9800
-
9801
- _this.children.forEach(function (child) {
9802
- if (isFunction(child.stop)) {
9803
- child.stop();
9804
- }
9805
- });
9806
- _this.children.clear();
9973
+ _this.update(nextState, _event);
9974
+ _this._stopChildren();
9807
9975
  registry.free(_this.sessionId);
9808
9976
  });
9809
9977
  return this;
@@ -9820,6 +9988,10 @@ function () {
9820
9988
  // tslint:disable-next-line:max-line-length
9821
9989
  "".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."));
9822
9990
  }
9991
+ if (!events.length) {
9992
+ return;
9993
+ }
9994
+ var exec = !!this.machine.config.predictableActionArguments && this._exec;
9823
9995
  this.scheduler.schedule(function () {
9824
9996
  var e_11, _a;
9825
9997
  var nextState = _this.state;
@@ -9829,9 +10001,9 @@ function () {
9829
10001
  var _event = toSCXMLEvent(event_1);
9830
10002
  _this.forward(_event);
9831
10003
  nextState = provide(_this, function () {
9832
- return _this.machine.transition(nextState, _event);
10004
+ return _this.machine.transition(nextState, _event, undefined, exec || undefined);
9833
10005
  });
9834
- batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
10006
+ batchedActions.push.apply(batchedActions, __spreadArray([], __read(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
9835
10007
  return bindActionToState(a, nextState);
9836
10008
  })), false));
9837
10009
  batchChanged = batchChanged || !!nextState.changed;
@@ -9866,8 +10038,11 @@ function () {
9866
10038
  Interpreter.prototype.sender = function (event) {
9867
10039
  return this.send.bind(this, event);
9868
10040
  };
9869
- Interpreter.prototype._nextState = function (event) {
10041
+ Interpreter.prototype._nextState = function (event, exec) {
9870
10042
  var _this = this;
10043
+ if (exec === void 0) {
10044
+ exec = !!this.machine.config.predictableActionArguments && this._exec;
10045
+ }
9871
10046
  var _event = toSCXMLEvent(event);
9872
10047
  if (_event.name.indexOf(errorPlatform) === 0 && !this.state.nextEvents.some(function (nextEvent) {
9873
10048
  return nextEvent.indexOf(errorPlatform) === 0;
@@ -9875,7 +10050,7 @@ function () {
9875
10050
  throw _event.data.data;
9876
10051
  }
9877
10052
  var nextState = provide(this, function () {
9878
- return _this.machine.transition(_this.state, _event, undefined, _this.machine.config.predictableActionArguments ? _this._exec : undefined);
10053
+ return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
9879
10054
  });
9880
10055
  return nextState;
9881
10056
  };
@@ -9888,7 +10063,7 @@ function () {
9888
10063
  */
9889
10064
 
9890
10065
  Interpreter.prototype.nextState = function (event) {
9891
- return this._nextState(event);
10066
+ return this._nextState(event, false);
9892
10067
  };
9893
10068
  Interpreter.prototype.forward = function (event) {
9894
10069
  var e_12, _a;
@@ -9917,7 +10092,7 @@ function () {
9917
10092
  var _this = this;
9918
10093
  this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
9919
10094
  if (sendAction.to) {
9920
- _this.sendTo(sendAction._event, sendAction.to);
10095
+ _this.sendTo(sendAction._event, sendAction.to, true);
9921
10096
  } else {
9922
10097
  _this.send(sendAction._event);
9923
10098
  }
@@ -10412,10 +10587,10 @@ function () {
10412
10587
  _context,
10413
10588
  // TODO: this is unsafe, but we're removing it in v5 anyway
10414
10589
  _stateInfo) {
10415
- var _this = this;
10416
10590
  if (_context === void 0) {
10417
10591
  _context = 'context' in config ? config.context : undefined;
10418
10592
  }
10593
+ var _this = this;
10419
10594
  var _a;
10420
10595
  this.config = config;
10421
10596
  this._context = _context;
@@ -10954,13 +11129,14 @@ function () {
10954
11129
  nodes.push(possibleAncestor);
10955
11130
  return nodes;
10956
11131
  };
10957
- StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState) {
11132
+ StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
10958
11133
  var e_4, _a, e_5, _b;
11134
+ var _this = this;
10959
11135
  var prevConfig = getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
10960
11136
  try {
10961
11137
  for (var resolvedConfig_1 = __values(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
10962
11138
  var sn = resolvedConfig_1_1.value;
10963
- if (!has(prevConfig, sn) || has(transition.entrySet, sn.parent)) {
11139
+ if (!has(prevConfig, sn) || has(transition.entrySet, sn.parent) && !has(transition.entrySet, sn)) {
10964
11140
  transition.entrySet.push(sn);
10965
11141
  }
10966
11142
  }
@@ -11023,18 +11199,19 @@ function () {
11023
11199
  });
11024
11200
  var entryStates = new Set(transition.entrySet);
11025
11201
  var exitStates = new Set(transition.exitSet);
11026
- var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
11027
- return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) {
11028
- return start(activity);
11029
- })), false), __read(stateNode.onEntry), false);
11030
- })).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
11031
- return __spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
11032
- return stop(activity);
11033
- })), false);
11034
- }))], 2),
11035
- entryActions = _c[0],
11036
- exitActions = _c[1];
11037
- var actions = toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
11202
+ var entryActions = Array.from(entryStates).map(function (stateNode) {
11203
+ var entryActions = stateNode.onEntry;
11204
+ var invokeActions = stateNode.activities.map(function (activity) {
11205
+ return start(activity);
11206
+ });
11207
+ return toActionObjects(predictableExec ? __spreadArray(__spreadArray([], __read(entryActions), false), __read(invokeActions), false) : __spreadArray(__spreadArray([], __read(invokeActions), false), __read(entryActions), false), _this.machine.options.actions);
11208
+ }).concat([doneEvents.map(raise)]);
11209
+ var exitActions = Array.from(exitStates).map(function (stateNode) {
11210
+ return toActionObjects(__spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
11211
+ return stop(activity);
11212
+ })), false), _this.machine.options.actions);
11213
+ });
11214
+ var actions = exitActions.concat([toActionObjects(transition.actions, this.machine.options.actions)]).concat(entryActions);
11038
11215
  if (isDone) {
11039
11216
  var stopActions = toActionObjects(flatten(__spreadArray([], __read(resolvedConfig), false).sort(function (a, b) {
11040
11217
  return b.order - a.order;
@@ -11043,7 +11220,7 @@ function () {
11043
11220
  })), this.machine.options.actions).filter(function (action) {
11044
11221
  return action.type !== raise$1 && (action.type !== send$1 || !!action.to && action.to !== SpecialTargets.Internal);
11045
11222
  });
11046
- return actions.concat(stopActions);
11223
+ return actions.concat([stopActions]);
11047
11224
  }
11048
11225
  return actions;
11049
11226
  };
@@ -11101,7 +11278,7 @@ function () {
11101
11278
  return state;
11102
11279
  };
11103
11280
  StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
11104
- var e_6, _a;
11281
+ var e_6, _a, e_7, _b;
11105
11282
  var _this = this;
11106
11283
  if (_event === void 0) {
11107
11284
  _event = initEvent;
@@ -11115,15 +11292,30 @@ function () {
11115
11292
  var isDone = isInFinalState(resolvedConfiguration, this);
11116
11293
  var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
11117
11294
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
11118
- var actions = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState);
11295
+ var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
11119
11296
  var activities = currentState ? _assign({}, currentState.activities) : {};
11120
11297
  try {
11121
- for (var actions_1 = __values(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
11122
- var action = actions_1_1.value;
11123
- if (action.type === start$1) {
11124
- activities[action.activity.id || action.activity.type] = action;
11125
- } else if (action.type === stop$1) {
11126
- activities[action.activity.id || action.activity.type] = false;
11298
+ for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
11299
+ var block = actionBlocks_1_1.value;
11300
+ try {
11301
+ 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()) {
11302
+ var action = block_1_1.value;
11303
+ if (action.type === start$1) {
11304
+ activities[action.activity.id || action.activity.type] = action;
11305
+ } else if (action.type === stop$1) {
11306
+ activities[action.activity.id || action.activity.type] = false;
11307
+ }
11308
+ }
11309
+ } catch (e_7_1) {
11310
+ e_7 = {
11311
+ error: e_7_1
11312
+ };
11313
+ } finally {
11314
+ try {
11315
+ if (block_1_1 && !block_1_1.done && (_b = block_1.return)) _b.call(block_1);
11316
+ } finally {
11317
+ if (e_7) throw e_7.error;
11318
+ }
11127
11319
  }
11128
11320
  }
11129
11321
  } catch (e_6_1) {
@@ -11132,19 +11324,19 @@ function () {
11132
11324
  };
11133
11325
  } finally {
11134
11326
  try {
11135
- if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
11327
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
11136
11328
  } finally {
11137
11329
  if (e_6) throw e_6.error;
11138
11330
  }
11139
11331
  }
11140
- var _b = __read(resolveActions(this, currentState, context, _event, actions, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
11141
- resolvedActions = _b[0],
11142
- updatedContext = _b[1];
11143
- var _c = __read(partition(resolvedActions, function (action) {
11332
+ var _c = __read(resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
11333
+ resolvedActions = _c[0],
11334
+ updatedContext = _c[1];
11335
+ var _d = __read(partition(resolvedActions, function (action) {
11144
11336
  return action.type === raise$1 || action.type === send$1 && action.to === SpecialTargets.Internal;
11145
11337
  }), 2),
11146
- raisedEvents = _c[0],
11147
- nonRaisedActions = _c[1];
11338
+ raisedEvents = _d[0],
11339
+ nonRaisedActions = _d[1];
11148
11340
  var invokeActions = resolvedActions.filter(function (action) {
11149
11341
  var _a;
11150
11342
  return action.type === start$1 && ((_a = action.activity) === null || _a === void 0 ? void 0 : _a.type) === invoke;
@@ -11352,7 +11544,7 @@ function () {
11352
11544
  var configuration = this.getStateNodes(stateValue);
11353
11545
  return this.resolveTransition({
11354
11546
  configuration: configuration,
11355
- entrySet: __spreadArray([], __read(configuration), false),
11547
+ entrySet: configuration,
11356
11548
  exitSet: [],
11357
11549
  transitions: [],
11358
11550
  source: undefined,
@@ -11518,7 +11710,7 @@ function () {
11518
11710
  * All the event types accepted by this state node and its descendants.
11519
11711
  */
11520
11712
  get: function get() {
11521
- var e_7, _a, e_8, _b;
11713
+ var e_8, _a, e_9, _b;
11522
11714
  if (this.__cache.events) {
11523
11715
  return this.__cache.events;
11524
11716
  }
@@ -11531,32 +11723,32 @@ function () {
11531
11723
  var state = states[stateId];
11532
11724
  if (state.states) {
11533
11725
  try {
11534
- for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
11726
+ for (var _e = (e_9 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
11535
11727
  var event_1 = _f.value;
11536
11728
  events.add("".concat(event_1));
11537
11729
  }
11538
- } catch (e_8_1) {
11539
- e_8 = {
11540
- error: e_8_1
11730
+ } catch (e_9_1) {
11731
+ e_9 = {
11732
+ error: e_9_1
11541
11733
  };
11542
11734
  } finally {
11543
11735
  try {
11544
11736
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
11545
11737
  } finally {
11546
- if (e_8) throw e_8.error;
11738
+ if (e_9) throw e_9.error;
11547
11739
  }
11548
11740
  }
11549
11741
  }
11550
11742
  }
11551
- } catch (e_7_1) {
11552
- e_7 = {
11553
- error: e_7_1
11743
+ } catch (e_8_1) {
11744
+ e_8 = {
11745
+ error: e_8_1
11554
11746
  };
11555
11747
  } finally {
11556
11748
  try {
11557
11749
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
11558
11750
  } finally {
11559
- if (e_7) throw e_7.error;
11751
+ if (e_8) throw e_8.error;
11560
11752
  }
11561
11753
  }
11562
11754
  }
@@ -11638,7 +11830,7 @@ function () {
11638
11830
  return transition;
11639
11831
  };
11640
11832
  StateNode.prototype.formatTransitions = function () {
11641
- var e_9, _a;
11833
+ var e_10, _a;
11642
11834
  var _this = this;
11643
11835
  var onConfig;
11644
11836
  if (!this.config.on) {
@@ -11688,15 +11880,15 @@ function () {
11688
11880
  var delayedTransition = delayedTransitions_1_1.value;
11689
11881
  formattedTransitions.push(delayedTransition);
11690
11882
  }
11691
- } catch (e_9_1) {
11692
- e_9 = {
11693
- error: e_9_1
11883
+ } catch (e_10_1) {
11884
+ e_10 = {
11885
+ error: e_10_1
11694
11886
  };
11695
11887
  } finally {
11696
11888
  try {
11697
11889
  if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
11698
11890
  } finally {
11699
- if (e_9) throw e_9.error;
11891
+ if (e_10) throw e_10.error;
11700
11892
  }
11701
11893
  }
11702
11894
  return formattedTransitions;