Skip to content

Commit be6eca6

Browse files
committed
update websocket send for angular
1 parent 0446e98 commit be6eca6

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

angular-websocket.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,9 @@ module.provider('WebSocket', function() {
5757
return this
5858
},
5959

60-
send: function(eventName, data, callback) {
61-
if (angular.isObject(eventName)) {
62-
ws.send(eventName);
63-
} else {
64-
if (callback) {
65-
ws.send(eventName, data, asyncAngularify(callback));
66-
} else if (data) {
67-
ws.send(eventName, data);
68-
} else {
69-
ws.send(eventName);
70-
}
71-
}
60+
send: function(message) {
61+
message = Array.prototype.slice.call(arguments);
62+
ws.send.apply(ws, message);
7263
return this;
7364
},
7465

example/index.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ <h2>WebSocket Test</h2>
3131
$scope.messages = MessagesService.get();
3232
$scope.status = TestWebSocket.status();
3333

34-
WebSocket.onopen(function() {
35-
console.log('connection');
36-
});
37-
WebSocket.send('Hello World');
3834
WebSocket.onmessage(function(event) {
3935
console.log('message: ', event);
4036
});
41-
37+
WebSocket.onclose(function() {
38+
console.log('closed connection');
39+
});
40+
WebSocket.onopen(function() {
41+
console.log('connection');
42+
WebSocket.send('Hello World');
43+
});
4244

4345
})
4446
.factory('MessagesService', function($q) {

0 commit comments

Comments
 (0)