angular-websocket
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -14,5 +14,5 @@ ;(function(module, undefined) { | ||
this.url = function(url, protocols) { | ||
this.uri = function(uri, protocols) { | ||
protocols = Array.prototype.slice.call(arguments, 1); | ||
_WebSocket = new WebSocket(url, protocols); | ||
_WebSocket = new WebSocket(uri, protocols); | ||
return this; | ||
@@ -37,4 +37,5 @@ }; | ||
event = event && 'on'+event || 'onmessage'; | ||
return function(eventName, callback) { | ||
ws[event](eventName, asyncAngularify(callback)); | ||
return function(callback) { | ||
ws[event] = asyncAngularify(callback); | ||
return this; | ||
}; | ||
@@ -44,3 +45,5 @@ }; | ||
var wrappedWebSocket = { | ||
on: addListener('message'), | ||
on: function(event) { | ||
return addListener(event); | ||
}, | ||
onmessage: addListener('message'), | ||
@@ -50,16 +53,16 @@ onclose: addListener('close'), | ||
onerror: addListener('error'), | ||
new: function(uri, protocols) { | ||
protocols = Array.prototype.slice.call(arguments, 1); | ||
ws = new WebSocket(url, protocols); | ||
return this; | ||
}, | ||
close: function() { | ||
ws.close(); | ||
return this | ||
}, | ||
send: function(eventName, data, callback) { | ||
if (angular.isObject(eventName)) { | ||
ws.send(eventName); | ||
} else { | ||
if (callback) { | ||
ws.send(eventName, data, asyncAngularify(callback)); | ||
} else { | ||
ws.send(eventName, data); | ||
} | ||
} | ||
send: function(message) { | ||
message = Array.prototype.slice.call(arguments); | ||
ws.send.apply(ws, message); | ||
return this; | ||
}, | ||
@@ -66,0 +69,0 @@ |
{ | ||
"name": "angular-websocket", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/gdi2290/angular-websocket", | ||
@@ -20,4 +20,4 @@ "authors": [ | ||
"dependencies": { | ||
"angular": "~1.2.0" | ||
"angular": "*" | ||
} | ||
} |
{ | ||
"name": "angular-websocket", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "angular-websocket.js", | ||
@@ -5,0 +5,0 @@ "description": "WebSocket service for Angular.js", |
@@ -27,3 +27,3 @@ # Work in progress | ||
.prefix('') | ||
.url('ws://localhost:8080'); | ||
.uri('ws://echo.websocket.org/'); | ||
}); | ||
@@ -38,2 +38,8 @@ | ||
WebSocket.onmessage(function(event) { | ||
console.log('message: ', event.data); | ||
}); | ||
}); | ||
@@ -40,0 +46,0 @@ </script> |
11015
10
167
47