From 2333ec30f61d4023adc67740ab178b9f1b6d237d Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 30 Sep 2016 15:14:12 -0400 Subject: [PATCH] check for auth error --- wsclient.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wsclient.js b/wsclient.js index 18078b9..b6cbda1 100644 --- a/wsclient.js +++ b/wsclient.js @@ -136,13 +136,9 @@ function run(copts) { return Object.keys(localclients).length; } }; - var wsHandlers = { onOpen: function () { console.info("[open] connected to '" + copts.stunneld + "'"); - - var machine = require('tunnel-packer').create(handlers); - wstunneler.on('message', machine.fns.addChunk); } , onClose: function () { @@ -185,11 +181,19 @@ function run(copts) { } } }; + var machine = require('tunnel-packer').create(handlers); console.info("[connect] '" + copts.stunneld + "'"); wstunneler = new WebSocket(tunnelUrl, { rejectUnauthorized: !copts.insecure }); wstunneler.on('open', wsHandlers.onOpen); + wstunneler.on('message', function (data, flags) { + if (data.error || '{' === data[0]) { + console.log(data); + return; + } + machine.fns.addChunk(data, flags); + }); wstunneler.on('close', wsHandlers.onClose); wstunneler.on('error', wsHandlers.onError); process.on('exit', wsHandlers.onExit);