1 | "use strict";
|
2 |
|
3 |
|
4 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
5 | if (k2 === undefined) k2 = k;
|
6 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
7 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
8 | desc = { enumerable: true, get: function() { return m[k]; } };
|
9 | }
|
10 | Object.defineProperty(o, k2, desc);
|
11 | }) : (function(o, m, k, k2) {
|
12 | if (k2 === undefined) k2 = k;
|
13 | o[k2] = m[k];
|
14 | }));
|
15 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
16 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
17 | }) : function(o, v) {
|
18 | o["default"] = v;
|
19 | });
|
20 | var __importStar = (this && this.__importStar) || function (mod) {
|
21 | if (mod && mod.__esModule) return mod;
|
22 | var result = {};
|
23 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
24 | __setModuleDefault(result, mod);
|
25 | return result;
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | exports.CommHandler = void 0;
|
29 | const disposable_1 = require("@lumino/disposable");
|
30 | const KernelMessage = __importStar(require("./messages"));
|
31 |
|
32 |
|
33 |
|
34 | class CommHandler extends disposable_1.DisposableDelegate {
|
35 | |
36 |
|
37 |
|
38 | constructor(target, id, kernel, disposeCb) {
|
39 | super(disposeCb);
|
40 | this._target = '';
|
41 | this._id = '';
|
42 | this._id = id;
|
43 | this._target = target;
|
44 | this._kernel = kernel;
|
45 | }
|
46 | |
47 |
|
48 |
|
49 | get commId() {
|
50 | return this._id;
|
51 | }
|
52 | |
53 |
|
54 |
|
55 | get targetName() {
|
56 | return this._target;
|
57 | }
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | get onClose() {
|
67 | return this._onClose;
|
68 | }
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | set onClose(cb) {
|
81 | this._onClose = cb;
|
82 | }
|
83 | |
84 |
|
85 |
|
86 | get onMsg() {
|
87 | return this._onMsg;
|
88 | }
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | set onMsg(cb) {
|
97 | this._onMsg = cb;
|
98 | }
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | open(data, metadata, buffers = []) {
|
108 | if (this.isDisposed || this._kernel.isDisposed) {
|
109 | throw new Error('Cannot open');
|
110 | }
|
111 | const msg = KernelMessage.createMessage({
|
112 | msgType: 'comm_open',
|
113 | channel: 'shell',
|
114 | username: this._kernel.username,
|
115 | session: this._kernel.clientId,
|
116 | content: {
|
117 | comm_id: this._id,
|
118 | target_name: this._target,
|
119 | data: data !== null && data !== void 0 ? data : {}
|
120 | },
|
121 | metadata,
|
122 | buffers
|
123 | });
|
124 | return this._kernel.sendShellMessage(msg, false, true);
|
125 | }
|
126 | |
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | send(data, metadata, buffers = [], disposeOnDone = true) {
|
135 | if (this.isDisposed || this._kernel.isDisposed) {
|
136 | throw new Error('Cannot send');
|
137 | }
|
138 | const msg = KernelMessage.createMessage({
|
139 | msgType: 'comm_msg',
|
140 | channel: 'shell',
|
141 | username: this._kernel.username,
|
142 | session: this._kernel.clientId,
|
143 | content: {
|
144 | comm_id: this._id,
|
145 | data: data
|
146 | },
|
147 | metadata,
|
148 | buffers
|
149 | });
|
150 | return this._kernel.sendShellMessage(msg, false, disposeOnDone);
|
151 | }
|
152 | |
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | close(data, metadata, buffers = []) {
|
164 | if (this.isDisposed || this._kernel.isDisposed) {
|
165 | throw new Error('Cannot close');
|
166 | }
|
167 | const msg = KernelMessage.createMessage({
|
168 | msgType: 'comm_close',
|
169 | channel: 'shell',
|
170 | username: this._kernel.username,
|
171 | session: this._kernel.clientId,
|
172 | content: {
|
173 | comm_id: this._id,
|
174 | data: data !== null && data !== void 0 ? data : {}
|
175 | },
|
176 | metadata,
|
177 | buffers
|
178 | });
|
179 | const future = this._kernel.sendShellMessage(msg, false, true);
|
180 | const onClose = this._onClose;
|
181 | if (onClose) {
|
182 | const ioMsg = KernelMessage.createMessage({
|
183 | msgType: 'comm_close',
|
184 | channel: 'iopub',
|
185 | username: this._kernel.username,
|
186 | session: this._kernel.clientId,
|
187 | content: {
|
188 | comm_id: this._id,
|
189 | data: data !== null && data !== void 0 ? data : {}
|
190 | },
|
191 | metadata,
|
192 | buffers
|
193 | });
|
194 |
|
195 |
|
196 | void onClose(ioMsg);
|
197 | }
|
198 | this.dispose();
|
199 | return future;
|
200 | }
|
201 | }
|
202 | exports.CommHandler = CommHandler;
|
203 |
|
\ | No newline at end of file |