mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 12:53:21 +02:00
Integrate new minicap along with a moderate rewrite. What's currently missing is recovering from socket death.
This commit is contained in:
40
lib/units/device/plugins/screen/util/broadcastset.js
Normal file
40
lib/units/device/plugins/screen/util/broadcastset.js
Normal file
@@ -0,0 +1,40 @@
|
||||
var util = require('util')
|
||||
|
||||
var EventEmitter = require('eventemitter3').EventEmitter
|
||||
|
||||
function BroadcastSet() {
|
||||
this.set = Object.create(null)
|
||||
this.count = 0
|
||||
}
|
||||
|
||||
util.inherits(BroadcastSet, EventEmitter)
|
||||
|
||||
BroadcastSet.prototype.insert = function(id, ws) {
|
||||
if (!(id in this.set)) {
|
||||
this.set[id] = ws
|
||||
this.count += 1
|
||||
this.emit('insert', id)
|
||||
if (this.count === 1) {
|
||||
this.emit('nonempty')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BroadcastSet.prototype.remove = function(id) {
|
||||
if (id in this.set) {
|
||||
delete this.set[id]
|
||||
this.count -= 1
|
||||
this.emit('remove', id)
|
||||
if (this.count === 0) {
|
||||
this.emit('empty')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BroadcastSet.prototype.each = function(fn) {
|
||||
return Object.keys(this.set).forEach(function(id) {
|
||||
return fn(this.set[id])
|
||||
}, this)
|
||||
}
|
||||
|
||||
module.exports = BroadcastSet
|
||||
Reference in New Issue
Block a user