diff --git a/lib/config.js b/lib/config.js index cb1b3f7..a8b91bc 100644 --- a/lib/config.js +++ b/lib/config.js @@ -17,7 +17,7 @@ const util = { defaultConfig: { host: 'ile.learn.co', port: 443, - path: 'v2/terminal', + path: 'environment', learnCo: 'https://learn.co' }, diff --git a/lib/terminal.js b/lib/terminal.js index 0ca658c..3489337 100644 --- a/lib/terminal.js +++ b/lib/terminal.js @@ -18,7 +18,7 @@ export default class Terminal { } connect(token) { - this.socket = new AtomSocket('term', this.url()); + this.socket = new AtomSocket('environment', this.url()); this.waitForSocket = new Promise(((resolve, reject) => { this.socket.on('open', e => { @@ -31,8 +31,19 @@ export default class Terminal { resolve() }) - this.socket.on('message', (msg='') => { - var decoded = new Buffer(msg, 'base64').toString(); + this.socket.on('message', (msg) => { + if (msg.slice(2,10) !== 'terminal') { return } + + try { + var {terminal} = JSON.parse(msg) + } catch ({message}) { + console.error(`terminal parse error: ${message}`) + return + } + + if (terminal == null) { return } + + var decoded = new Buffer(terminal, 'base64').toString(); this.emit('message', decoded) }) @@ -64,14 +75,15 @@ export default class Terminal { } send(msg) { - if (this.waitForSocket === null ) { - this.socket.send(msg) + var preparedMessage = JSON.stringify({terminal: msg}) + if (this.waitForSocket != null ) { + this.socket.send(preparedMessage) return } this.waitForSocket.then(() => { this.waitForSocket = null; - this.socket.send(msg); + this.socket.send(preparedMessage); }); } diff --git a/package.json b/package.json index 71e99a8..90d2945 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "atom-material-syntax-light": "0.4.6", "learn-ide-material-ui": "1.3.15", "learn-ide-notifications": "0.66.5", - "learn-ide-tree": "1.0.23" + "learn-ide-tree": "1.0.24" }, "devDependencies": { "decompress": "4.0.0",