mirror of
https://github.com/openstf/stf
synced 2025-10-03 17:59:28 +02:00
41 lines
831 B
JavaScript
41 lines
831 B
JavaScript
var io = require('socket.io')
|
|
|
|
module.exports = function SocketFactory($rootScope, VersionUpdateService) {
|
|
var socket = io('/', {
|
|
reconnection: false
|
|
, transports: ['websocket']
|
|
})
|
|
|
|
socket.scoped = function($scope) {
|
|
var listeners = []
|
|
|
|
$scope.$on('$destroy', function() {
|
|
listeners.forEach(function(listener) {
|
|
socket.removeListener(listener.event, listener.handler)
|
|
})
|
|
})
|
|
|
|
return {
|
|
on: function(event, handler) {
|
|
listeners.push({
|
|
event: event
|
|
, handler: handler
|
|
})
|
|
socket.on(event, handler)
|
|
return this
|
|
}
|
|
}
|
|
}
|
|
|
|
socket.on('outdated', function () {
|
|
VersionUpdateService.open()
|
|
})
|
|
|
|
socket.on('socket.ip', function(ip) {
|
|
$rootScope.$apply(function() {
|
|
socket.ip = ip
|
|
})
|
|
})
|
|
|
|
return socket
|
|
}
|