How to use the isomorphic-ws.Server function in isomorphic-ws

To help you get started, we’ve selected a few isomorphic-ws 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 heineiuo / seashell / src / SeashellGateway.js View on Github external
createGatewayServer = (internalRequestHandler, connectionHandler = defaultConnectionHandler, options = { }) => {
    const serverOption = {}
    if ('port' in options) {
      serverOption.port = options.port
    } else if ('server' in options)  {
      serverOption.server = options.server
    } else if ('noServer' in options) {
      serverOption.noServer = options.noServer
    }
    const server = new WebSocket.Server(serverOption)
    server.on('connection', async (socket, req) => {
      try {
        const { id } = await connectionHandler(socket, req)
        socket.id = id
        this.clientMap[id] = socket
        socket.on('message', (msg) => this.handleGatewayMessage(msg, socket))
        socket.on('close', () => {
          delete this.clientMap[id]
        })
      } catch (e) {
        console.log(e)
        socket.terminate()
      }
    })
    this.replaceInternalSocket(internalRequestHandler)
    return server
github diegodorado / atom-live-emojing / lib / chrome.js View on Github external
initWs() {
    this.server = express().listen(8080, ()=>{})
    //todo: let change port
    this.wsServer = new ws.Server({port: 1337})
    this.wsServer.on('connection', (ws) => {
      ws.on('message', (str) =>{
        const msg = JSON.parse(str) //JSON.parse(str.utf8Data)
        const s = this.callback(msg)
        if (s !== null && msg.user_id!==null) {
          let url = `https://graph.facebook.com/${msg.user_id}/picture?height=320`
          s.updatePhoto(url)
        }
      })
    })

  }
github adzialocha / osc-js / src / plugin / bridge.js View on Github external
const dgram = typeof __dirname !== 'undefined' ? require('dgram') : undefined
const WebSocketServer = typeof __dirname !== 'undefined' ? require('isomorphic-ws').Server : undefined

/**
 * Status flags
 * @private
 */
const STATUS = {
  IS_NOT_INITIALIZED: -1,
  IS_CONNECTING: 0,
  IS_OPEN: 1,
  IS_CLOSING: 2,
  IS_CLOSED: 3,
}

/**
 * Default options
 * @private
github diegodorado / atom-live-emojing / lib / adapters / websocket.js View on Github external
initWs() {
    this.server = express().listen(8080, ()=>{})
    this.wsServer = new ws.Server({port: 1337})
    this.wsServer.on('connection', (ws) => {
      ws.on('message', (str) =>{
        const msg = JSON.parse(str) //JSON.parse(str.utf8Data)
        const s = this.callback(msg)


        //empty message after filter?
        if (msg.text.replace(/[\x7f-\xfF|a-z|A-Z|\s]/g, '').length == 0) {
          atom.notifications.addInfo('<b>'+msg.who +':</b><br>'+msg.text)
        }else{
          return this.messageReceived(msg)
        }


        if (s !== null &amp;&amp; msg.user_id!==null) {
          let url = `https://graph.facebook.com/${msg.user_id}/picture?height=320`
github heineiuo / seashell / packages / seashell / src / core / Seashell.js View on Github external
attach = (server) => {
    if (this.__start) return new Error('Seashell has started')
    delete this.__options.port
    this.__options.server = server
    this.server = new WebSocket.Server(this.__options);
    this.server.on('connection', this.onChildConnection);
    this.__start = true
  }
github adzialocha / osc-js / lib / osc.js View on Github external
}
    }, {
      key: "send",
      value: function send(binary) {
        var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        var options = _objectSpread2({}, this.options.send, {}, customOptions);
        var port = options.port,
            host = options.host;
        this.socket.send(Buffer.from(binary), 0, binary.byteLength, port, host);
      }
    }]);
    return DatagramPlugin;
  }();

  var dgram$1 = typeof __dirname !== 'undefined' ? require('dgram') : undefined;
  var WebSocketServer = typeof __dirname !== 'undefined' ? require('isomorphic-ws').Server : undefined;
  var STATUS$1 = {
    IS_NOT_INITIALIZED: -1,
    IS_CONNECTING: 0,
    IS_OPEN: 1,
    IS_CLOSING: 2,
    IS_CLOSED: 3
  };
  var defaultOptions$2 = {
    udpServer: {
      host: 'localhost',
      port: 41234,
      exclusive: false
    },
    udpClient: {
      host: 'localhost',
      port: 41235
github adzialocha / osc-js / lib / osc.js View on Github external
}, {
      key: "close",
      value: function close() {
        this.socketStatus = STATUS$2.IS_CLOSING;
        this.socket.close();
      }
    }, {
      key: "send",
      value: function send(binary) {
        this.socket.send(binary);
      }
    }]);
    return WebsocketClientPlugin;
  }();

  var WebSocketServer$1 = typeof __dirname !== 'undefined' ? require('isomorphic-ws').Server : undefined;
  var STATUS$3 = {
    IS_NOT_INITIALIZED: -1,
    IS_CONNECTING: 0,
    IS_OPEN: 1,
    IS_CLOSING: 2,
    IS_CLOSED: 3
  };
  var defaultOptions$4 = {
    host: 'localhost',
    port: 8080
  };
  var WebsocketServerPlugin =
  function () {
    function WebsocketServerPlugin(customOptions) {
      _classCallCheck(this, WebsocketServerPlugin);
      if (!WebSocketServer$1) {

isomorphic-ws

Isomorphic implementation of WebSocket

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis