Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 2045716

Browse files
authored
Merge pull request #493 from learn-co/single
Prepare for single websocket connection
2 parents 01dd4e1 + 43f5a9f commit 2045716

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const util = {
1717
defaultConfig: {
1818
host: 'ile.learn.co',
1919
port: 443,
20-
path: 'v2/terminal',
20+
path: 'environment',
2121
learnCo: 'https://learn.co'
2222
},
2323

lib/terminal.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class Terminal {
1818
}
1919

2020
connect(token) {
21-
this.socket = new AtomSocket('term', this.url());
21+
this.socket = new AtomSocket('environment', this.url());
2222

2323
this.waitForSocket = new Promise(((resolve, reject) => {
2424
this.socket.on('open', e => {
@@ -31,8 +31,19 @@ export default class Terminal {
3131
resolve()
3232
})
3333

34-
this.socket.on('message', (msg='') => {
35-
var decoded = new Buffer(msg, 'base64').toString();
34+
this.socket.on('message', (msg) => {
35+
if (msg.slice(2,10) !== 'terminal') { return }
36+
37+
try {
38+
var {terminal} = JSON.parse(msg)
39+
} catch ({message}) {
40+
console.error(`terminal parse error: ${message}`)
41+
return
42+
}
43+
44+
if (terminal == null) { return }
45+
46+
var decoded = new Buffer(terminal, 'base64').toString();
3647
this.emit('message', decoded)
3748
})
3849

@@ -64,14 +75,15 @@ export default class Terminal {
6475
}
6576

6677
send(msg) {
67-
if (this.waitForSocket === null ) {
68-
this.socket.send(msg)
78+
var preparedMessage = JSON.stringify({terminal: msg})
79+
if (this.waitForSocket != null ) {
80+
this.socket.send(preparedMessage)
6981
return
7082
}
7183

7284
this.waitForSocket.then(() => {
7385
this.waitForSocket = null;
74-
this.socket.send(msg);
86+
this.socket.send(preparedMessage);
7587
});
7688
}
7789

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"atom-material-syntax-light": "0.4.6",
3838
"learn-ide-material-ui": "1.3.15",
3939
"learn-ide-notifications": "0.66.5",
40-
"learn-ide-tree": "1.0.23"
40+
"learn-ide-tree": "1.0.24"
4141
},
4242
"devDependencies": {
4343
"decompress": "4.0.0",

0 commit comments

Comments
 (0)