Open files, web sites, executables via web sockets middleware.
npm i openspace --save
Could be loaded from url /openspace/openspace.js
.
const prefix = '/openspace';
/* could be one argument: callback */
openspace(prefix, function(opener) {
const path = 'hello.js';
const end = () => {
console.log('end');
opener.removeListener('end', end);
};
opener.open(from, to, names);
opener.on('end', end);
opener.on('error', (error) => {
console.error(error.message);
});
});
const openspace = require('openspace');
const http = require('http');
const express = require('express');
const io = require('socket.io');
const app = express();
const port = 1337;
const server = http.createServer(app);
const socket = io.listen(server);
server.listen(port);
app.use(openspace({
online: true
});
openspace.listen(socket, {
prefix: '/openspace', /* default */
root: '/', /* string or function */
authCheck: (socket, ok) => { /* optional */
/* auth check logic */
ok();
}
});
MIT