После некоторого копания оказывается, что вы можете POST на http-сервер.Вот что я сделал:
Machine1:
let ip = '192.168.1.35';
// create a json
let json = {
movies:[
{title: 'my movie 1',
path: 'D:\Videos\mymovie1.mkv,
size: 100000},
{title: 'my movie 2',
path: 'D:\Videos\mymovie2.mkv,
size: 100000}
]
};
// create a server for GET/POST
let apiServer = require('http').createServer((res,req) => {
// on GET, serve the json
if (req.method === 'GET') {
res.writeHead(200, {'Content-Type': 'application/json'});
res.write(JSON.stringify(json));
res.end();
}
// on POST, check what the Machine2 wants to play
if (req.method === 'POST') {
let body = String(); // create body
req.on('data', data => body += data); // update body with POST content
req.on('end', () => {
let file = JSON.parse(body);
// create a server for serving the file over http
let playServer = http.createServer((req,res) => {
res.writeHead(200, {
'Content-Type': 'video/mp4',
'Content-Length': file.size
});
let readStream = require('fs').createReadStream(file.path);
readStream.pipe(res);
});
// start serving the file on localhost:3001
playServer.listen(3001);
// respond to Machine2 where the file is streamed
res.writeHead(200, {'Content-Type': 'application/json'});
res.write(JSON.stringify({
url: `http://${ip}:3001`
}));
res.end();
});
}
});
// start serving the json on localhost:3000
apiServer.listen(3000);
Machine2:
let available;
// send a GET to Machine1
require('request')('http://192.168.1.35:3000', (err, res, body) => {
available = JSON.parse(body);
});
// select desired file
let wantedMovie = available.movies[0];
// send a POST to Machine1 saying what I want.
require('request')('http://192.168.1.35:3000', {
method: 'POST',
body: JSON.stringify(wantedMovie)
}, (err, res, body) => {
let url = JSON.parse(body).url;
// => playback the file from Machine1 via the URL.
});