Displays buffer content in main window
Handles the weechat _buffer_line_added event and displays every new line in the main buffer.
This commit is contained in:
parent
4bebd3af79
commit
0df3112d8d
3 changed files with 36 additions and 13 deletions
|
@ -23,9 +23,6 @@ var Protocol = function() {
|
||||||
return key.split(':');
|
return key.split(':');
|
||||||
});
|
});
|
||||||
var i;
|
var i;
|
||||||
console.log("Keys: ", keys);
|
|
||||||
console.log("Paths: ", paths);
|
|
||||||
console.log("Count: ", count);
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
var tmp = {};
|
var tmp = {};
|
||||||
|
|
||||||
|
@ -33,8 +30,6 @@ var Protocol = function() {
|
||||||
return getPointer();
|
return getPointer();
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Pointers: ", tmp.pointers);
|
|
||||||
|
|
||||||
keys.forEach(function(key) {
|
keys.forEach(function(key) {
|
||||||
tmp[key[0]] = runType(key[1]);
|
tmp[key[0]] = runType(key[1]);
|
||||||
});
|
});
|
||||||
|
@ -45,7 +40,7 @@ var Protocol = function() {
|
||||||
|
|
||||||
function getPointer() {
|
function getPointer() {
|
||||||
var l = getChar();
|
var l = getChar();
|
||||||
console.log("Length: ", l);
|
|
||||||
var pointer = getSlice(l)
|
var pointer = getSlice(l)
|
||||||
var parsed_data = new Uint8Array(pointer);
|
var parsed_data = new Uint8Array(pointer);
|
||||||
return _uiatos(parsed_data);
|
return _uiatos(parsed_data);
|
||||||
|
@ -122,7 +117,7 @@ var Protocol = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.parse = function() {
|
self.parse = function() {
|
||||||
console.log(new Uint8Array(self.data));
|
|
||||||
var header = getHeader();
|
var header = getHeader();
|
||||||
var id = getId();
|
var id = getId();
|
||||||
var objects = [];
|
var objects = [];
|
||||||
|
|
|
@ -25,18 +25,23 @@ weechat.factory('connection', ['$rootScope', function($scope) {
|
||||||
$scope.connected = true;
|
$scope.connected = true;
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
websocket.onclose = function (evt) {
|
websocket.onclose = function (evt) {
|
||||||
console.log("disconnected", "Disconnected");
|
console.log("disconnected", "Disconnected");
|
||||||
$scope.connected = false;
|
$scope.connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
websocket.onmessage = function (evt) {
|
websocket.onmessage = function (evt) {
|
||||||
console.log("recv", "⇒ " + evt.data);
|
|
||||||
protocol.setData(evt.data);
|
protocol.setData(evt.data);
|
||||||
console.log(protocol.parse());
|
message = protocol.parse()
|
||||||
|
console.log(evt);
|
||||||
$scope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type) ;
|
$scope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type) ;
|
||||||
|
parseMessage(message);
|
||||||
data = evt.data;
|
data = evt.data;
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
websocket.onerror = function (evt) {
|
websocket.onerror = function (evt) {
|
||||||
console.log("error", "ERROR: " + evt.data);
|
console.log("error", "ERROR: " + evt.data);
|
||||||
}
|
}
|
||||||
|
@ -44,10 +49,31 @@ weechat.factory('connection', ['$rootScope', function($scope) {
|
||||||
this.websocket = websocket;
|
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) {
|
var sendMessage = function(message) {
|
||||||
message = message + "\n"
|
message = message + "\n"
|
||||||
doSend(message);
|
doSend(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var types = {
|
||||||
|
_buffer_line_added: handleBufferLineAdded
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connect: connect,
|
connect: connect,
|
||||||
sendMessage: sendMessage
|
sendMessage: sendMessage
|
||||||
|
@ -57,6 +83,8 @@ weechat.factory('connection', ['$rootScope', function($scope) {
|
||||||
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', 'connection', function ($rootScope, $scope, connection) {
|
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', 'connection', function ($rootScope, $scope, connection) {
|
||||||
$rootScope.commands = []
|
$rootScope.commands = []
|
||||||
|
|
||||||
|
$rootScope.buffer = []
|
||||||
|
|
||||||
$scope.hostport = "localhost:9001"
|
$scope.hostport = "localhost:9001"
|
||||||
$scope.proto = "weechat"
|
$scope.proto = "weechat"
|
||||||
$scope.password = ""
|
$scope.password = ""
|
||||||
|
|
|
@ -37,8 +37,8 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div ng-show="connected">
|
<div ng-show="connected">
|
||||||
<div ng-repeat="command in commands">
|
<div ng-repeat="bufferline in buffer">
|
||||||
{{ command }}
|
{{ bufferline }}
|
||||||
</div>
|
</div>
|
||||||
<form ng-submit="sendMessage()">
|
<form ng-submit="sendMessage()">
|
||||||
<input type="text" ng-model="command"></input>
|
<input type="text" ng-model="command"></input>
|
||||||
|
|
Loading…
Reference in a new issue