Skip to content

Commit faa83c8

Browse files
committed
updated: code
1 parent 81bf6ba commit faa83c8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

angularjs-websocket/app/services/websocketService.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ app.factory('websocketService', ['$rootScope', '$timeout', function($rootScope,
2323
return {
2424

2525
login: function(url, username) {
26+
27+
_username = username;
28+
2629
_ws = new WebSocket(url);
2730
_ws.onmessage = onMessage;
28-
_username = username;
29-
$timeout(function() {
31+
_ws.onopen = function () {
3032
_ws.send(encodeURIComponent(JSON.stringify({ type: 'change', message: _username })));
31-
}, 500);
33+
};
34+
3235
},
3336

3437
logoff: function() {

0 commit comments

Comments
 (0)