|
@@ -1,7 +1,8 @@
|
|
angular.module('chatServices', [])
|
|
angular.module('chatServices', [])
|
|
-.factory('Connection', function($rootScope, $timeout) {
|
|
|
|
|
|
+.factory('Connection', function($rootScope, $timeout, $interval) {
|
|
var WS = window['MozWebSocket'] ? MozWebSocket : WebSocket;
|
|
var WS = window['MozWebSocket'] ? MozWebSocket : WebSocket;
|
|
var chatSocket = null;
|
|
var chatSocket = null;
|
|
|
|
+ var ping = null;
|
|
|
|
|
|
var service = {
|
|
var service = {
|
|
username: '',
|
|
username: '',
|
|
@@ -28,15 +29,21 @@ angular.module('chatServices', [])
|
|
chatSocket = new WS(jsRoutes.controllers.Application.chat(username).webSocketURL());
|
|
chatSocket = new WS(jsRoutes.controllers.Application.chat(username).webSocketURL());
|
|
chatSocket.onmessage = wrap(function(event) {
|
|
chatSocket.onmessage = wrap(function(event) {
|
|
var message = JSON.parse(event.data);
|
|
var message = JSON.parse(event.data);
|
|
- $rootScope.$broadcast('ws:message', message);
|
|
|
|
|
|
+ if(message.kind != "pong") {
|
|
|
|
+ $rootScope.$broadcast('ws:message', message);
|
|
|
|
+ }
|
|
});
|
|
});
|
|
chatSocket.onopen = wrap(function() {
|
|
chatSocket.onopen = wrap(function() {
|
|
$rootScope.$broadcast('ws:connected', username);
|
|
$rootScope.$broadcast('ws:connected', username);
|
|
service.username = username;
|
|
service.username = username;
|
|
|
|
+ ping = $interval(function() {
|
|
|
|
+ service.send('/ping');
|
|
|
|
+ }, 60000, 0, false);
|
|
});
|
|
});
|
|
chatSocket.onclose = wrap(function() {
|
|
chatSocket.onclose = wrap(function() {
|
|
$rootScope.$broadcast('ws:disconnected');
|
|
$rootScope.$broadcast('ws:disconnected');
|
|
service.username = '';
|
|
service.username = '';
|
|
|
|
+ $interval.cancel(ping);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|