From 81054f06bde908ef9e98e6307a0b0fd60f370521 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sun, 9 Feb 2014 19:06:30 -0500 Subject: [PATCH] Move specific weechat websocket manipulation in glowingbear.js --- js/glowingbear.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 2ee76c0..fbf462a 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -206,16 +206,38 @@ weechat.factory('connection', 'handlers', 'models', 'ngWebsockets', - function($rootScope, - $log, - storage, - handlers, - models, - ngWebsockets) { - +function($rootScope, + $log, + storage, + handlers, + models, + ngWebsockets) { + protocol = new weeChat.Protocol(); // Takes care of the connection and websocket hooks + + var _formatForWs = function(message) { + /* + * Formats a weechat message to be sent over + * the websocket. + */ + message.replace(/[\r\n]+$/g, "").split("\n"); + return message; + }; + + var _send = function(message) { + return ngWebsockets.send(_formatForWs(message)); + }; + + var _sendAll = function(messages) { + for (var i in messages) { + messages[i] = _formatForWs(messages[i]); + } + return ngWebsockets.sendAll(messages); + }; + + var connect = function (host, port, passwd, ssl, noCompression) { var proto = ssl ? 'wss' : 'ws'; var url = proto + "://" + host + ":" + port + "/weechat";