diff --git a/js/protocol.js b/js/protocol.js index 603b447..0251063 100644 --- a/js/protocol.js +++ b/js/protocol.js @@ -23,9 +23,6 @@ var Protocol = function() { return key.split(':'); }); var i; - console.log("Keys: ", keys); - console.log("Paths: ", paths); - console.log("Count: ", count); for (i = 0; i < count; i++) { var tmp = {}; @@ -33,8 +30,6 @@ var Protocol = function() { return getPointer(); }); - console.log("Pointers: ", tmp.pointers); - keys.forEach(function(key) { tmp[key[0]] = runType(key[1]); }); @@ -45,7 +40,7 @@ var Protocol = function() { function getPointer() { var l = getChar(); - console.log("Length: ", l); + var pointer = getSlice(l) var parsed_data = new Uint8Array(pointer); return _uiatos(parsed_data); @@ -122,7 +117,7 @@ var Protocol = function() { } self.parse = function() { - console.log(new Uint8Array(self.data)); + var header = getHeader(); var id = getId(); var objects = []; diff --git a/js/websockets.js b/js/websockets.js index 91fad14..f009018 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -25,18 +25,23 @@ weechat.factory('connection', ['$rootScope', function($scope) { $scope.connected = true; $scope.$apply(); } + websocket.onclose = function (evt) { console.log("disconnected", "Disconnected"); $scope.connected = false; } + websocket.onmessage = function (evt) { - console.log("recv", "⇒ " + evt.data); - protocol.setData(evt.data); - console.log(protocol.parse()); + protocol.setData(evt.data); + message = protocol.parse() + console.log(evt); $scope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type) ; - data = evt.data; + parseMessage(message); + data = evt.data; $scope.$apply(); } + + websocket.onerror = function (evt) { console.log("error", "ERROR: " + evt.data); } @@ -44,10 +49,31 @@ weechat.factory('connection', ['$rootScope', function($scope) { this.websocket = websocket; } + var parseMessage = function(message) { + console.log(message['id']); + if (message['id'] == '_buffer_line_added') { + types[message['id']](message); + } + console.log(message); + + } + + + + var handleBufferLineAdded = function(message) { + var buffer_line = message['objects'][0]['content'][0]['message']; + $scope.buffer.push(buffer_line); + } + var sendMessage = function(message) { message = message + "\n" doSend(message); } + + var types = { + _buffer_line_added: handleBufferLineAdded + } + return { connect: connect, sendMessage: sendMessage @@ -57,6 +83,8 @@ weechat.factory('connection', ['$rootScope', function($scope) { weechat.controller('WeechatCtrl', ['$rootScope', '$scope', 'connection', function ($rootScope, $scope, connection) { $rootScope.commands = [] + $rootScope.buffer = [] + $scope.hostport = "localhost:9001" $scope.proto = "weechat" $scope.password = "" diff --git a/websockets.html b/websockets.html index 855727f..e2fd958 100644 --- a/websockets.html +++ b/websockets.html @@ -37,8 +37,8 @@