From e68e7dd01d2b3e19717e22cc73805ccbb29c1761 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Fri, 14 Feb 2014 09:09:09 -0500 Subject: [PATCH] websockets: add support for user specified onmessage --- js/glowingbear.js | 2 +- js/websockets.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 5567de4..6ae219e 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -338,13 +338,13 @@ function($rootScope, return '(' + id + ') ' + message; }; + ngWebsockets.connect(url, protocol, { 'binaryType': "arraybuffer", 'onopen': onopen, 'onclose': onclose, - 'onmessage': onmessage, 'onerror': onerror, }); diff --git a/js/websockets.js b/js/websockets.js index be989b9..bdcf949 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -108,7 +108,6 @@ function($rootScope, $q) { } $rootScope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type); $rootScope.$apply(); - }; var connect = function(url, @@ -121,7 +120,14 @@ function($rootScope, $q) { ws[property] = properties[property]; } - ws.onmessage = onmessage; + if ('onmessage' in properties) { + ws.onmessage = function(event) { + properties['onmessage'](event); + onmessage(event); + } + } else { + ws.onmessage = onmessage; + } }; var disconnect = function() {