UNPKG

network-collection

Version:

Baseline collection of graphs and network data structures using **socket.io**.

37 lines (31 loc) 974 B
'use strict'; const sio = require('socket.io'); const config = require('./config.json'); const Collection = require('../'); const port = config.port; const io = sio(port); const Cluster = Collection.Cluster; const Graph = Collection.Graph; const Node = Collection.Node; // Create a new network socket manager. const cluster = new Cluster(io); let connections = 0; io.on('connection', function(socket) { // Connect all the sockets as they come in. connections++; cluster.connect(socket, () => console.log('Network connected.')); // Wait for all connections. if (connections === config.connections) { // Make a query to find something. // In this example, we make a query to find // an graph with a label = 'stores' and a // node with the specific information supplied. cluster.find('stores', { price: 10, }).then((responses) => { console.log(responses); }).catch((error) => { console.error(error); }); } });