|
1 | | -import * as dnode from 'dnode'; |
2 | | -import * as net from 'net'; |
3 | 1 | import * as path from 'path'; |
4 | 2 | import * as os from 'os'; |
5 | 3 | import * as readline from 'readline'; |
6 | 4 | import * as ssh2 from 'ssh2'; |
7 | 5 | import * as ssh2Streams from 'ssh2-streams'; |
8 | | -import * as stream from 'stream'; |
9 | 6 | import * as vscode from 'vscode'; |
10 | 7 | import * as Observable from 'zen-observable'; |
11 | 8 |
|
12 | 9 | import { Brickd } from './brickd'; |
13 | 10 | import * as dnssd from './dnssd'; |
14 | | -import { Shell } from './native-helper/shell'; |
15 | 11 |
|
16 | 12 | /** |
17 | 13 | * Object that represents a remote ev3dev device. |
18 | 14 | */ |
19 | 15 | export class Device extends vscode.Disposable { |
20 | 16 | private readonly client: ssh2.Client; |
21 | 17 | private sftp?: ssh2.SFTPWrapper; |
22 | | - private shellServer?: net.Server; |
23 | 18 | private _homeDirectoryAttr?: ssh2Streams.Attributes; |
24 | 19 | private _isConnecting = false; |
25 | 20 | private _isConnected = false; |
@@ -92,7 +87,6 @@ export class Device extends vscode.Disposable { |
92 | 87 | try { |
93 | 88 | this.sftp = await this.getSftp(); |
94 | 89 | this._homeDirectoryAttr = await this.stat(this.homeDirectoryPath); |
95 | | - this.shellServer = await this.createServer(); |
96 | 90 | this._isConnecting = false; |
97 | 91 | this._isConnected = true; |
98 | 92 | this._onDidConnect.fire(); |
@@ -152,64 +146,11 @@ export class Device extends vscode.Disposable { |
152 | 146 | }); |
153 | 147 | } |
154 | 148 |
|
155 | | - private createServer(): Promise<net.Server> { |
156 | | - return new Promise((resolve, reject) => { |
157 | | - const server = net.createServer(socket => { |
158 | | - const d = dnode<Shell>({ |
159 | | - shell: (ttySettings, dataOut, dataErr, ready, exit) => { |
160 | | - this.shell(ttySettings).then(ch => { |
161 | | - (<stream.Readable>ch.stdout).on('data', data => { |
162 | | - dataOut(data.toString('base64')); |
163 | | - }); |
164 | | - ch.stderr.on('data', data => { |
165 | | - dataErr((<Buffer> data).toString('base64')); |
166 | | - }); |
167 | | - ch.on('error', (err: any) => { |
168 | | - vscode.window.showErrorMessage(`SSH connection error: ${err.message}`); |
169 | | - exit(); |
170 | | - ch.destroy(); |
171 | | - d.destroy(); |
172 | | - }); |
173 | | - ch.on('close', () => { |
174 | | - exit(); |
175 | | - ch.destroy(); |
176 | | - d.destroy(); |
177 | | - }); |
178 | | - ready((rows, cols) => { |
179 | | - // resize callback |
180 | | - ch.setWindow(rows, cols, 0, 0); |
181 | | - }, data => { |
182 | | - // dataIn callback |
183 | | - ch.stdin.write(Buffer.from(data, 'base64')); |
184 | | - }); |
185 | | - }); |
186 | | - } |
187 | | - }, { |
188 | | - // weak requires native module, which we can't use in vscode |
189 | | - weak: false |
190 | | - }); |
191 | | - socket.on('error', err => { |
192 | | - // TODO: not sure what to do here. |
193 | | - // The default dnode implementation only ignores EPIPE. |
194 | | - // On Windows, we can also get ECONNRESET when a client disconnects. |
195 | | - }); |
196 | | - socket.pipe(d).pipe(socket); |
197 | | - }); |
198 | | - server.listen(0, '127.0.0.1'); |
199 | | - server.once('listening', () => resolve(server)); |
200 | | - server.once('error', reject); |
201 | | - }); |
202 | | - } |
203 | | - |
204 | 149 | /** |
205 | 150 | * Disconnect from the device. |
206 | 151 | */ |
207 | 152 | public disconnect(): void { |
208 | 153 | this._isConnected = false; |
209 | | - if (this.shellServer) { |
210 | | - this.shellServer.close(); |
211 | | - this.shellServer = undefined; |
212 | | - } |
213 | 154 | if (this.sftp) { |
214 | 155 | this.sftp.end(); |
215 | 156 | this.sftp = undefined; |
@@ -256,16 +197,6 @@ export class Device extends vscode.Disposable { |
256 | 197 | return this.service.txt['ev3dev.robot.home'] || `/home/${this.username}`; |
257 | 198 | } |
258 | 199 |
|
259 | | - /** |
260 | | - * Gets the TCP port where the shell server is listening. |
261 | | - */ |
262 | | - public get shellPort(): number { |
263 | | - if (!this.shellServer) { |
264 | | - throw new Error('Not connected'); |
265 | | - } |
266 | | - return this.shellServer.address().port; |
267 | | - } |
268 | | - |
269 | 200 | /** |
270 | 201 | * Sets file permissions. |
271 | 202 | * @param path The path to a file or directory |
|
0 commit comments