mirror of
https://github.com/openstf/stf
synced 2025-10-06 03:50:04 +02:00

- Make index.html cacheable by being stateless - Improve compression (base64 doesn't gzip well) - Remove base64 encoding/decoding step - Make AppState injectable so it can be unit tested - Ready to remove the global leakage
42 lines
965 B
JavaScript
42 lines
965 B
JavaScript
var io = require('socket.io')
|
|
|
|
module.exports =
|
|
function SocketFactory($rootScope, VersionUpdateService, AppState) {
|
|
var websocketUrl = AppState.config.websocketUrl || ''
|
|
|
|
var socket = io(websocketUrl, {
|
|
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
|
|
}
|