1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
11 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | const stagehand_1 = __importDefault(require("./stagehand"));
|
15 | const STAGEHAND_INSTANCE = '--stagehand-instance';
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function launch(endpoint, implementation) {
|
22 | return __awaiter(this, void 0, void 0, function* () {
|
23 | let stagehand = new stagehand_1.default(implementation);
|
24 | stagehand.listen(endpoint);
|
25 | return stagehand;
|
26 | });
|
27 | }
|
28 | exports.launch = launch;
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function connect(endpoint) {
|
38 | return __awaiter(this, void 0, void 0, function* () {
|
39 | let stagehand = new stagehand_1.default();
|
40 | let { name, methods } = yield stagehand.connect(endpoint);
|
41 | class StagehandRemote {
|
42 | }
|
43 | for (let method of methods) {
|
44 | Object.defineProperty(StagehandRemote.prototype, method, {
|
45 | value: (...args) => stagehand.call(method, args)
|
46 | });
|
47 | }
|
48 | Object.defineProperty(StagehandRemote.prototype, STAGEHAND_INSTANCE, { value: stagehand });
|
49 | Object.defineProperty(StagehandRemote, 'name', { value: `StagehandRemote<${name}>` });
|
50 | return new StagehandRemote();
|
51 | });
|
52 | }
|
53 | exports.connect = connect;
|
54 |
|
55 |
|
56 |
|
57 | function disconnect(remote) {
|
58 | remote[STAGEHAND_INSTANCE].disconnect();
|
59 | }
|
60 | exports.disconnect = disconnect;
|