Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function newPeerServerChannel(channel) {
var peerServer = ExpressPeerServer(server, options);
// Attach PeerJS server to Express server
app.use('/api/' + channel, peerServer);
// PeerJS event handlers
peerServer.on('connection', function (id) {
console.log("connection - channel: " + channel + ", ID:", id);
console.log("peers:", Object.keys( peerServer._clients.peerjs));
});
peerServer.on('disconnect', function (id) {
console.log("disconnect - channel: " + channel + ", ID:", id);
console.log("peers:", Object.keys( peerServer._clients.peerjs));
});
app.get('/peers/' + channel, function(req, res, next) {
var fs = require('fs');
var express = require('express');
var app = express();
var ExpressPeerServer = require('peer').ExpressPeerServer;
var server = app.listen(3000, function () {
console.log(':3000');
});
var options = {
debug: true
};
app.use("/public", express.static(process.env.PWD + '/public'));
app.use("/bower_components", express.static(process.env.PWD + '/bower_components'));
app.use("/node_modules", express.static(process.env.PWD + '/node_modules'));
app.use('/peerjs', ExpressPeerServer(server, options));
app.get('/', function(req, res){
res.sendFile(process.env.PWD + '/views/index.html');
});
app.get('/cardboard', function(req, res){
res.sendFile(process.env.PWD + '/views/index.html');
});
app.get('/:id', function(req, res){
res.sendFile(process.env.PWD + '/views/controller.html');
});
//http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
var randomValueBase64 = function (len) {
return crypto.randomBytes(Math.ceil(len * 3 / 4))
.toString('base64') // convert to base64 format
.slice(0, len) // return required number of characters
var compression = require('compression');
var app = express();
var http = require('http');
var ExpressPeerServer = require('peer').ExpressPeerServer;
var wsServer = require('./server/ws-server.js');
var server = http.createServer(app);
// Serve up content from public directory
app.use(compression());
app.use(express.static(__dirname + '/public'));
var port = process.env.PORT || 3002;
server.listen(port);
wsServer.create(server);
app.use('/peerjs', ExpressPeerServer(server, {
debug: true
}));
console.log('listening on port ' + port);
const express = require('express');
const app = express();
const peer = require('peer');
const path = require('path');
const port = process.env.PORT || 3001;
app.set('port', port);
const server = app.listen(app.get('port'));
app.use('/peerjs', peer.ExpressPeerServer(server, {
debug: true,
}));
// Express only serves static assets in production
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
}
res.render('bots', {title: 'Talk to Bots'});
});
app.get('/idLength', function (req, res) {
res.render('idGraph');
});
app.get('/opTime', function (req, res) {
res.render('timeGraph');
})
var srv = app.listen(port, function() {
console.log('Listening on '+port)
})
app.use('/peerjs', require('peer').ExpressPeerServer(srv, {
debug: true
}))
new Promise(resolve => {
const app = express()
const peerServer = ExpressPeerServer(app, {})
app.use('/api', peerServer)
peerServer.on('connection', (id: string) => {
peers.set(id, true)
console.log('peer connected:', id)
})
peerServer.on('disconnect', (id: string) => {
peers.delete(id)
console.log('peer disconnected:', id)
})
app.get('/peers', (_req, res) => {
res.json(Object.keys(peerServer._clients.peerjs))
})
module.exports.createRendezvousServer = function createRendezvousServer (port) {
let app = express()
let server = app.listen(port, function () {
let host = server.address().address
let port = server.address().port
console.log('View the rendezvous server at http://%s:%s/', host, port)
})
app.use('/', ExpressPeerServer(server, {debug: true, allow_discovery: true}))
return server
}
app.prepare().then(() => {
var expressApp = express()
var server = require("http").createServer(expressApp)
expressApp.use(
"/peerjs",
ExpressPeerServer(server, {
debug: true
})
)
expressApp.use(handler)
server.listen(3000)
})
export function start(dirname, userPort = 8080) {
log = new Log('info');
expressServer = new ExpressServer().listen(dirname);
var options = {
debug: true,
allow_discovery: true
};
expressServer.app.use('/multi', ExpressPeerServer(expressServer.server, options));
expressServer.server.on('connection', onConnection);
expressServer.server.on('disconnect', onDisconnect);
}