mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
VNC screen is visible (w/ RAW encoding). Size of VNC screen is still
hardcoded, preventing real use.
This commit is contained in:
@@ -443,7 +443,7 @@ module.exports = syrup.serial()
|
||||
|
||||
return createServer()
|
||||
.then(function(wss) {
|
||||
var broadcastSet = new BroadcastSet()
|
||||
var broadcastSet = plugin.broadcastSet = new BroadcastSet()
|
||||
var frameProducer = new FrameProducer(
|
||||
new FrameConfig(display.properties, display.properties))
|
||||
|
||||
@@ -460,32 +460,8 @@ module.exports = syrup.serial()
|
||||
})
|
||||
|
||||
frameProducer.on('start', function() {
|
||||
var message = util.format(
|
||||
'start %s'
|
||||
, JSON.stringify(frameProducer.banner)
|
||||
)
|
||||
|
||||
broadcastSet.keys().forEach(function(id) {
|
||||
var ws = broadcastSet.get(id)
|
||||
switch (ws.readyState) {
|
||||
case WebSocket.OPENING:
|
||||
// This should never happen.
|
||||
log.warn('Unable to send banner to OPENING client "%s"', id)
|
||||
break
|
||||
case WebSocket.OPEN:
|
||||
// This is what SHOULD happen.
|
||||
ws.send(message)
|
||||
break
|
||||
case WebSocket.CLOSING:
|
||||
// Ok, a 'close' event should remove the client from the set
|
||||
// soon.
|
||||
break
|
||||
case WebSocket.CLOSED:
|
||||
// This should never happen.
|
||||
log.warn('Unable to send banner to CLOSED client "%s"', id)
|
||||
broadcastSet.remove(id)
|
||||
break
|
||||
}
|
||||
broadcastSet.keys().map(function(id) {
|
||||
return broadcastSet.get(id).onStart(frameProducer)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -493,32 +469,7 @@ module.exports = syrup.serial()
|
||||
var frame
|
||||
if ((frame = frameProducer.nextFrame())) {
|
||||
Promise.settle([broadcastSet.keys().map(function(id) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var ws = broadcastSet.get(id)
|
||||
switch (ws.readyState) {
|
||||
case WebSocket.OPENING:
|
||||
// This should never happen.
|
||||
return reject(new Error(util.format(
|
||||
'Unable to send frame to OPENING client "%s"', id)))
|
||||
case WebSocket.OPEN:
|
||||
// This is what SHOULD happen.
|
||||
ws.send(frame, {
|
||||
binary: true
|
||||
}, function(err) {
|
||||
return err ? reject(err) : resolve()
|
||||
})
|
||||
return
|
||||
case WebSocket.CLOSING:
|
||||
// Ok, a 'close' event should remove the client from the set
|
||||
// soon.
|
||||
return
|
||||
case WebSocket.CLOSED:
|
||||
// This should never happen.
|
||||
broadcastSet.remove(id)
|
||||
return reject(new Error(util.format(
|
||||
'Unable to send frame to CLOSED client "%s"', id)))
|
||||
}
|
||||
})
|
||||
return broadcastSet.get(id).onFrame(frame)
|
||||
})]).then(next)
|
||||
}
|
||||
else {
|
||||
@@ -534,12 +485,74 @@ module.exports = syrup.serial()
|
||||
wss.on('connection', function(ws) {
|
||||
var id = uuid.v4()
|
||||
|
||||
function wsStartNotifier() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var message = util.format(
|
||||
'start %s'
|
||||
, JSON.stringify(frameProducer.banner)
|
||||
)
|
||||
|
||||
switch (ws.readyState) {
|
||||
case WebSocket.OPENING:
|
||||
// This should never happen.
|
||||
log.warn('Unable to send banner to OPENING client "%s"', id)
|
||||
break
|
||||
case WebSocket.OPEN:
|
||||
// This is what SHOULD happen.
|
||||
ws.send(message, function(err) {
|
||||
return err ? reject(err) : resolve()
|
||||
})
|
||||
break
|
||||
case WebSocket.CLOSING:
|
||||
// Ok, a 'close' event should remove the client from the set
|
||||
// soon.
|
||||
break
|
||||
case WebSocket.CLOSED:
|
||||
// This should never happen.
|
||||
log.warn('Unable to send banner to CLOSED client "%s"', id)
|
||||
broadcastSet.remove(id)
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function wsFrameNotifier(frame) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
switch (ws.readyState) {
|
||||
case WebSocket.OPENING:
|
||||
// This should never happen.
|
||||
return reject(new Error(util.format(
|
||||
'Unable to send frame to OPENING client "%s"', id)))
|
||||
case WebSocket.OPEN:
|
||||
// This is what SHOULD happen.
|
||||
ws.send(frame, {
|
||||
binary: true
|
||||
}, function(err) {
|
||||
return err ? reject(err) : resolve()
|
||||
})
|
||||
return
|
||||
case WebSocket.CLOSING:
|
||||
// Ok, a 'close' event should remove the client from the set
|
||||
// soon.
|
||||
return
|
||||
case WebSocket.CLOSED:
|
||||
// This should never happen.
|
||||
broadcastSet.remove(id)
|
||||
return reject(new Error(util.format(
|
||||
'Unable to send frame to CLOSED client "%s"', id)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ws.on('message', function(data) {
|
||||
var match
|
||||
if ((match = /^(on|off|(size) ([0-9]+)x([0-9]+))$/.exec(data))) {
|
||||
switch (match[2] || match[1]) {
|
||||
case 'on':
|
||||
broadcastSet.insert(id, ws)
|
||||
broadcastSet.insert(id, {
|
||||
onStart: wsStartNotifier
|
||||
, onFrame: wsFrameNotifier
|
||||
})
|
||||
break
|
||||
case 'off':
|
||||
broadcastSet.remove(id)
|
||||
|
||||
Reference in New Issue
Block a user