1 | 'use strict';
|
2 |
|
3 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = undefined;
|
9 |
|
10 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
11 |
|
12 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
13 |
|
14 | var _desc, _value, _class;
|
15 |
|
16 | var _debugDecorator = require('./debug-decorator');
|
17 |
|
18 | Function.prototype.$asyncbind = function $asyncbind(self, catcher) {
|
19 | "use strict";
|
20 |
|
21 | if (!Function.prototype.$asyncbind) {
|
22 | Object.defineProperty(Function.prototype, "$asyncbind", {
|
23 | value: $asyncbind,
|
24 | enumerable: false,
|
25 | configurable: true,
|
26 | writable: true
|
27 | });
|
28 | }
|
29 |
|
30 | if (!$asyncbind.trampoline) {
|
31 | $asyncbind.trampoline = function trampoline(t, x, s, e, u) {
|
32 | return function b(q) {
|
33 | while (q) {
|
34 | if (q.then) {
|
35 | q = q.then(b, e);
|
36 | return u ? undefined : q;
|
37 | }
|
38 |
|
39 | try {
|
40 | if (q.pop) {
|
41 | if (q.length) return q.pop() ? x.call(t) : q;
|
42 | q = s;
|
43 | } else q = q.call(t);
|
44 | } catch (r) {
|
45 | return e(r);
|
46 | }
|
47 | }
|
48 | };
|
49 | };
|
50 | }
|
51 |
|
52 | if (!$asyncbind.LazyThenable) {
|
53 | $asyncbind.LazyThenable = function () {
|
54 | function isThenable(obj) {
|
55 | return obj && obj instanceof Object && typeof obj.then === "function";
|
56 | }
|
57 |
|
58 | function resolution(p, r, how) {
|
59 | try {
|
60 | var x = how ? how(r) : r;
|
61 | if (p === x) return p.reject(new TypeError("Promise resolution loop"));
|
62 |
|
63 | if (isThenable(x)) {
|
64 | x.then(function (y) {
|
65 | resolution(p, y);
|
66 | }, function (e) {
|
67 | p.reject(e);
|
68 | });
|
69 | } else {
|
70 | p.resolve(x);
|
71 | }
|
72 | } catch (ex) {
|
73 | p.reject(ex);
|
74 | }
|
75 | }
|
76 |
|
77 | function Chained() {}
|
78 |
|
79 | ;
|
80 | Chained.prototype = {
|
81 | resolve: _unchained,
|
82 | reject: _unchained,
|
83 | then: thenChain
|
84 | };
|
85 |
|
86 | function _unchained(v) {}
|
87 |
|
88 | function thenChain(res, rej) {
|
89 | this.resolve = res;
|
90 | this.reject = rej;
|
91 | }
|
92 |
|
93 | function then(res, rej) {
|
94 | var chain = new Chained();
|
95 |
|
96 | try {
|
97 | this._resolver(function (value) {
|
98 | return isThenable(value) ? value.then(res, rej) : resolution(chain, value, res);
|
99 | }, function (ex) {
|
100 | resolution(chain, ex, rej);
|
101 | });
|
102 | } catch (ex) {
|
103 | resolution(chain, ex, rej);
|
104 | }
|
105 |
|
106 | return chain;
|
107 | }
|
108 |
|
109 | function Thenable(resolver) {
|
110 | this._resolver = resolver;
|
111 | this.then = then;
|
112 | }
|
113 |
|
114 | ;
|
115 |
|
116 | Thenable.resolve = function (v) {
|
117 | return Thenable.isThenable(v) ? v : {
|
118 | then: function then(resolve) {
|
119 | return resolve(v);
|
120 | }
|
121 | };
|
122 | };
|
123 |
|
124 | Thenable.isThenable = isThenable;
|
125 | return Thenable;
|
126 | }();
|
127 |
|
128 | $asyncbind.EagerThenable = $asyncbind.Thenable = ($asyncbind.EagerThenableFactory = function (tick) {
|
129 | tick = tick || (typeof process === 'undefined' ? 'undefined' : _typeof(process)) === "object" && process.nextTick || typeof setImmediate === "function" && setImmediate || function (f) {
|
130 | setTimeout(f, 0);
|
131 | };
|
132 |
|
133 | var soon = function () {
|
134 | var fq = [],
|
135 | fqStart = 0,
|
136 | bufferSize = 1024;
|
137 |
|
138 | function callQueue() {
|
139 | while (fq.length - fqStart) {
|
140 | fq[fqStart]();
|
141 | fq[fqStart++] = undefined;
|
142 |
|
143 | if (fqStart === bufferSize) {
|
144 | fq.splice(0, bufferSize);
|
145 | fqStart = 0;
|
146 | }
|
147 | }
|
148 | }
|
149 |
|
150 | return function (fn) {
|
151 | fq.push(fn);
|
152 | if (fq.length - fqStart === 1) tick(callQueue);
|
153 | };
|
154 | }();
|
155 |
|
156 | function Zousan(func) {
|
157 | if (func) {
|
158 | var me = this;
|
159 | func(function (arg) {
|
160 | me.resolve(arg);
|
161 | }, function (arg) {
|
162 | me.reject(arg);
|
163 | });
|
164 | }
|
165 | }
|
166 |
|
167 | Zousan.prototype = {
|
168 | resolve: function resolve(value) {
|
169 | if (this.state !== undefined) return;
|
170 | if (value === this) return this.reject(new TypeError("Attempt to resolve promise with self"));
|
171 | var me = this;
|
172 |
|
173 | if (value && (typeof value === "function" || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === "object")) {
|
174 | try {
|
175 | var first = 0;
|
176 | var then = value.then;
|
177 |
|
178 | if (typeof then === "function") {
|
179 | then.call(value, function (ra) {
|
180 | if (!first++) {
|
181 | me.resolve(ra);
|
182 | }
|
183 | }, function (rr) {
|
184 | if (!first++) {
|
185 | me.reject(rr);
|
186 | }
|
187 | });
|
188 | return;
|
189 | }
|
190 | } catch (e) {
|
191 | if (!first) this.reject(e);
|
192 | return;
|
193 | }
|
194 | }
|
195 |
|
196 | this.state = STATE_FULFILLED;
|
197 | this.v = value;
|
198 | if (me.c) soon(function () {
|
199 | for (var n = 0, l = me.c.length; n < l; n++) {
|
200 | STATE_FULFILLED(me.c[n], value);
|
201 | }
|
202 | });
|
203 | },
|
204 | reject: function reject(reason) {
|
205 | if (this.state !== undefined) return;
|
206 | this.state = STATE_REJECTED;
|
207 | this.v = reason;
|
208 | var clients = this.c;
|
209 | if (clients) soon(function () {
|
210 | for (var n = 0, l = clients.length; n < l; n++) {
|
211 | STATE_REJECTED(clients[n], reason);
|
212 | }
|
213 | });
|
214 | },
|
215 | then: function then(onF, onR) {
|
216 | var p = new Zousan();
|
217 | var client = {
|
218 | y: onF,
|
219 | n: onR,
|
220 | p: p
|
221 | };
|
222 |
|
223 | if (this.state === undefined) {
|
224 | if (this.c) this.c.push(client);else this.c = [client];
|
225 | } else {
|
226 | var s = this.state,
|
227 | a = this.v;
|
228 | soon(function () {
|
229 | s(client, a);
|
230 | });
|
231 | }
|
232 |
|
233 | return p;
|
234 | }
|
235 | };
|
236 |
|
237 | function STATE_FULFILLED(c, arg) {
|
238 | if (typeof c.y === "function") {
|
239 | try {
|
240 | var yret = c.y.call(undefined, arg);
|
241 | c.p.resolve(yret);
|
242 | } catch (err) {
|
243 | c.p.reject(err);
|
244 | }
|
245 | } else c.p.resolve(arg);
|
246 | }
|
247 |
|
248 | function STATE_REJECTED(c, reason) {
|
249 | if (typeof c.n === "function") {
|
250 | try {
|
251 | var yret = c.n.call(undefined, reason);
|
252 | c.p.resolve(yret);
|
253 | } catch (err) {
|
254 | c.p.reject(err);
|
255 | }
|
256 | } else c.p.reject(reason);
|
257 | }
|
258 |
|
259 | Zousan.resolve = function (val) {
|
260 | if (val && val instanceof Zousan) return val;
|
261 | var z = new Zousan();
|
262 | z.resolve(val);
|
263 | return z;
|
264 | };
|
265 |
|
266 | Zousan.reject = function (err) {
|
267 | if (err && err instanceof Zousan) return err;
|
268 | var z = new Zousan();
|
269 | z.reject(err);
|
270 | return z;
|
271 | };
|
272 |
|
273 | Zousan.version = "2.3.2-nodent";
|
274 | return Zousan;
|
275 | })();
|
276 | }
|
277 |
|
278 | var resolver = this;
|
279 |
|
280 | switch (catcher) {
|
281 | case true:
|
282 | return new $asyncbind.Thenable(boundThen);
|
283 |
|
284 | case 0:
|
285 | return new $asyncbind.LazyThenable(boundThen);
|
286 |
|
287 | case undefined:
|
288 | boundThen.then = boundThen;
|
289 | return boundThen;
|
290 |
|
291 | default:
|
292 | return function () {
|
293 | try {
|
294 | return resolver.apply(self, arguments);
|
295 | } catch (ex) {
|
296 | return catcher(ex);
|
297 | }
|
298 | };
|
299 | }
|
300 |
|
301 | function boundThen() {
|
302 | return resolver.apply(self, arguments);
|
303 | }
|
304 | };
|
305 |
|
306 | function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
307 |
|
308 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
309 |
|
310 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
311 |
|
312 | function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
|
313 | var desc = {};
|
314 | Object['ke' + 'ys'](descriptor).forEach(function (key) {
|
315 | desc[key] = descriptor[key];
|
316 | });
|
317 | desc.enumerable = !!desc.enumerable;
|
318 | desc.configurable = !!desc.configurable;
|
319 |
|
320 | if ('value' in desc || desc.initializer) {
|
321 | desc.writable = true;
|
322 | }
|
323 |
|
324 | desc = decorators.slice().reverse().reduce(function (desc, decorator) {
|
325 | return decorator(target, property, desc) || desc;
|
326 | }, desc);
|
327 |
|
328 | if (context && desc.initializer !== void 0) {
|
329 | desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
330 | desc.initializer = undefined;
|
331 | }
|
332 |
|
333 | if (desc.initializer === void 0) {
|
334 | Object['define' + 'Property'](target, property, desc);
|
335 | desc = null;
|
336 | }
|
337 |
|
338 | return desc;
|
339 | }
|
340 |
|
341 | function compare(a, b) {
|
342 | if (!isNaN(parseInt(a.path))) {
|
343 | return parseInt(a.path) - parseInt(b.path);
|
344 | } else {
|
345 | return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
346 | }
|
347 | }
|
348 |
|
349 | var ParallelTransport = (_class = function () {
|
350 | function ParallelTransport(transports) {
|
351 | _classCallCheck(this, ParallelTransport);
|
352 |
|
353 | this.name = 'ParallelTransport';
|
354 | this.debug = false;
|
355 | this.requestNeeded = false;
|
356 |
|
357 | this.transports = transports;
|
358 | }
|
359 |
|
360 | _createClass(ParallelTransport, [{
|
361 | key: '_prepend',
|
362 | value: function _prepend(name, devices) {
|
363 | return devices.map(function (device) {
|
364 | return {
|
365 | path: name + '-' + device.path,
|
366 | session: device.session == null ? null : name + '-' + device.session
|
367 | };
|
368 | });
|
369 | }
|
370 | }, {
|
371 | key: '_filter',
|
372 | value: function _filter(name, devices) {
|
373 | var _this = this;
|
374 |
|
375 | return devices.filter(function (device) {
|
376 | return _this._parseName(device.path).name === name;
|
377 | }).map(function (device) {
|
378 | return _extends({}, device, {
|
379 | path: _this._parseName(device.path).rest,
|
380 | session: device.session == null ? device.session : _this._parseName(device.session).rest
|
381 | });
|
382 | });
|
383 | }
|
384 | }, {
|
385 | key: '_antiFilter',
|
386 | value: function _antiFilter(name, devices) {
|
387 | var _this2 = this;
|
388 |
|
389 | return devices.filter(function (device) {
|
390 | return _this2._parseName(device.path).name !== name;
|
391 | });
|
392 | }
|
393 | }, {
|
394 | key: 'enumerate',
|
395 | value: function enumerate() {
|
396 | return new Promise(function ($return, $error) {
|
397 | var $Try_1_Finally = function ($Try_1_Exit) {
|
398 | return function ($Try_1_Value) {
|
399 | try {
|
400 | if (!_iteratorNormalCompletion && _iterator.return) {
|
401 | _iterator.return();
|
402 | }
|
403 | } catch ($exception_3) {
|
404 | return $Try_2_Finally($error)($exception_3);
|
405 | } finally {
|
406 | if (_didIteratorError) {
|
407 | return $error(_iteratorError);
|
408 | }
|
409 | }
|
410 |
|
411 | return $Try_1_Exit && $Try_1_Exit.call(this, $Try_1_Value);
|
412 | }.$asyncbind(this, $error);
|
413 | }.$asyncbind(this);
|
414 |
|
415 | var res, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, name, devices;
|
416 |
|
417 | res = [];
|
418 | _iteratorNormalCompletion = true;
|
419 | _didIteratorError = false;
|
420 | _iteratorError = undefined;
|
421 |
|
422 | function $Try_1_Post() {
|
423 | return $return(res.sort(compare));
|
424 | }
|
425 |
|
426 | var $Try_1_Catch = function (err) {
|
427 | _didIteratorError = true;
|
428 | _iteratorError = err;
|
429 | return $Try_1_Finally($Try_1_Post).call(this);
|
430 | }.$asyncbind(this, $Try_1_Finally($error));
|
431 |
|
432 | try {
|
433 | _iterator = Object.keys(this.transports)[Symbol.iterator]();
|
434 | return Function.$asyncbind.trampoline(this, $Loop_16_exit, $Loop_16_step, $Try_1_Catch, true)($Loop_16);
|
435 |
|
436 | function $Loop_16() {
|
437 | if (!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) {
|
438 | name = _step.value;
|
439 | return this.transports[name].enumerate().then(function ($await_23) {
|
440 | devices = $await_23;
|
441 | res.push.apply(res, _toConsumableArray(this._prepend(name, devices)));
|
442 | return $Loop_16_step;
|
443 | }.$asyncbind(this, $Try_1_Catch), $Try_1_Catch);
|
444 | } else return [1];
|
445 | }
|
446 |
|
447 | function $Loop_16_step() {
|
448 | _iteratorNormalCompletion = true;
|
449 | return $Loop_16;
|
450 | }
|
451 |
|
452 | function $Loop_16_exit() {
|
453 | return $Try_1_Finally($Try_1_Post).call(this);
|
454 | }
|
455 | } catch (err) {
|
456 | $Try_1_Catch(err)
|
457 | }
|
458 | }.$asyncbind(this));
|
459 | }
|
460 | }, {
|
461 | key: 'listen',
|
462 | value: function listen(old) {
|
463 | return new Promise(function ($return, $error) {
|
464 | var _this3, actualOld, promises, _ref, name, devices, antiFiltered, prepended;
|
465 |
|
466 | _this3 = this;
|
467 | return new Promise(function ($return, $error) {
|
468 | if (old == null) {
|
469 | return this.enumerate().then($return, $error);
|
470 | }return $return(old);
|
471 | }.$asyncbind(this)).then(function ($await_25) {
|
472 | actualOld = $await_25;
|
473 |
|
474 | promises = Object.keys(this.transports).map(function (name) {
|
475 | return new Promise(function ($return, $error) {
|
476 | var oldFiltered, devices;
|
477 |
|
478 | oldFiltered = _this3._filter(name, actualOld);
|
479 | return _this3.transports[name].listen(oldFiltered).then(function ($await_26) {
|
480 | devices = $await_26;
|
481 | return $return({ name: name, devices: devices });
|
482 | }.$asyncbind(this, $error), $error);
|
483 | }.$asyncbind(this));
|
484 | });
|
485 |
|
486 | return Promise.race(promises).then(function ($await_27) {
|
487 | _ref = $await_27, name = _ref.name, devices = _ref.devices;
|
488 |
|
489 |
|
490 | antiFiltered = this._antiFilter(name, actualOld);
|
491 | prepended = this._prepend(name, devices);
|
492 |
|
493 | return $return(antiFiltered.concat(prepended).sort(compare));
|
494 | }.$asyncbind(this, $error), $error);
|
495 | }.$asyncbind(this, $error), $error);
|
496 | }.$asyncbind(this));
|
497 | }
|
498 | }, {
|
499 | key: '_parseName',
|
500 | value: function _parseName(input) {
|
501 | if (input == null) {
|
502 | throw new Error('Wrong input');
|
503 | }
|
504 |
|
505 | var _input$split = input.split('-'),
|
506 | _input$split2 = _toArray(_input$split),
|
507 | name = _input$split2[0],
|
508 | restArray = _input$split2.slice(1);
|
509 |
|
510 | if (restArray.length === 0) {
|
511 | throw new Error('Input has to contain transport name.');
|
512 | }
|
513 | var transport = this.transports[name];
|
514 | if (transport == null) {
|
515 | throw new Error('Input has to contain valid transport name.');
|
516 | }
|
517 | var rest = restArray.join('-');
|
518 |
|
519 | return {
|
520 | transport: transport,
|
521 | name: name,
|
522 | rest: rest
|
523 | };
|
524 | }
|
525 | }, {
|
526 | key: 'acquire',
|
527 | value: function acquire(input) {
|
528 | return new Promise(function ($return, $error) {
|
529 | var path, previous, newInput, res;
|
530 |
|
531 | path = this._parseName(input.path);
|
532 | previous = input.previous == null ? null : this._parseName(input.previous);
|
533 | if (previous != null && path.name !== previous.name) {
|
534 | return $error(new Error('Session transport has to equal path transport.'));
|
535 | }
|
536 | newInput = {
|
537 | path: path.rest,
|
538 | previous: previous == null ? null : previous.rest,
|
539 | checkPrevious: input.checkPrevious
|
540 | };
|
541 | return path.transport.acquire(newInput).then(function ($await_28) {
|
542 | res = $await_28;
|
543 | return $return(path.name + '-' + res);
|
544 | }.$asyncbind(this, $error), $error);
|
545 | }.$asyncbind(this));
|
546 | }
|
547 | }, {
|
548 | key: 'release',
|
549 | value: function release(session) {
|
550 | return new Promise(function ($return, $error) {
|
551 | var sessionP = this._parseName(session);
|
552 | return $return(sessionP.transport.release(sessionP.rest));
|
553 | }.$asyncbind(this));
|
554 | }
|
555 | }, {
|
556 | key: '_checkConfigured',
|
557 | value: function _checkConfigured() {
|
558 |
|
559 | var _iteratorNormalCompletion2 = true;
|
560 | var _didIteratorError2 = false;
|
561 | var _iteratorError2 = undefined;
|
562 |
|
563 | try {
|
564 | for (var _iterator2 = Object.keys(this.transports)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
565 | var name = _step2.value;
|
566 |
|
567 | var transport = this.transports[name];
|
568 | if (!transport.configured) {
|
569 | return false;
|
570 | }
|
571 | }
|
572 | } catch (err) {
|
573 | _didIteratorError2 = true;
|
574 | _iteratorError2 = err;
|
575 | } finally {
|
576 | try {
|
577 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
578 | _iterator2.return();
|
579 | }
|
580 | } finally {
|
581 | if (_didIteratorError2) {
|
582 | throw _iteratorError2;
|
583 | }
|
584 | }
|
585 | }
|
586 |
|
587 | return true;
|
588 | }
|
589 | }, {
|
590 | key: 'configure',
|
591 | value: function configure(signedData) {
|
592 | return new Promise(function ($return, $error) {
|
593 | var $Try_6_Finally = function ($Try_6_Exit) {
|
594 | return function ($Try_6_Value) {
|
595 | try {
|
596 | if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
597 | _iterator3.return();
|
598 | }
|
599 | } catch ($exception_8) {
|
600 | return $Try_7_Finally($error)($exception_8);
|
601 | } finally {
|
602 | if (_didIteratorError3) {
|
603 | return $error(_iteratorError3);
|
604 | }
|
605 | }
|
606 |
|
607 | return $Try_6_Exit && $Try_6_Exit.call(this, $Try_6_Value);
|
608 | }.$asyncbind(this, $error);
|
609 | }.$asyncbind(this);
|
610 |
|
611 | var _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, name, transport;
|
612 |
|
613 | _iteratorNormalCompletion3 = true;
|
614 | _didIteratorError3 = false;
|
615 | _iteratorError3 = undefined;
|
616 |
|
617 | function $Try_6_Post() {
|
618 | this.configured = this._checkConfigured();
|
619 | return $return();
|
620 | }
|
621 |
|
622 | var $Try_6_Catch = function (err) {
|
623 | _didIteratorError3 = true;
|
624 | _iteratorError3 = err;
|
625 | return $Try_6_Finally($Try_6_Post).call(this);
|
626 | }.$asyncbind(this, $Try_6_Finally($error));
|
627 | try {
|
628 | _iterator3 = Object.keys(this.transports)[Symbol.iterator]();
|
629 | return Function.$asyncbind.trampoline(this, $Loop_19_exit, $Loop_19_step, $Try_6_Catch, true)($Loop_19);
|
630 |
|
631 | function $Loop_19() {
|
632 | if (!(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done)) {
|
633 | name = _step3.value;
|
634 |
|
635 | transport = this.transports[name];
|
636 | return transport.configure(signedData).then(function ($await_29) {
|
637 | return $Loop_19_step;
|
638 | }.$asyncbind(this, $Try_6_Catch), $Try_6_Catch);
|
639 | } else return [1];
|
640 | }
|
641 |
|
642 | function $Loop_19_step() {
|
643 | _iteratorNormalCompletion3 = true;
|
644 | return $Loop_19;
|
645 | }
|
646 |
|
647 | function $Loop_19_exit() {
|
648 | return $Try_6_Finally($Try_6_Post).call(this);
|
649 | }
|
650 | } catch (err) {
|
651 | $Try_6_Catch(err)
|
652 | }
|
653 | }.$asyncbind(this));
|
654 | }
|
655 | }, {
|
656 | key: 'call',
|
657 | value: function call(session, name, data) {
|
658 | return new Promise(function ($return, $error) {
|
659 | var sessionP = this._parseName(session);
|
660 | return $return(sessionP.transport.call(sessionP.rest, name, data));
|
661 | }.$asyncbind(this));
|
662 | }
|
663 |
|
664 |
|
665 |
|
666 | }, {
|
667 | key: 'init',
|
668 | value: function init(debug) {
|
669 | return new Promise(function ($return, $error) {
|
670 | var $Try_9_Finally = function ($Try_9_Exit) {
|
671 | return function ($Try_9_Value) {
|
672 | try {
|
673 | if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
674 | _iterator4.return();
|
675 | }
|
676 | } catch ($exception_11) {
|
677 | return $Try_10_Finally($error)($exception_11);
|
678 | } finally {
|
679 | if (_didIteratorError4) {
|
680 | return $error(_iteratorError4);
|
681 | }
|
682 | }
|
683 |
|
684 | return $Try_9_Exit && $Try_9_Exit.call(this, $Try_9_Value);
|
685 | }.$asyncbind(this, $error);
|
686 | }.$asyncbind(this);
|
687 |
|
688 | var version, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, name, transport;
|
689 |
|
690 | this.debug = !!debug;
|
691 | version = '';
|
692 | _iteratorNormalCompletion4 = true;
|
693 | _didIteratorError4 = false;
|
694 | _iteratorError4 = undefined;
|
695 |
|
696 | function $Try_9_Post() {
|
697 | this.version = version;
|
698 | this.configured = this._checkConfigured();
|
699 | return $return();
|
700 | }
|
701 |
|
702 | var $Try_9_Catch = function (err) {
|
703 | _didIteratorError4 = true;
|
704 | _iteratorError4 = err;
|
705 | return $Try_9_Finally($Try_9_Post).call(this);
|
706 | }.$asyncbind(this, $Try_9_Finally($error));
|
707 | try {
|
708 | _iterator4 = Object.keys(this.transports)[Symbol.iterator]();
|
709 | return Function.$asyncbind.trampoline(this, $Loop_21_exit, $Loop_21_step, $Try_9_Catch, true)($Loop_21);
|
710 |
|
711 | function $Loop_21() {
|
712 | if (!(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done)) {
|
713 | name = _step4.value;
|
714 |
|
715 | transport = this.transports[name];
|
716 | return transport.init(debug).then(function ($await_30) {
|
717 | version = version + (name + ':' + transport.version + ';');
|
718 | if (transport.requestNeeded) {
|
719 | this.requestNeeded = transport.requestNeeded;
|
720 | }
|
721 | return $Loop_21_step;
|
722 | }.$asyncbind(this, $Try_9_Catch), $Try_9_Catch);
|
723 | } else return [1];
|
724 | }
|
725 |
|
726 | function $Loop_21_step() {
|
727 | _iteratorNormalCompletion4 = true;
|
728 | return $Loop_21;
|
729 | }
|
730 |
|
731 | function $Loop_21_exit() {
|
732 | return $Try_9_Finally($Try_9_Post).call(this);
|
733 | }
|
734 | } catch (err) {
|
735 | $Try_9_Catch(err)
|
736 | }
|
737 | }.$asyncbind(this));
|
738 | }
|
739 | }, {
|
740 | key: 'requestDevice',
|
741 | value: function requestDevice() {
|
742 | return new Promise(function ($return, $error) {
|
743 | var $Try_12_Finally = function ($Try_12_Exit) {
|
744 | return function ($Try_12_Value) {
|
745 | try {
|
746 | if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
747 | _iterator5.return();
|
748 | }
|
749 | } catch ($exception_14) {
|
750 | return $Try_13_Finally($error)($exception_14);
|
751 | } finally {
|
752 | if (_didIteratorError5) {
|
753 | return $error(_iteratorError5);
|
754 | }
|
755 | }
|
756 |
|
757 | return $Try_12_Exit && $Try_12_Exit.call(this, $Try_12_Value);
|
758 | }.$asyncbind(this, $error);
|
759 | }.$asyncbind(this);
|
760 |
|
761 | var _iteratorNormalCompletion5 = true;
|
762 | var _didIteratorError5 = false;
|
763 | var _iteratorError5 = undefined;
|
764 |
|
765 | function $Try_12_Post() {
|
766 |
|
767 | return $return(Promise.reject());
|
768 | }
|
769 |
|
770 | var $Try_12_Catch = function (err) {
|
771 | _didIteratorError5 = true;
|
772 | _iteratorError5 = err;
|
773 | return $Try_12_Finally($Try_12_Post).call(this);
|
774 | }.$asyncbind(this, $Try_12_Finally($error));
|
775 | try {
|
776 | for (var _iterator5 = Object.keys(this.transports)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
777 | var name = _step5.value;
|
778 |
|
779 | var transport = this.transports[name];
|
780 | if (transport.requestNeeded) {
|
781 | return $Try_12_Finally($return)(transport.requestDevice());
|
782 | }
|
783 | }return $Try_12_Finally($Try_12_Post).call(this);
|
784 | } catch (err) {
|
785 | $Try_12_Catch(err)
|
786 | }
|
787 | }.$asyncbind(this));
|
788 | }
|
789 | }]);
|
790 |
|
791 | return ParallelTransport;
|
792 | }(), (_applyDecoratedDescriptor(_class.prototype, 'enumerate', [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, 'enumerate'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'listen', [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, 'listen'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'acquire', [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, 'acquire'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'release', [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, 'release'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'configure', [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, 'configure'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'call', [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, 'call'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'init', [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, 'init'), _class.prototype)), _class);
|
793 | exports.default = ParallelTransport;
|
794 | module.exports = exports['default']; |
\ | No newline at end of file |