How to use the faye-websocket.Client function in faye-websocket

To help you get started, we’ve selected a few faye-websocket 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 apifytech / proxy-chain / test / server.js View on Github external
return new Promise((resolve, reject) => {
                const wsUrl = `${useSsl ? 'wss' : 'ws'}://127.0.0.1:${targetServerPort}`;
                const ws = new WebSocket.Client(wsUrl, [], {
                    proxy: {
                        origin: mainProxyUrl,
                        tls: useSsl ? { cert: sslCrt } : null,
                    }
                });

                ws.on('error', (err) => {
                    ws.close();
                    reject(err);
                });
                ws.on('open', () => {
                    ws.send('hello world');
                });
                ws.on('message', (event) => {
                    ws.close();
                    resolve(event.data);
github apifytech / proxy-chain / test / server.js View on Github external
return new Promise((resolve, reject) => {
                const wsUrl = `${useSsl ? 'wss' : 'ws'}://127.0.0.1:${targetServerPort}`;
                const ws = new WebSocket.Client(wsUrl, [], {
                    proxy: {
                        origin: mainProxyUrl,
                        tls: useSsl ? { cert: sslCrt } : null,
                    }
                });

                ws.on('error', (err) => {
                    ws.close();
                    reject(err);
                });
                ws.on('open', () => {
                    ws.send('hello world');
                });
                ws.on('message', (event) => {
                    ws.close();
                    resolve(event.data);
github tisunov / InstacabDispatcher / driver-app.js View on Github external
epoch: Math.round(new Date().getTime() / 1000.0)
};

var tripCoordinates = [
  [51.681520, 39.183383],
  [51.675932, 39.169736],
  [51.670715, 39.161153],
  [51.672419, 39.153171],
  [51.675719, 39.143300],
  [51.677901, 39.136691],
  [51.680296, 39.129653],
  [51.683448, 39.122151],
];

var WebSocket = require('faye-websocket'),
    client    = new WebSocket.Client('ws://localhost:9000/');

client.on('open', function(event) {
  console.log('WebSocket client connected');
  
  client.sendWithLog = function(message) {
    console.log('Sending ' + message.messageType);
    console.log(message);
    this.send(JSON.stringify(message));
  };

  client.sendWithLog(login1);
});


client.on('close', function(event) {
  console.log('Connection Closed', event.code, event.reason);
github redcap3000 / crypto-socket / index.js View on Github external
makeSocket: function(url, title, onMessage, send) {
        if (typeof url != "string" || typeof title != "string") {
            return false;
        }
        if (typeof Sockets[title] == "undefined" || !Sockets[title]) {
            Sockets[title] = {};
        }
        Sockets[title] = new WebSocket.Client(url);

        try {
            Sockets[title].on('open', function(event) {
                console.log(title + ' open');
                if (typeof Exchanges[title] == "undefined" && title != "gemini2") {
                    Exchanges[title] = {};
                }
            })
        } catch (error) {
            console.log(error);
            return false;

        }
        try {
            Sockets[title].on('close', function(event) {
                console.log(title + ' close');
github tisunov / InstacabDispatcher / client-app.js View on Github external
region: "Коминтерновский район",
    city: "Воронеж",
    longitude: 39.122151,
    latitude: 51.683448    
  }
};

cancelPickup = {
  messageType: "PickupCanceledClient",
  longitude: 39.122151,
  latitude: 51.683448,
  app: 'client',
};

var WebSocket = require('faye-websocket'),
    client    = new WebSocket.Client('ws://localhost:9000/');

var timeId;

client.on('open', function(event) {
  console.log('WebSocket client connected');
  
  client.sendWithLog = function(message) {
    console.log('Sending ' + message.messageType);
    console.log(message);
    this.send(JSON.stringify(message));
  };

  client.sendWithLog(login);

  if (timeId) clearInterval(timerId);
github tjanczuk / git-azure / src / cli / commands / logs.js View on Github external
function connect(prefixes) {
		if (prefixes.length === 0) {
			writelog({
				app: 'git-azure',
				type: 'stderr',
				data: 'Unable to establish a WebSocket connection to either wss://' + config.sanitizedEndpoint 
					+ ' or ws://' + config.sanitizedEndpoint + '.'
			});

			process.exit(1);
		}

		var prefix = prefixes.shift();
		var connected;

		var ws = new WebSocket(prefix + config.endpoint);

		ws.onopen = function () {
			writelog({
				app: 'git-azure',
				type: 'system',
				data: 'Connected to ' + prefix + config.sanitizedEndpoint + '. Waiting for logs...'
			});

			connected = true;
		}

		ws.onclose = function () {
			if (connected) {
				writelog({
					app: 'git-azure',
					type: 'stderr',
github tisunov / InstacabDispatcher / driver-app.js View on Github external
setTimeout(function() {
    client = new WebSocket.Client('ws://localhost:9000/');
  }, 500);
});
github jxcore / jxm / backend / jxm_client.js View on Github external
if (toSocket) {
                    jx_obj.Socket.send(jx_obj.SFirst[o]);
                } else {
                    jx_obj.Send(jx_obj.SFirst[o], false, true);
                }
            }
            jx_obj.SFirst = [];
        }
    };

    if (jx_obj.Socket == null) {


        var url = jx_obj.IsSecure ? "wss://" : "ws://";
        url += jx_obj.SocketURL + ":" + jx_obj.SocketPort + jx_obj.ListenUrl + "c=" + jx_obj.clid + "&sid=" + jx_obj.SecuredKey;
        jx_obj.Socket = new WebSocket.Client(url);

        jx_obj.Socket.on('open', function () {
            jx_obj.SocketOpen = true;
            sendFirsts(true);
        });
        jx_obj.Socket.on('message', function (event) {
            var d = event.data.toString();
            jx_obj.ParseMessages(d);
        });
        jx_obj.Socket.on('error', function (event) {
            jx_obj.Socket = null;
            jx_obj.SocketDisabled = true;
            jx_obj.Act("15", false);

            errorMessage("Socket error. Falling back to reverse ajax: " + event.message.replace(event.target.url, ""));
github gitterHQ / halley / lib / transport / node / node-websocket.js View on Github external
_createWebsocket: function(url) {
    return new WebSocket.Client(url, [], { extensions: this._dispatcher.wsExtensions });
  },
});
github oortcloud / node-ddp-client / lib / ddp-client.js View on Github external
DDPClient.prototype._makeWebSocketConnection = function(url) {
  var self = this;
  self.socket = new WebSocket.Client(url, null, self.tlsOpts);
  self._prepareHandlers();
};

faye-websocket

Standards-compliant WebSocket server and client

Apache-2.0
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis