How to use the uws.Server function in uws

To help you get started, we’ve selected a few uws 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 tabvn / nodejs-reactjs-chatapp / server / src / index.js View on Github external
//app.use(morgan('dev'));


app.use(cors({
    exposedHeaders: "*"
}));

app.use(bodyParser.json({
    limit: '50mb'
}));



app.wss = new Server({
	server: app.server
});


// static www files use express
const wwwPath = path.join(__dirname, 'www');

app.use('/', express.static(wwwPath));

// Connect to Mongo Database

new Database().connect().then((db) => {

	console.log("Successful connected to database.")

	app.db = db;
github sjones6 / gun-flint / bin / commands / gun / lib / uws.js View on Github external
Gun.on('opt', function mount(ctx){
	this.to.next(ctx);
	var opt = ctx.opt;
	if(ctx.once){ return }
	if(!opt.web){ return }
	var ws = opt.uws || opt.ws || (opt.uws = {}), batch;

	ws.server = ws.server || opt.web;
	ws.path = ws.path || '/gun';

	ws.web = new WebSocket.Server(ws);

	ws.web.on('connection', function(peer){
		peer.upgradeReq = peer.upgradeReq || {};
		peer.url = url.parse(peer.upgradeReq.url||'', true);
		peer.id = peer.id || Gun.text.random(6);
		opt.peers[peer.id] = {wire: peer};
		peer.on('message', function(msg){
			//console.log("MESSAGE", msg);
			receive(msg, peer, ctx); // diff: peer is wire.
		});
		peer.on('close', function(){
			Gun.obj.del(opt.peers, peer.id);
		});
	});	

	ctx.on('out', function(at){
github kripod / wsx / src / server / server.js View on Github external
* @param {string} type Type of the message.
     * @param {*} [payload] Payload of the message.
     * @param {ServerSideSocket[]} [sockets] Sockets to broadcast the message
     * between.
     */
    this.socketExtensions.set('broadcast', (socket) =>
      (type, payload, sockets = this.sockets) => {
        this.bulkSend(
          [...sockets].filter((socket2) => socket2 !== socket),
          type,
          payload
        );
      }
    );

    this.base = new WebSocketServer(options, successCallback)
      .on('error', (error) => this.emit('error', error))
      .on('connection', (socket) => {
        // Extend the functionality of sockets
        this.socketExtensions.apply(socket, this);

        // Add the connected socket to the main group of sockets
        this.sockets.add(socket);

        socket
          .on('error', (error) => this.emit('error', error, socket))
          .on('close', (code, reason) => {
            // Remove the disconnected socket from every group
            this.sockets.delete(socket);
            for (const socketGroup of Object.values(this.socketGroups)) {
              socketGroup.delete(socket);
            }
github ClusterWS / ClusterWS / src / lib / modules / worker / worker.ts View on Github external
let brokerConnection: TcpSocket = new TcpSocket(this.options.brokerPort, '127.0.0.1')
        brokerConnection.on('error', (err: any) => logError('Worker' + ', PID ' + process.pid + '\n' + err.stack + '\n'))
        brokerConnection.on('message', (msg: any) => msg === '#0' ? brokerConnection.send('#1') : this.socketServer.emitter.emit('#publish', JSON.parse(msg)))
        brokerConnection.on('disconnect', () => logError('Something went wrong broker has been disconnected'))

        this.socketServer.middleware = {}
        this.socketServer.emitter = new EventEmitter()
        this.socketServer.on = (event: string, fn: any) => this.socketServer.emitter.on(event, fn)
        this.socketServer.publish = (channel: string, data: any) => {
            brokerConnection.send(brokerMessage(channel, data))
            this.socketServer.emitter.emit('#publish', { channel: channel, data: data })
        }

        this.httpServer = createServer().listen(this.options.port)

        let uWS: any = new uws.Server({ server: this.httpServer })
        uWS.on('connection', (socket: any) => this.socketServer.emitter.emit('connection', new Socket(socket, this)))

        this.options.worker.call(this)

        process.send(processMessages('ready', process.pid))
    }
}
github higordiego / seed-atomic / server / app.js View on Github external
app.use('/api', jwt);

const port = 3000;

require('./routes')(app)

app.use((req, res, next)=>{
  res.status(404).json({error: 'Route not found'});
})

const server = http.createServer(app)

const io = socket.listen(server);

io.engine.ws = new (require('uws').Server)({
    noServer: true,
    clientTracking: false,
    perMessageDeflate: false
});

require('./_quarks/socket-io')(io)

server.listen(3000, () => console.log(`Init Server to port: ${port} `));
github ClusterWS / ClusterWS / src1 / modules / main / worker / worker.ts View on Github external
this.httpServer = createServer().listen(this.options.port, () => {
            const uws: Server = new Server({ server: this.httpServer })
            uws.on('connection', (socket: any) => this.socketServer.emitter.emit('connection', new Socket(socket, this)))

            this.options.worker.call(this)
            process.send(processMessage('ready', process.pid))
        })
    }
github aerojs / aero / lib / LiveReload / index.js View on Github external
this.http.listen(this.port, error => {
			if(error)
				throw error

			this.server = new WebSocket.Server({
				server: this.http
			})

			this.script = this.scriptCode.replace('${port}', this.port)
		})
	}
github PsychoLlama / mytosis / packages / mytosis-websocket / src / server.js View on Github external
constructor(config) {
    assert(config, `Expected config, got "${config}"`);

    super();

    const server = new Server(config);
    server.on('connection', socket => {
      const connection = new Connection(socket);

      this.add(connection);

      socket.on('close', () => this.remove(connection));
    });
  }
}
github champierre / ml2scratch / old / glitch / server.js View on Github external
const WebSocketServer = require("uws").Server
const wss = new WebSocketServer({port: process.env.PORT})
var connections = {};

wss.on('connection', (ws) => {
  ws.on('close', function() {
    Object.keys(connections).forEach(function (key) {
      if (connections[key] === ws) {
        delete connections[key];
      }
    });
  });
  ws.on('message', function(json) {

    var data = JSON.parse(json);
    if (data.action == 'connect') {
      connections[data.conn_id] = ws;
    } else if (data.action == 'predict') {
github plantain-00 / ws-tool / proxy.js View on Github external
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var express = require("express");
var uws_1 = require("uws");
var http = require("http");
var net = require("net");
var dgram = require("dgram");
var node_fetch_1 = require("node-fetch");
var types = require("./types");
var compression = require("compression");
var server = http.createServer();
var wss = new uws_1.Server({ server: server });
var app = express();
app.use("/", express.static(__dirname));
app.disable("x-powered-by");
app.use(compression());
var toUrlHeaderName = "x-to-url";
var headersName = "x-headers";
app.all("/proxy", function (request, proxyResponse) {
    var url = request.header(toUrlHeaderName);
    if (!url) {
        proxyResponse.send("No header: " + toUrlHeaderName);
    }
    else {
        var chunks_1 = [];
        request.on("data", function (chunk) {
            chunks_1.push(chunk);
        });

uws

## Go to [https://github.com/uNetworking/uWebSockets.js](https://github.com/uNetworking/uWebSockets.js).

Apache-2.0
Latest version published 4 years ago

Package Health Score

63 / 100
Full package analysis