How to use peer - 10 common examples

To help you get started, we’ve selected a few peer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-chaincode-node / test / unit / chaincode.js View on Github external
process.argv.push('--grpc.max_receive_message_length');
	process.argv.push('177');
	process.argv.push('--grpc.keepalive_time_ms');
	process.argv.push('1234');
	process.argv.push('--grpc.keepalive_timeout_ms');
	process.argv.push('5678');
	process.argv.push('--grpc.http2.min_time_between_pings_ms');
	process.argv.push('7654');
	process.argv.push('--grpc.http2.max_pings_without_data');
	process.argv.push('99');
	process.argv.push('--grpc.keepalive_permit_without_calls');
	process.argv.push('2');
	delete require.cache[require.resolve('fabric-shim/lib/chaincode.js')];
	Chaincode = rewire('fabric-shim/lib/chaincode.js');
	opts = Chaincode.__get__('opts');
	t.deepEqual(opts['peer.address'], 'localhost:7051', 'Test passing only --peer.address argument is correctly picked up');
	t.equal(opts['grpc.max_send_message_length'],101, 'Test grpc.max_send_message_length can be set');
	t.equal(opts['grpc.max_receive_message_length'], 177, 'Test grpc.max_receive_message_length can be set');
	t.equal(opts['grpc.keepalive_time_ms'], 1234, 'Test grpc.keepalive_time_ms can be set');
	t.equal(opts['grpc.http2.min_time_between_pings_ms'], 7654, 'Test grpc.http2.min_time_between_pings_ms can be set');
	t.equal(opts['grpc.keepalive_timeout_ms'], 5678, 'Test grpc.keepalive_timeout_ms can be set');
	t.equal(opts['grpc.http2.max_pings_without_data'], 99, 'Test grpc.http2.max_pings_without_data can be set');
	t.equal(opts['grpc.keepalive_permit_without_calls'], 2, 'Test grpc.keepalive_permit_without_calls can be set');

	// remove the 7 parameters passed
	for (let index = 0; index < 7; index++) {
		process.argv.pop();
		process.argv.pop();
	}

	process.argv.pop();  // remove localhost:7051
	process.argv.pop();  // remove peer.address
github space-chat / space-chat / index.js View on Github external
// var express = require('express');

var PeerServer = require('peer').PeerServer,
    express = require('express'),
    Topics = require('./app/src/Topics.js'),
    app = express(),
    port = process.env.PORT || 3001;

app.use(express.static(__dirname + '/public'));

var expressServer = app.listen(port);
var io = require('socket.io').listen(expressServer);

console.log('Listening on port', port);

var peerServer = new PeerServer({ port: 9000, path: '/chat' });

peerServer.on('connection', function (id) {
  io.emit(Topics.USER_CONNECTED, id);
  console.log('User connected with #', id);
});

peerServer.on('disconnect', function (id) {
  io.emit(Topics.USER_DISCONNECTED, id);
  console.log('User disconnected with #', id);
});


// var routes = require('./routes');

// var app = express();
github leahsteinberg / co / index.js View on Github external
var server = app.listen(4004, function(){
        var host = server.address().address;
        var port = server.address().port;
        console.log("Collab App listening at http://%s:%s ~~~", host, port);
});

app.use("/public", express.static(path.resolve('public')));



/* peer js server */


var PeerServer = require('peer').PeerServer;
var pserver = PeerServer({port: 9000, path: '/myapp'});

pserver.on('connection', function(id) { 
  console.log("peer connected: ", id);


 });

pserver.on('disconnect', function(id) {

  console.log("peer disconnected: ", id);
});


var rooms = {names: {}, next_doc_id: 1, docs: {}};
github Glavin001 / open-world / server / server.js View on Github external
// 
var http = require('http'),
app = http.createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs'),
staticHeaders = { host: 'localhost',
  connection: 'keep-alive',
  'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Ubuntu/12.10 Chromium/22.0.1229.94 Chrome/22.0.1229.94 Safari/537.4',
  accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'accept-encoding': 'gzip,deflate,sdch',
  'accept-language': 'en-GB,en-US;q=0.8,en;q=0.6',
  'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3' };
app.listen(port);
// Peerjs Broker Server
var PeerServer = require('peer').PeerServer;
var peerServer = new PeerServer({ port: 9000 });

console.log("Server started listening on port "+port);
console.log("Go to http://localhost:"+port+"/game.html");
console.log();

function handler (req, res) {
	var url = req.url;
	if (url === "/")
		url = "/index.html";
	else if (url.substr(0, 6) === '/proxy') {
		handleProxy(req, res);
		return;
	}
	var fullPath = __dirname + '/../client' + url;
	fs.stat(fullPath, function (err, stats) {
		if (!err) {
github PeerServer / peer-server / server.js View on Github external
/* 
 * Set up bindings for real server. 
 * Handle handshake between clientServer and clientBrowser
 */

/* Load in dependencies */
var config = require('getconfig'),
    http = require('http'),
    fs = require('fs');
var app = require('express')();

/* Create the peer server for the app */
var PeerServer = require('peer').PeerServer;
var peerServer = new PeerServer({ port: 9000, debug: true });

/* Create the file server for the app */
var server = require('http').createServer(app);

var port = process.env.PORT || config.server.port || 5000;
/* Start the server at the port. */
server.listen(port, function() {
  console.log('Server running at port ' + port);
});

/* Static file mappings */
app.param('filename');

app.get('/server', function(req, res) {
  res.sendfile(__dirname + '/server/index.html');
});
github kanaka / raft.js / rtc_server.js View on Github external
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) {
github jssolichin / infinite-mondrian / app.js View on Github external
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
github RobinLinus / snapdrop / index.js View on Github external
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);
github kinectron / kinectron / app / kinectron-app.js View on Github external
//     depthPixelIndex += 2;
//   }

//   azureCtx.putImageData(depthImageData, 0, 0);
// };

// const map = (value, inputMin, inputMax, outputMin, outputMax) => {
//   return (
//     ((value - inputMin) * (outputMax - outputMin)) / (inputMax - inputMin) +
//     outputMin
//   );
// };

//  Create local peer server
var PeerServer = require("peer").PeerServer;
var server = PeerServer({ port: 9001, path: "/" });

// Set peer credentials for localhost by default
var peerNet = { host: "localhost", port: 9001, path: "/" };
var myPeerId = "kinectron";
var peer_ids = [];
var peer_connections = [];
var peer = null;
var peerIdDisplay = null;
var newPeerEntry = false;
var newPeerInfo;

var canvas = null;
var context = null;
var canvasState = null;

const WINDOWSCOLORWIDTH = 1920;
github ouroboros-team / ouroboros / server.js View on Github external
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'));
  });
}

peer

PeerJS server component

MIT
Latest version published 11 months ago

Package Health Score

76 / 100
Full package analysis