mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Only track devices when we need to.
This commit is contained in:
parent
615088edcd
commit
2692f71219
4 changed files with 102 additions and 69 deletions
|
@ -2,5 +2,27 @@ var io = require('socket.io')
|
|||
|
||||
module.exports = function SocketServiceFactory() {
|
||||
var socketService = io.connect()
|
||||
|
||||
socketService.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
|
||||
})
|
||||
socketService.on(event, handler)
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return socketService
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue