2016-12-11 19:24:52 +00:00
|
|
|
require = requireInjector(getfenv(1))
|
2017-07-24 02:37:07 +00:00
|
|
|
local Event = require('event')
|
2016-12-11 19:24:52 +00:00
|
|
|
local Socket = require('socket')
|
|
|
|
local Logger = require('logger')
|
|
|
|
|
|
|
|
Logger.setScreenLogging()
|
|
|
|
|
|
|
|
local args = { ... }
|
|
|
|
local mon = device[args[1] or 'monitor']
|
|
|
|
|
|
|
|
if not mon then
|
|
|
|
error('Monitor not attached')
|
|
|
|
end
|
|
|
|
|
|
|
|
mon.setBackgroundColor(colors.black)
|
|
|
|
mon.clear()
|
|
|
|
|
|
|
|
while true do
|
2017-05-09 05:57:00 +00:00
|
|
|
local socket = Socket.server(5901)
|
2016-12-11 19:24:52 +00:00
|
|
|
|
|
|
|
print('mirror: connection from ' .. socket.dhost)
|
|
|
|
|
2017-07-24 02:37:07 +00:00
|
|
|
Event.addRoutine(function()
|
2016-12-11 19:24:52 +00:00
|
|
|
while true do
|
|
|
|
local data = socket:read()
|
|
|
|
if not data then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
for _,v in ipairs(data) do
|
|
|
|
mon[v.f](unpack(v.args))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-05-10 23:59:09 +00:00
|
|
|
-- ensure socket is connected
|
2017-07-24 02:37:07 +00:00
|
|
|
Event.onInterval(3, function(h)
|
|
|
|
if not socket:ping() then
|
|
|
|
Event.off(h)
|
2017-05-10 10:11:25 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
while true do
|
2017-07-24 02:37:07 +00:00
|
|
|
Event.pullEvent()
|
|
|
|
if not socket.connected then
|
2016-12-11 19:24:52 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print('connection lost')
|
|
|
|
|
|
|
|
socket:close()
|
|
|
|
end
|