How to use socketcluster-server - 10 common examples

To help you get started, we’ve selected a few socketcluster-server 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 LiskHQ / lisk-sdk-examples / elements / lisk-p2p / src / p2p.ts View on Github external
public constructor(config: P2PConfig) {
		super();
		this._config = config;
		this._isActive = false;
		this._newPeers = new Map();
		this._triedPeers = new Map();

		this._httpServer = http.createServer();
		this._scServer = attach(this._httpServer) as SCServerUpdated;

		// This needs to be an arrow function so that it can be used as a listener.
		this._handlePeerPoolRPC = (request: P2PRequest) => {
			if (request.procedure === REMOTE_RPC_GET_ALL_PEERS_LIST) {
				this._handleGetPeersRequest(request);
			}
			// Re-emit the request for external use.
			this.emit(EVENT_REQUEST_RECEIVED, request);
		};

		// This needs to be an arrow function so that it can be used as a listener.
		this._handlePeerPoolMessage = (message: P2PMessagePacket) => {
			// Re-emit the message for external use.
			this.emit(EVENT_MESSAGE_RECEIVED, message);
		};
github LiskHQ / lisk-sdk / packages / lisk-p2p / src / p2p.ts View on Github external
public constructor(config: P2PConfig) {
		super();
		this._config = config;
		this._isActive = false;
		this._newPeers = new Map();
		this._triedPeers = new Map();

		this._httpServer = http.createServer();
		this._scServer = attach(this._httpServer) as SCServerUpdated;

		// This needs to be an arrow function so that it can be used as a listener.
		this._handlePeerPoolRPC = (request: P2PRequest) => {
			// Re-emit the request for external use.
			this.emit(EVENT_REQUEST_RECEIVED, request);
		};

		// This needs to be an arrow function so that it can be used as a listener.
		this._handlePeerPoolMessage = (message: P2PMessagePacket) => {
			// Re-emit the message for external use.
			this.emit(EVENT_MESSAGE_RECEIVED, message);
		};

		this._handlePeerConnect = (peerInfo: P2PPeerInfo) => {
			// Re-emit the message to allow it to bubble up the class hierarchy.
			this.emit(EVENT_CONNECT_OUTBOUND, peerInfo);
github as-com / s2forums-search / search-interface-old / index.js View on Github external
}
	}, function(error, response) {
		res.json({
			// hasError: Boolean(error),
			error: error,
			response: response
		});
	});
});
var httpSrv = http.createServer(app).listen(3000);
// var server = app.listen(3000, function() {
//     var host = server.address().address;
//     var port = server.address().port;
//     console.log('App listening at http://%s:%s', host, port);
// });
var scServer = socketClusterServer.attach(httpSrv);
// var documentCount = -1;
var prevDocCount = -1;
scServer.on("connection", function(socket) {
	// logger.info("New connection!");
});
client.ping({
	requestTimeout: 30000,
	// undocumented params are appended to the query string
	hello: "elasticsearch"
}, function(error) {
	if (error) {
		logger.fatal("elasticsearch is down!");
		// console.error('elasticsearch cluster is down!');
	} else {
		// console.log('All is well');
		logger.info("Connected to elasticsearch!");
github LiskHQ / lisk-sdk / elements / lisk-p2p / src / p2p.ts View on Github external
public constructor(config: P2PConfig) {
		super();

		this._config = config;
		this._isActive = false;
		this._newPeers = new Map();
		this._triedPeers = new Map();

		this._httpServer = http.createServer();
		this._scServer = attach(this._httpServer, {
			wsEngineServerOptions: {
				maxPayload: config.wsMaxPayload
					? config.wsMaxPayload
					: DEFAULT_WS_MAX_PAYLOAD,
			},
		}) as SCServerUpdated;

		// This needs to be an arrow function so that it can be used as a listener.
		this._handlePeerPoolRPC = (request: P2PRequest) => {
			if (request.procedure === REMOTE_RPC_GET_ALL_PEERS_LIST) {
				this._handleGetPeersRequest(request);
			}
			// Re-emit the request for external use.
			this.emit(EVENT_REQUEST_RECEIVED, request);
		};
github SocketCluster / socketcluster-client / test / integration.js View on Github external
it('Should still work if token verification is asynchronous', function (done) {
      var port = 8511;
      server = socketClusterServer.listen(port, {
        authKey: serverOptions.authKey,
        authVerifyAsync: false
      });
      server.once('connection', connectionHandler);
      server.once('ready', function () {
        client = socketClusterClient.create({
          hostname: clientOptions.hostname,
          port: port,
          multiplex: false
        });
        client.once('connect', function (statusA) {
          client.emit('login', {username: 'bob'});
          client.once('authenticate', function (newSignedToken) {
            client.once('disconnect', function () {
              client.once('connect', function (statusB) {
                assert.equal(statusB.isAuthenticated, true);
github SocketCluster / socketcluster-client / test / integration.js View on Github external
it('Token should be available inside login callback if token engine signing is synchronous', function (done) {
      var port = 8509;
      server = socketClusterServer.listen(port, {
        authKey: serverOptions.authKey,
        authSignAsync: false
      });
      server.once('connection', connectionHandler);
      server.once('ready', function () {
        client = socketClusterClient.create({
          hostname: clientOptions.hostname,
          port: port,
          multiplex: false
        });
        client.once('connect', function (statusA) {
          client.emit('login', {username: 'bob'}, function (err) {
            assert.equal(client.authState, 'authenticated');
            assert.notEqual(client.authToken, null);
            assert.equal(client.authToken.username, 'bob');
            done();
github SocketCluster / socketcluster-client / test / integration.js View on Github external
it('If token engine signing is asynchronous, authentication can be captured using the authenticate event', function (done) {
      var port = 8510;
      server = socketClusterServer.listen(port, {
        authKey: serverOptions.authKey,
        authSignAsync: true
      });
      server.once('connection', connectionHandler);
      server.once('ready', function () {
        client = socketClusterClient.create({
          hostname: clientOptions.hostname,
          port: port,
          multiplex: false
        });
        client.once('connect', function (statusA) {
          client.emit('login', {username: 'bob'});
          client.once('authenticate', function (newSignedToken) {
            assert.equal(client.authState, 'authenticated');
            assert.notEqual(client.authToken, null);
            assert.equal(client.authToken.username, 'bob');
github SocketCluster / socketcluster-client / test / integration.js View on Github external
beforeEach('Run the server before start', function (done) {
    serverOptions = {
      authKey: 'testkey',
      ackTimeout: 200
    };

    server = socketClusterServer.listen(portNumber, serverOptions);
    server.on('connection', connectionHandler);

    server.addMiddleware(server.MIDDLEWARE_AUTHENTICATE, function (req, next) {
      if (req.authToken.username === 'alice') {
        var err = new Error('Blocked by MIDDLEWARE_AUTHENTICATE');
        err.name = 'AuthenticateMiddlewareError';
        next(err);
      } else {
        next();
      }
    });

    clientOptions = {
      hostname: '127.0.0.1',
      port: portNumber,
      multiplex: false,
github as-com / s2forums-search / src / server.js View on Github external
console.warn("Memory leak detected: " + info);
});
setTimeout(function() {
	memwatch.gc();
}, 10000);
setInterval(function() {
	memwatch.gc();
}, 120000);


var app = express();
const hostname = process.env.HOSTNAME || "localhost";
const port = process.env.PORT || 8000;

var server = http.createServer(app);
var scServer = socketClusterServer.attach(server);

scServer.addMiddleware(scServer.MIDDLEWARE_PUBLISH_IN, function(req, next) {
	next({name: "denied", message: "Clients can't publish"});
});


var esclient = new elasticsearch.Client({
	host: (process.env.ELASTIC || "192.168.1.65") + ':9200',
	log: 'info'
});

app.use(express.static("static"));
app.use(bodyParser.json());
app.use(cacheResponseDirective());

app.use(function(err, req, res, next) {
github jondubois / nombo / nombo-worker.node.js View on Github external
cachemere.setPrepProvider(self._prepProvider);
	
	self._server = http.createServer(self._middleware[self.MIDDLEWARE_HTTP].run);
	
	self._httpRequestCount = 0;
	self._ioRequestCount = 0;
	self._httpRPM = 0;
	self._ioRPM = 0;
	
	if (self._statusInterval != null) {
		clearInterval(self._statusInterval);
	}
	self._statusInterval = setInterval(this._calculateStatus.bind(this), this._options.workerStatusInterval * 1000);
	
	self._socketServer = socketCluster.attach(self._server, {
		sourcePort: self._options.port,
		ioClusterClient: self._ioClusterClient,
		transports: self._options.transports,
		pingTimeout: self._options.heartbeatTimeout,
		pingInterval: self._options.heartbeatInterval,
		upgradeTimeout: self._options.connectTimeout,
		host: self._options.host,
		secure: self._options.protocol == 'https',
		appName: self._options.appName
	});
	
	self._socketServer.on('notice', self.noticeHandler.bind(self));
	self._errorDomain.add(self._socketServer);
	
	var oldRequestListeners = self._server.listeners('request').splice(0);
	self._server.removeAllListeners('request');

socketcluster-server

Server module for SocketCluster

MIT
Latest version published 2 months ago

Package Health Score

68 / 100
Full package analysis

Popular socketcluster-server functions