cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

index.js (1055B)


      1'use strict';
      2
      3/*!
      4 * ws: a node.js websocket client
      5 * Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
      6 * MIT Licensed
      7 */
      8
      9var WS = module.exports = require('./lib/WebSocket');
     10
     11WS.Server = require('./lib/WebSocketServer');
     12WS.Sender = require('./lib/Sender');
     13WS.Receiver = require('./lib/Receiver');
     14
     15/**
     16 * Create a new WebSocket server.
     17 *
     18 * @param {Object} options Server options
     19 * @param {Function} fn Optional connection listener.
     20 * @returns {WS.Server}
     21 * @api public
     22 */
     23WS.createServer = function createServer(options, fn) {
     24  var server = new WS.Server(options);
     25
     26  if (typeof fn === 'function') {
     27    server.on('connection', fn);
     28  }
     29
     30  return server;
     31};
     32
     33/**
     34 * Create a new WebSocket connection.
     35 *
     36 * @param {String} address The URL/address we need to connect to.
     37 * @param {Function} fn Open listener.
     38 * @returns {WS}
     39 * @api public
     40 */
     41WS.connect = WS.createConnection = function connect(address, fn) {
     42  var client = new WS(address);
     43
     44  if (typeof fn === 'function') {
     45    client.on('open', fn);
     46  }
     47
     48  return client;
     49};