Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
screen
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
screen
Commits
04b234e2
Commit
04b234e2
authored
May 19, 2017
by
Neil Gershenfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial screen commit
parent
8934aaa8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
135 additions
and
0 deletions
+135
-0
screen.js
screen.js
+135
-0
No files found.
screen.js
0 → 100644
View file @
04b234e2
//
// screen.js
// mjpeg content server
// Neil Gershenfeld
// 2/9/17
// todo
// standalone client content push
// browser client content push
// https
// parse command line
// add authentication
// interframe compression
// include audio
// uses maim for screen capture:
// https://github.com/naelstrof/maim
// https://github.com/naelstrof/maim/archive/master.zip
// install libimlib2-dev libxrandr-dev libxfixes-dev cmake
//
// command line
//
if
(
process
.
argv
.
length
!=
5
)
{
console
.
log
(
"
node screen.js server_port server_update_rate_ms client_update_rate_ms
"
)
process
.
exit
()
}
var
port
=
parseInt
(
process
.
argv
[
2
])
var
server_delay
=
parseFloat
(
process
.
argv
[
3
])
var
client_delay
=
parseFloat
(
process
.
argv
[
4
])
//
// requires
//
var
http
=
require
(
'
http
'
)
const
spawn
=
require
(
'
child_process
'
).
spawn
;
const
spawnSync
=
require
(
'
child_process
'
).
spawnSync
const
fork
=
require
(
'
child_process
'
).
fork
const
fs
=
require
(
'
fs
'
)
const
events
=
require
(
'
events
'
)
//
// globals
//
var
img
,
newimg
var
max
=
0
var
last
//
// initialization
//
spawnSync
(
'
maim
'
,[
'
--showcursor
'
,
'
out.jpg
'
])
img
=
fs
.
readFileSync
(
'
out.jpg
'
,
'
binary
'
)
var
requests
=
[
null
]
//
// start http server
//
http
.
createServer
(
function
(
request
,
response
)
{
var
headers
=
request
.
headers
var
method
=
request
.
method
var
url
=
request
.
url
if
(
url
==
'
/
'
)
{
fs
.
readFile
(
'
viewer.html
'
,
function
(
err
,
data
){
response
.
writeHead
(
200
,{
'
Content-Type
'
:
'
text/html
'
});
response
.
end
(
data
)
})
}
else
if
(
url
==
'
/img
'
)
{
requests
.
push
(
response
)
}
else
if
(
url
==
'
/initvars
'
)
{
var
vars
=
{
'
client_delay
'
:
client_delay
}
response
.
writeHead
(
200
,{
'
Content-Type
'
:
'
text/plain
'
});
response
.
end
(
JSON
.
stringify
(
vars
))
}
else
if
(
url
==
'
/initimg
'
)
{
response
.
writeHead
(
200
,{
'
Content-Type
'
:
'
application/octet-stream
'
})
response
.
end
(
img
,
'
binary
'
)
}
else
if
(
url
==
'
/screen.js
'
)
{
fs
.
readFile
(
'
screen.js
'
,
function
(
err
,
data
){
response
.
writeHead
(
200
,{
'
Content-Type
'
:
'
text/plain
'
});
response
.
end
(
data
)
})
}
else
if
(
url
==
'
/viewer.html
'
)
{
fs
.
readFile
(
'
viewer.html
'
,
function
(
err
,
data
){
response
.
writeHead
(
200
,{
'
Content-Type
'
:
'
text/plain
'
});
response
.
end
(
data
)
})
}
else
if
(
url
==
'
/stats
'
)
{
var
resp
=
"
<html>
"
resp
+=
"
<body>
"
resp
+=
"
last:
"
+
last
+
"
<br>
"
resp
+=
"
max:
"
+
max
+
"
<br>
"
response
.
writeHead
(
200
,{
'
Content-Type
'
:
'
text/html
'
});
response
.
end
(
resp
)
}
}).
listen
(
port
)
//
// start event loop
//
update
()
//
// event loop
//
function
update
()
{
if
(
requests
[
0
]
==
null
)
{
const
ps
=
spawn
(
'
maim
'
,[
'
--showcursor
'
,
'
out.jpg
'
])
ps
.
on
(
'
close
'
,
function
(
code
){
fs
.
readFile
(
'
out.jpg
'
,
'
binary
'
,
function
(
err
,
data
){
var
changed
=
false
for
(
var
i
=
0
;
i
<
img
.
length
;
++
i
)
{
if
(
img
[
i
]
!=
data
[
i
])
{
changed
=
true
break
}
}
if
(
changed
==
true
)
{
if
(
requests
.
length
>
max
)
max
=
requests
.
length
last
=
requests
.
length
img
=
data
requests
.
splice
(
0
,
1
)
requests
.
push
(
null
)
//console.log('changed: '+requests.length)
}
//else
//console.log('not changed: '+requests.length)
})
setTimeout
(
update
,
server_delay
)
})
}
else
{
requests
[
0
].
writeHead
(
200
,{
'
Content-Type
'
:
'
application/octet-stream
'
})
requests
[
0
].
end
(
img
,
'
binary
'
)
requests
.
splice
(
0
,
1
)
setTimeout
(
update
,
server_delay
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment