mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
APPSTATE refactoring:
- 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
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
module.exports = angular.module('stf/socket', [
|
||||
//TODO: Refactor version update out to its own Ctrl
|
||||
require('stf/app-state').name,
|
||||
require('stf/common-ui/modals/version-update').name
|
||||
])
|
||||
.factory('socket', require('./socket-service'))
|
||||
|
||||
@@ -1,46 +1,42 @@
|
||||
var io = require('socket.io')
|
||||
|
||||
module.exports = function SocketFactory($rootScope, VersionUpdateService) {
|
||||
/*globals APPSTATE:false*/
|
||||
//TODO: Refactor APPSTATE to AppStateConstant
|
||||
var websocketUrl = APPSTATE && APPSTATE.config &&
|
||||
APPSTATE.config.websocketUrl ? APPSTATE.config.websocketUrl : ''
|
||||
module.exports =
|
||||
function SocketFactory($rootScope, VersionUpdateService, AppState) {
|
||||
var websocketUrl = AppState.config.websocketUrl || ''
|
||||
|
||||
var socket = io(websocketUrl, {
|
||||
reconnection: false
|
||||
, transports: ['websocket']
|
||||
})
|
||||
var socket = io(websocketUrl, {
|
||||
reconnection: false, transports: ['websocket']
|
||||
})
|
||||
|
||||
socket.scoped = function($scope) {
|
||||
var listeners = []
|
||||
socket.scoped = function ($scope) {
|
||||
var listeners = []
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
listeners.forEach(function(listener) {
|
||||
socket.removeListener(listener.event, listener.handler)
|
||||
$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 {
|
||||
on: function(event, handler) {
|
||||
listeners.push({
|
||||
event: event
|
||||
, handler: handler
|
||||
})
|
||||
socket.on(event, handler)
|
||||
return this
|
||||
}
|
||||
}
|
||||
return socket
|
||||
}
|
||||
|
||||
socket.on('outdated', function () {
|
||||
VersionUpdateService.open()
|
||||
})
|
||||
|
||||
socket.on('socket.ip', function(ip) {
|
||||
$rootScope.$apply(function() {
|
||||
socket.ip = ip
|
||||
})
|
||||
})
|
||||
|
||||
return socket
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user