1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 |
|
8 | var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
9 |
|
10 | var _monkey_patch = require("./protobuf/monkey_patch");
|
11 |
|
12 | var _defered = require("../defered");
|
13 |
|
14 | var _parse_protocol = require("./protobuf/parse_protocol");
|
15 |
|
16 | var _send = require("./send");
|
17 |
|
18 | var _receive = require("./receive");
|
19 |
|
20 | var _debugDecorator = require("../debug-decorator");
|
21 |
|
22 | var _sharedConnectionWorker = require("./sharedConnectionWorker");
|
23 |
|
24 | var _class, _temp;
|
25 |
|
26 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
27 |
|
28 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
29 |
|
30 | function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
31 |
|
32 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
33 |
|
34 | 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); } }
|
35 |
|
36 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
37 |
|
38 | function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
39 |
|
40 | (0, _monkey_patch.patch)();
|
41 |
|
42 |
|
43 | var stringify = require('json-stable-stringify');
|
44 |
|
45 | function stableStringify(devices) {
|
46 | if (devices == null) {
|
47 | return "null";
|
48 | }
|
49 |
|
50 | var pureDevices = devices.map(function (device) {
|
51 | var path = device.path;
|
52 | var session = device.session == null ? null : device.session;
|
53 | return {
|
54 | path: path,
|
55 | session: session
|
56 | };
|
57 | });
|
58 | return stringify(pureDevices);
|
59 | }
|
60 |
|
61 | function compare(a, b) {
|
62 | if (!isNaN(parseInt(a.path))) {
|
63 | return parseInt(a.path) - parseInt(b.path);
|
64 | } else {
|
65 | return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
66 | }
|
67 | }
|
68 |
|
69 | var ITER_MAX = 60;
|
70 | var ITER_DELAY = 500;
|
71 | var LowlevelTransportWithSharedConnections = (_class = (_temp =
|
72 |
|
73 | function () {
|
74 |
|
75 | function LowlevelTransportWithSharedConnections(plugin, sharedWorkerFactory) {
|
76 | _classCallCheck(this, LowlevelTransportWithSharedConnections);
|
77 |
|
78 | this.name = "LowlevelTransportWithSharedConnections";
|
79 | this.debug = false;
|
80 | this.deferedDebugOnRelease = {};
|
81 | this.deferedNormalOnRelease = {};
|
82 | this.configured = false;
|
83 | this.stopped = false;
|
84 | this._lastStringified = "";
|
85 | this.requestNeeded = false;
|
86 | this.latestId = 0;
|
87 | this.defereds = {};
|
88 | this.isOutdated = false;
|
89 | this.plugin = plugin;
|
90 | this.version = plugin.version;
|
91 | this._sharedWorkerFactory = sharedWorkerFactory;
|
92 |
|
93 | if (!this.plugin.allowsWriteAndEnumerate) {
|
94 |
|
95 | throw new Error("Plugin with shared connections cannot disallow write and enumerate");
|
96 | }
|
97 | }
|
98 |
|
99 | _createClass(LowlevelTransportWithSharedConnections, [{
|
100 | key: "enumerate",
|
101 | value: function enumerate() {
|
102 | return this._silentEnumerate();
|
103 | }
|
104 | }, {
|
105 | key: "_silentEnumerate",
|
106 | value: function () {
|
107 | var _silentEnumerate2 = _asyncToGenerator(
|
108 |
|
109 | _regenerator["default"].mark(function _callee() {
|
110 | var devices, sessionsM, debugSessions, normalSessions, devicesWithSessions;
|
111 | return _regenerator["default"].wrap(function _callee$(_context) {
|
112 | while (1) {
|
113 | switch (_context.prev = _context.next) {
|
114 | case 0:
|
115 | _context.next = 2;
|
116 | return this.sendToWorker({
|
117 | type: "enumerate-intent"
|
118 | });
|
119 |
|
120 | case 2:
|
121 | devices = [];
|
122 | _context.prev = 3;
|
123 | _context.next = 6;
|
124 | return this.plugin.enumerate();
|
125 |
|
126 | case 6:
|
127 | devices = _context.sent;
|
128 |
|
129 | case 7:
|
130 | _context.prev = 7;
|
131 | _context.next = 10;
|
132 | return this.sendToWorker({
|
133 | type: "enumerate-done"
|
134 | });
|
135 |
|
136 | case 10:
|
137 | return _context.finish(7);
|
138 |
|
139 | case 11:
|
140 | _context.next = 13;
|
141 | return this.sendToWorker({
|
142 | type: "get-sessions-and-disconnect",
|
143 | devices: devices
|
144 | });
|
145 |
|
146 | case 13:
|
147 | sessionsM = _context.sent;
|
148 |
|
149 | if (!(sessionsM.type !== "sessions")) {
|
150 | _context.next = 16;
|
151 | break;
|
152 | }
|
153 |
|
154 | throw new Error("Wrong reply");
|
155 |
|
156 | case 16:
|
157 | debugSessions = sessionsM.debugSessions;
|
158 | normalSessions = sessionsM.normalSessions;
|
159 | devicesWithSessions = devices.map(function (device) {
|
160 | var session = normalSessions[device.path];
|
161 | var debugSession = debugSessions[device.path];
|
162 | return {
|
163 | path: device.path,
|
164 | session: session,
|
165 | debug: device.debug,
|
166 | debugSession: debugSession
|
167 | };
|
168 | });
|
169 |
|
170 | this._releaseDisconnected(devicesWithSessions);
|
171 |
|
172 | return _context.abrupt("return", devicesWithSessions.sort(compare));
|
173 |
|
174 | case 21:
|
175 | case "end":
|
176 | return _context.stop();
|
177 | }
|
178 | }
|
179 | }, _callee, this, [[3,, 7, 11]]);
|
180 | }));
|
181 |
|
182 | function _silentEnumerate() {
|
183 | return _silentEnumerate2.apply(this, arguments);
|
184 | }
|
185 |
|
186 | return _silentEnumerate;
|
187 | }()
|
188 | }, {
|
189 | key: "_releaseDisconnected",
|
190 | value: function _releaseDisconnected(devices) {
|
191 | var _this = this;
|
192 |
|
193 | var connected = {};
|
194 | devices.forEach(function (device) {
|
195 | if (device.session != null) {
|
196 | connected[device.session] = true;
|
197 | }
|
198 | });
|
199 | Object.keys(this.deferedDebugOnRelease).forEach(function (session) {
|
200 | if (connected[session] == null) {
|
201 | _this._releaseCleanup(session, true);
|
202 | }
|
203 | });
|
204 | Object.keys(this.deferedNormalOnRelease).forEach(function (session) {
|
205 | if (connected[session] == null) {
|
206 | _this._releaseCleanup(session, false);
|
207 | }
|
208 | });
|
209 | }
|
210 | }, {
|
211 | key: "listen",
|
212 | value: function () {
|
213 | var _listen = _asyncToGenerator(
|
214 |
|
215 | _regenerator["default"].mark(function _callee2(old) {
|
216 | var oldStringified, last;
|
217 | return _regenerator["default"].wrap(function _callee2$(_context2) {
|
218 | while (1) {
|
219 | switch (_context2.prev = _context2.next) {
|
220 | case 0:
|
221 | oldStringified = stableStringify(old);
|
222 | last = old == null ? this._lastStringified : oldStringified;
|
223 | return _context2.abrupt("return", this._runIter(0, last));
|
224 |
|
225 | case 3:
|
226 | case "end":
|
227 | return _context2.stop();
|
228 | }
|
229 | }
|
230 | }, _callee2, this);
|
231 | }));
|
232 |
|
233 | function listen(_x) {
|
234 | return _listen.apply(this, arguments);
|
235 | }
|
236 |
|
237 | return listen;
|
238 | }()
|
239 | }, {
|
240 | key: "_runIter",
|
241 | value: function () {
|
242 | var _runIter2 = _asyncToGenerator(
|
243 |
|
244 | _regenerator["default"].mark(function _callee3(iteration, oldStringified) {
|
245 | var devices, stringified;
|
246 | return _regenerator["default"].wrap(function _callee3$(_context3) {
|
247 | while (1) {
|
248 | switch (_context3.prev = _context3.next) {
|
249 | case 0:
|
250 | _context3.next = 2;
|
251 | return this._silentEnumerate();
|
252 |
|
253 | case 2:
|
254 | devices = _context3.sent;
|
255 | stringified = stableStringify(devices);
|
256 |
|
257 | if (!(stringified !== oldStringified || iteration === ITER_MAX)) {
|
258 | _context3.next = 7;
|
259 | break;
|
260 | }
|
261 |
|
262 | this._lastStringified = stringified;
|
263 | return _context3.abrupt("return", devices);
|
264 |
|
265 | case 7:
|
266 | _context3.next = 9;
|
267 | return (0, _defered.resolveTimeoutPromise)(ITER_DELAY, null);
|
268 |
|
269 | case 9:
|
270 | return _context3.abrupt("return", this._runIter(iteration + 1, stringified));
|
271 |
|
272 | case 10:
|
273 | case "end":
|
274 | return _context3.stop();
|
275 | }
|
276 | }
|
277 | }, _callee3, this);
|
278 | }));
|
279 |
|
280 | function _runIter(_x2, _x3) {
|
281 | return _runIter2.apply(this, arguments);
|
282 | }
|
283 |
|
284 | return _runIter;
|
285 | }()
|
286 | }, {
|
287 | key: "acquire",
|
288 | value: function () {
|
289 | var _acquire = _asyncToGenerator(
|
290 |
|
291 | _regenerator["default"].mark(function _callee4(input, debugLink) {
|
292 | var messBack, reset, messBack2, session;
|
293 | return _regenerator["default"].wrap(function _callee4$(_context4) {
|
294 | while (1) {
|
295 | switch (_context4.prev = _context4.next) {
|
296 | case 0:
|
297 | _context4.next = 2;
|
298 | return this.sendToWorker({
|
299 | type: "acquire-intent",
|
300 | path: input.path,
|
301 | previous: input.previous,
|
302 | debug: debugLink
|
303 | });
|
304 |
|
305 | case 2:
|
306 | messBack = _context4.sent;
|
307 |
|
308 | if (!(messBack.type === "wrong-previous-session")) {
|
309 | _context4.next = 5;
|
310 | break;
|
311 | }
|
312 |
|
313 | throw new Error("wrong previous session");
|
314 |
|
315 | case 5:
|
316 | if (!(messBack.type !== "other-session")) {
|
317 | _context4.next = 7;
|
318 | break;
|
319 | }
|
320 |
|
321 | throw new Error("Strange reply");
|
322 |
|
323 | case 7:
|
324 | reset = messBack.otherSession == null;
|
325 | _context4.prev = 8;
|
326 | _context4.next = 11;
|
327 | return this.plugin.connect(input.path, debugLink, reset);
|
328 |
|
329 | case 11:
|
330 | _context4.next = 18;
|
331 | break;
|
332 |
|
333 | case 13:
|
334 | _context4.prev = 13;
|
335 | _context4.t0 = _context4["catch"](8);
|
336 | _context4.next = 17;
|
337 | return this.sendToWorker({
|
338 | type: "acquire-failed"
|
339 | });
|
340 |
|
341 | case 17:
|
342 | throw _context4.t0;
|
343 |
|
344 | case 18:
|
345 | _context4.next = 20;
|
346 | return this.sendToWorker({
|
347 | type: "acquire-done"
|
348 | });
|
349 |
|
350 | case 20:
|
351 | messBack2 = _context4.sent;
|
352 |
|
353 | if (!(messBack2.type !== "session-number")) {
|
354 | _context4.next = 23;
|
355 | break;
|
356 | }
|
357 |
|
358 | throw new Error("Strange reply.");
|
359 |
|
360 | case 23:
|
361 | session = messBack2.number;
|
362 |
|
363 | if (debugLink) {
|
364 | this.deferedDebugOnRelease[session] = (0, _defered.create)();
|
365 | } else {
|
366 | this.deferedNormalOnRelease[session] = (0, _defered.create)();
|
367 | }
|
368 |
|
369 | return _context4.abrupt("return", session);
|
370 |
|
371 | case 26:
|
372 | case "end":
|
373 | return _context4.stop();
|
374 | }
|
375 | }
|
376 | }, _callee4, this, [[8, 13]]);
|
377 | }));
|
378 |
|
379 | function acquire(_x4, _x5) {
|
380 | return _acquire.apply(this, arguments);
|
381 | }
|
382 |
|
383 | return acquire;
|
384 | }()
|
385 | }, {
|
386 | key: "release",
|
387 | value: function () {
|
388 | var _release = _asyncToGenerator(
|
389 |
|
390 | _regenerator["default"].mark(function _callee5(session, onclose, debugLink) {
|
391 | var messback, path, otherSession, last;
|
392 | return _regenerator["default"].wrap(function _callee5$(_context5) {
|
393 | while (1) {
|
394 | switch (_context5.prev = _context5.next) {
|
395 | case 0:
|
396 | if (!(onclose && !debugLink)) {
|
397 | _context5.next = 3;
|
398 | break;
|
399 | }
|
400 |
|
401 |
|
402 |
|
403 |
|
404 | this.sendToWorker({
|
405 | type: "release-onclose",
|
406 | session: session
|
407 | });
|
408 | return _context5.abrupt("return");
|
409 |
|
410 | case 3:
|
411 | _context5.next = 5;
|
412 | return this.sendToWorker({
|
413 | type: "release-intent",
|
414 | session: session,
|
415 | debug: debugLink
|
416 | });
|
417 |
|
418 | case 5:
|
419 | messback = _context5.sent;
|
420 |
|
421 | if (!(messback.type === "double-release")) {
|
422 | _context5.next = 8;
|
423 | break;
|
424 | }
|
425 |
|
426 | throw new Error("Trying to double release.");
|
427 |
|
428 | case 8:
|
429 | if (!(messback.type !== "path")) {
|
430 | _context5.next = 10;
|
431 | break;
|
432 | }
|
433 |
|
434 | throw new Error("Strange reply.");
|
435 |
|
436 | case 10:
|
437 | path = messback.path;
|
438 | otherSession = messback.otherSession;
|
439 | last = otherSession == null;
|
440 |
|
441 | this._releaseCleanup(session, debugLink);
|
442 |
|
443 | _context5.prev = 14;
|
444 | _context5.next = 17;
|
445 | return this.plugin.disconnect(path, debugLink, last);
|
446 |
|
447 | case 17:
|
448 | _context5.next = 21;
|
449 | break;
|
450 |
|
451 | case 19:
|
452 | _context5.prev = 19;
|
453 | _context5.t0 = _context5["catch"](14);
|
454 |
|
455 | case 21:
|
456 | _context5.next = 23;
|
457 | return this.sendToWorker({
|
458 | type: "release-done"
|
459 | });
|
460 |
|
461 | case 23:
|
462 | case "end":
|
463 | return _context5.stop();
|
464 | }
|
465 | }
|
466 | }, _callee5, this, [[14, 19]]);
|
467 | }));
|
468 |
|
469 | function release(_x6, _x7, _x8) {
|
470 | return _release.apply(this, arguments);
|
471 | }
|
472 |
|
473 | return release;
|
474 | }()
|
475 | }, {
|
476 | key: "_releaseCleanup",
|
477 | value: function _releaseCleanup(session, debugLink) {
|
478 | var table = debugLink ? this.deferedDebugOnRelease : this.deferedNormalOnRelease;
|
479 |
|
480 | if (table[session] != null) {
|
481 | table[session].reject(new Error("Device released or disconnected"));
|
482 | delete table[session];
|
483 | }
|
484 | }
|
485 | }, {
|
486 | key: "configure",
|
487 | value: function () {
|
488 | var _configure = _asyncToGenerator(
|
489 |
|
490 | _regenerator["default"].mark(function _callee6(signedData) {
|
491 | var messages;
|
492 | return _regenerator["default"].wrap(function _callee6$(_context6) {
|
493 | while (1) {
|
494 | switch (_context6.prev = _context6.next) {
|
495 | case 0:
|
496 | messages = (0, _parse_protocol.parseConfigure)(signedData);
|
497 | this._messages = messages;
|
498 | this.configured = true;
|
499 |
|
500 | case 3:
|
501 | case "end":
|
502 | return _context6.stop();
|
503 | }
|
504 | }
|
505 | }, _callee6, this);
|
506 | }));
|
507 |
|
508 | function configure(_x9) {
|
509 | return _configure.apply(this, arguments);
|
510 | }
|
511 |
|
512 | return configure;
|
513 | }()
|
514 | }, {
|
515 | key: "_sendLowlevel",
|
516 | value: function _sendLowlevel(path, debug) {
|
517 | var _this2 = this;
|
518 |
|
519 | return function (data) {
|
520 | return _this2.plugin.send(path, data, debug);
|
521 | };
|
522 | }
|
523 | }, {
|
524 | key: "_receiveLowlevel",
|
525 | value: function _receiveLowlevel(path, debug) {
|
526 | var _this3 = this;
|
527 |
|
528 | return function () {
|
529 | return _this3.plugin.receive(path, debug);
|
530 | };
|
531 | }
|
532 | }, {
|
533 | key: "messages",
|
534 | value: function messages() {
|
535 | if (this._messages == null) {
|
536 | throw new Error("Transport not configured.");
|
537 | }
|
538 |
|
539 | return this._messages;
|
540 | }
|
541 | }, {
|
542 | key: "doWithSession",
|
543 | value: function () {
|
544 | var _doWithSession = _asyncToGenerator(
|
545 |
|
546 | _regenerator["default"].mark(function _callee7(session, debugLink, inside) {
|
547 | var sessionsM, sessionsMM, path_, path, resPromise, defered;
|
548 | return _regenerator["default"].wrap(function _callee7$(_context7) {
|
549 | while (1) {
|
550 | switch (_context7.prev = _context7.next) {
|
551 | case 0:
|
552 | _context7.next = 2;
|
553 | return this.sendToWorker({
|
554 | type: "get-sessions"
|
555 | });
|
556 |
|
557 | case 2:
|
558 | sessionsM = _context7.sent;
|
559 |
|
560 | if (!(sessionsM.type !== "sessions")) {
|
561 | _context7.next = 5;
|
562 | break;
|
563 | }
|
564 |
|
565 | throw new Error("Wrong reply");
|
566 |
|
567 | case 5:
|
568 | sessionsMM = debugLink ? sessionsM.debugSessions : sessionsM.normalSessions;
|
569 | path_ = null;
|
570 | Object.keys(sessionsMM).forEach(function (kpath) {
|
571 | if (sessionsMM[kpath] === session) {
|
572 | path_ = kpath;
|
573 | }
|
574 | });
|
575 |
|
576 | if (!(path_ == null)) {
|
577 | _context7.next = 10;
|
578 | break;
|
579 | }
|
580 |
|
581 | throw new Error("Session not available.");
|
582 |
|
583 | case 10:
|
584 | path = path_;
|
585 | _context7.next = 13;
|
586 | return inside(path);
|
587 |
|
588 | case 13:
|
589 | resPromise = _context7.sent;
|
590 | defered = debugLink ? this.deferedDebugOnRelease[session] : this.deferedNormalOnRelease[session];
|
591 | return _context7.abrupt("return", Promise.race([defered.rejectingPromise, resPromise]));
|
592 |
|
593 | case 16:
|
594 | case "end":
|
595 | return _context7.stop();
|
596 | }
|
597 | }
|
598 | }, _callee7, this);
|
599 | }));
|
600 |
|
601 | function doWithSession(_x10, _x11, _x12) {
|
602 | return _doWithSession.apply(this, arguments);
|
603 | }
|
604 |
|
605 | return doWithSession;
|
606 | }()
|
607 | }, {
|
608 | key: "call",
|
609 | value: function () {
|
610 | var _call = _asyncToGenerator(
|
611 |
|
612 | _regenerator["default"].mark(function _callee9(session, name, data, debugLink) {
|
613 | var _this4 = this;
|
614 |
|
615 | var callInside;
|
616 | return _regenerator["default"].wrap(function _callee9$(_context9) {
|
617 | while (1) {
|
618 | switch (_context9.prev = _context9.next) {
|
619 | case 0:
|
620 | callInside =
|
621 |
|
622 | function () {
|
623 | var _ref = _asyncToGenerator(
|
624 |
|
625 | _regenerator["default"].mark(function _callee8(path) {
|
626 | var messages, message;
|
627 | return _regenerator["default"].wrap(function _callee8$(_context8) {
|
628 | while (1) {
|
629 | switch (_context8.prev = _context8.next) {
|
630 | case 0:
|
631 | messages = _this4.messages();
|
632 | _context8.next = 3;
|
633 | return (0, _send.buildAndSend)(messages, _this4._sendLowlevel(path, debugLink), name, data);
|
634 |
|
635 | case 3:
|
636 | _context8.next = 5;
|
637 | return (0, _receive.receiveAndParse)(messages, _this4._receiveLowlevel(path, debugLink));
|
638 |
|
639 | case 5:
|
640 | message = _context8.sent;
|
641 | return _context8.abrupt("return", message);
|
642 |
|
643 | case 7:
|
644 | case "end":
|
645 | return _context8.stop();
|
646 | }
|
647 | }
|
648 | }, _callee8);
|
649 | }));
|
650 |
|
651 | return function callInside(_x17) {
|
652 | return _ref.apply(this, arguments);
|
653 | };
|
654 | }();
|
655 |
|
656 | return _context9.abrupt("return", this.doWithSession(session, debugLink, callInside));
|
657 |
|
658 | case 2:
|
659 | case "end":
|
660 | return _context9.stop();
|
661 | }
|
662 | }
|
663 | }, _callee9, this);
|
664 | }));
|
665 |
|
666 | function call(_x13, _x14, _x15, _x16) {
|
667 | return _call.apply(this, arguments);
|
668 | }
|
669 |
|
670 | return call;
|
671 | }()
|
672 | }, {
|
673 | key: "post",
|
674 | value: function () {
|
675 | var _post = _asyncToGenerator(
|
676 |
|
677 | _regenerator["default"].mark(function _callee11(session, name, data, debugLink) {
|
678 | var _this5 = this;
|
679 |
|
680 | var callInside;
|
681 | return _regenerator["default"].wrap(function _callee11$(_context11) {
|
682 | while (1) {
|
683 | switch (_context11.prev = _context11.next) {
|
684 | case 0:
|
685 | callInside =
|
686 |
|
687 | function () {
|
688 | var _ref2 = _asyncToGenerator(
|
689 |
|
690 | _regenerator["default"].mark(function _callee10(path) {
|
691 | var messages;
|
692 | return _regenerator["default"].wrap(function _callee10$(_context10) {
|
693 | while (1) {
|
694 | switch (_context10.prev = _context10.next) {
|
695 | case 0:
|
696 | messages = _this5.messages();
|
697 | _context10.next = 3;
|
698 | return (0, _send.buildAndSend)(messages, _this5._sendLowlevel(path, debugLink), name, data);
|
699 |
|
700 | case 3:
|
701 | case "end":
|
702 | return _context10.stop();
|
703 | }
|
704 | }
|
705 | }, _callee10);
|
706 | }));
|
707 |
|
708 | return function callInside(_x22) {
|
709 | return _ref2.apply(this, arguments);
|
710 | };
|
711 | }();
|
712 |
|
713 | return _context11.abrupt("return", this.doWithSession(session, debugLink, callInside));
|
714 |
|
715 | case 2:
|
716 | case "end":
|
717 | return _context11.stop();
|
718 | }
|
719 | }
|
720 | }, _callee11, this);
|
721 | }));
|
722 |
|
723 | function post(_x18, _x19, _x20, _x21) {
|
724 | return _post.apply(this, arguments);
|
725 | }
|
726 |
|
727 | return post;
|
728 | }()
|
729 | }, {
|
730 | key: "read",
|
731 | value: function () {
|
732 | var _read = _asyncToGenerator(
|
733 |
|
734 | _regenerator["default"].mark(function _callee13(session, debugLink) {
|
735 | var _this6 = this;
|
736 |
|
737 | var callInside;
|
738 | return _regenerator["default"].wrap(function _callee13$(_context13) {
|
739 | while (1) {
|
740 | switch (_context13.prev = _context13.next) {
|
741 | case 0:
|
742 | callInside =
|
743 |
|
744 | function () {
|
745 | var _ref3 = _asyncToGenerator(
|
746 |
|
747 | _regenerator["default"].mark(function _callee12(path) {
|
748 | var messages, message;
|
749 | return _regenerator["default"].wrap(function _callee12$(_context12) {
|
750 | while (1) {
|
751 | switch (_context12.prev = _context12.next) {
|
752 | case 0:
|
753 | messages = _this6.messages();
|
754 | _context12.next = 3;
|
755 | return (0, _receive.receiveAndParse)(messages, _this6._receiveLowlevel(path, debugLink));
|
756 |
|
757 | case 3:
|
758 | message = _context12.sent;
|
759 | return _context12.abrupt("return", message);
|
760 |
|
761 | case 5:
|
762 | case "end":
|
763 | return _context12.stop();
|
764 | }
|
765 | }
|
766 | }, _callee12);
|
767 | }));
|
768 |
|
769 | return function callInside(_x25) {
|
770 | return _ref3.apply(this, arguments);
|
771 | };
|
772 | }();
|
773 |
|
774 | return _context13.abrupt("return", this.doWithSession(session, debugLink, callInside));
|
775 |
|
776 | case 2:
|
777 | case "end":
|
778 | return _context13.stop();
|
779 | }
|
780 | }
|
781 | }, _callee13, this);
|
782 | }));
|
783 |
|
784 | function read(_x23, _x24) {
|
785 | return _read.apply(this, arguments);
|
786 | }
|
787 |
|
788 | return read;
|
789 | }()
|
790 | }, {
|
791 | key: "init",
|
792 | value: function () {
|
793 | var _init = _asyncToGenerator(
|
794 |
|
795 | _regenerator["default"].mark(function _callee14(debug) {
|
796 | var _this7 = this;
|
797 |
|
798 | return _regenerator["default"].wrap(function _callee14$(_context14) {
|
799 | while (1) {
|
800 | switch (_context14.prev = _context14.next) {
|
801 | case 0:
|
802 | this.debug = !!debug;
|
803 | this.requestNeeded = this.plugin.requestNeeded;
|
804 | _context14.next = 4;
|
805 | return this.plugin.init(debug);
|
806 |
|
807 | case 4:
|
808 |
|
809 | if (this._sharedWorkerFactory != null) {
|
810 | this.sharedWorker = this._sharedWorkerFactory();
|
811 |
|
812 | if (this.sharedWorker != null) {
|
813 | this.sharedWorker.port.onmessage = function (e) {
|
814 |
|
815 | _this7.receiveFromWorker(e.data);
|
816 | };
|
817 | }
|
818 | }
|
819 |
|
820 | case 5:
|
821 | case "end":
|
822 | return _context14.stop();
|
823 | }
|
824 | }
|
825 | }, _callee14, this);
|
826 | }));
|
827 |
|
828 | function init(_x26) {
|
829 | return _init.apply(this, arguments);
|
830 | }
|
831 |
|
832 | return init;
|
833 | }()
|
834 | }, {
|
835 | key: "requestDevice",
|
836 | value: function () {
|
837 | var _requestDevice = _asyncToGenerator(
|
838 |
|
839 | _regenerator["default"].mark(function _callee15() {
|
840 | return _regenerator["default"].wrap(function _callee15$(_context15) {
|
841 | while (1) {
|
842 | switch (_context15.prev = _context15.next) {
|
843 | case 0:
|
844 | return _context15.abrupt("return", this.plugin.requestDevice());
|
845 |
|
846 | case 1:
|
847 | case "end":
|
848 | return _context15.stop();
|
849 | }
|
850 | }
|
851 | }, _callee15, this);
|
852 | }));
|
853 |
|
854 | function requestDevice() {
|
855 | return _requestDevice.apply(this, arguments);
|
856 | }
|
857 |
|
858 | return requestDevice;
|
859 | }()
|
860 | }, {
|
861 | key: "sendToWorker",
|
862 | value: function sendToWorker(message) {
|
863 | var _this8 = this;
|
864 |
|
865 | if (this.stopped) {
|
866 | return Promise.reject("Transport stopped.");
|
867 | }
|
868 |
|
869 | this.latestId++;
|
870 | var id = this.latestId;
|
871 | this.defereds[id] = (0, _defered.create)();
|
872 |
|
873 | if (this.sharedWorker != null) {
|
874 | this.sharedWorker.port.postMessage({
|
875 | id: id,
|
876 | message: message
|
877 | });
|
878 | } else {
|
879 | (0, _sharedConnectionWorker.postModuleMessage)({
|
880 | id: id,
|
881 | message: message
|
882 | }, function (m) {
|
883 | return _this8.receiveFromWorker(m);
|
884 | });
|
885 | }
|
886 |
|
887 | return this.defereds[id].promise;
|
888 | }
|
889 | }, {
|
890 | key: "receiveFromWorker",
|
891 | value: function receiveFromWorker(m) {
|
892 | this.defereds[m.id].resolve(m.message);
|
893 | delete this.defereds[m.id];
|
894 | }
|
895 | }, {
|
896 | key: "setBridgeLatestUrl",
|
897 | value: function setBridgeLatestUrl(url) {}
|
898 | }, {
|
899 | key: "stop",
|
900 | value: function stop() {
|
901 | this.stopped = true;
|
902 | this.sharedWorker = null;
|
903 | }
|
904 | }]);
|
905 |
|
906 | return LowlevelTransportWithSharedConnections;
|
907 | }(), _temp), (_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, "post", [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, "post"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "read", [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, "read"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "init", [_debugDecorator.debugInOut], Object.getOwnPropertyDescriptor(_class.prototype, "init"), _class.prototype)), _class);
|
908 | exports["default"] = LowlevelTransportWithSharedConnections;
|
909 | module.exports = exports.default; |
\ | No newline at end of file |