Example #1
0
        socket.on('open', function () {
          socket.on('message', function (msg) {
            expect(msg).to.not.be('this should not be handled');
          });

          socket.on('close', function (reason) {
            expect(reason).to.be('forced close');
          });
        });
Example #2
0
 var engine = listen({}, function (port) {
   var socket = new eioc.Socket('ws://localhost:%d'.s(port), { });
   socket.on('handshake', function (obj) {
     expect(obj.upgrades).to.have.length(2);
     expect(obj.upgrades).to.have.contain('flashsocket');
     expect(obj.upgrades).to.have.contain('websocket');
     done();
   });
 });
Example #3
0
 var engine = listen({ allowUpgrades: false }, function (port) {
   var socket = new eioc.Socket('ws://localhost:%d'.s(port));
   socket.on('handshake', function (obj) {
     expect(obj.sid).to.be.a('string');
     expect(obj.pingTimeout).to.be.a('number');
     expect(obj.upgrades).to.be.an('array');
     done();
   });
 });
Example #4
0
 .end(function (err, res) {
   expect(err).to.be(null);
   expect(res.status).to.be(400);
   expect(res.body.code).to.be(3);
   socket.send('echo');
   socket.on('message', function (msg) {
     expect(msg).to.be('echo');
     done();
   });
 });
Example #5
0
 var engine = listen(opts, function (port) {
   var socket = new eioc.Socket('http://invalidserver:%d'.s(port));
   socket.on('open', function(){
     done(new Error('Test invalidation'));
   });
   socket.on('close', function(reason){
     expect(reason).to.be('transport error');
     done();
   });
 });
Example #6
0
 var engine = listen({ allowUpgrades: true }, function (port) {
   var socket = new eioc.Socket('ws://localhost:%d'.s(port));
   socket.on('open', function () {
     socket.close();
     // we wait until complete to see if we get an uncaught EPIPE
     setTimeout(function(){
       done();
     }, 100);
   });
 });
Example #7
0
        socket.on('open', function () {
          socket.send('a');
          socket.on('close', function (reason) {
            expect(reason).to.be('forced close');
            --total || done();
          });

          setTimeout(function () {
            socket.close();
          }, 10);
        });
Example #8
0
 var engine = listen(opts, function (port) {
   var socket = new eioc.Socket('http://localhost:%d'.s(port));
   socket.on('open', function(){
     done(new Error('Test invalidation'));
   });
   socket.on('close', function(reason){
     expect(reason).to.be('forced close');
     done();
   });
   socket.close();
 });
Example #9
0
 var engine = listen(opts, function (port) {
   var socket = new eioc.Socket('ws://localhost:%d'.s(port));
   socket.on('open', function () {
     // override onPacket to simulate an inactive server after handshake
     socket.onPacket = function(){};
     socket.on('close', function (reason, err) {
       expect(reason).to.be('ping timeout');
       done();
     });
   });
 });
Example #10
0
 var engine = listen(opts, function (port) {
   var socket = new eioc.Socket('ws://localhost:%d'.s(port));
   socket.close();
   socket.on('open', function(){
     throw new Error('Nope');
   });
   socket.on('close', function(){
     throw new Error('Nope');
   });
   setTimeout(done, 100);
 });
Example #11
0
      var engine = listen('should trigger when server closes a client', opts, function (port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] })
          , total = 1;

        socket.on('open', function () {
          socket.on('close', function (reason) {
            expect(reason).to.be('transport close');
            --total || done();
          });
        });
      });
Example #12
0
      var engine = listen('should trigger when server closes a client', { allowUpgrades: false }, function (port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port))
          , total = 1;

        socket.on('open', function () {
          socket.on('close', function (reason) {
            expect(reason).to.be('transport close');
            --total || done();
          });
        });
      });
Example #13
0
      var engine = listen({ allowUpgrades: false }, function (port) {
        expect(Object.keys(engine.clients)).to.have.length(0);
        expect(engine.clientsCount).to.be(0);

        var socket = new eioc.Socket('ws://localhost:%d'.s(port));
        socket.on('open', function () {
          expect(Object.keys(engine.clients)).to.have.length(1);
          expect(engine.clientsCount).to.be(1);
          done();
        });
      });
Example #14
0
 var engine = listen({ allowUpgrades: false }, function (port) {
   var socket = new eioc.Socket('ws://localhost:%d'.s(port));
   engine.on('connection', function (conn) {
     conn.send('a');
   });
   socket.on('open', function () {
     socket.on('message', function (msg) {
       expect(msg).to.be('a');
       done();
     });
   });
 });
Example #15
0
 var engine = listen(opts, function (port) {
   var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
   engine.on('connection', function (conn) {
     conn.send('a');
   });
   socket.on('open', function () {
     socket.on('message', function (msg) {
       expect(msg).to.be('a');
       done();
     });
   });
 });
Example #16
0
      var engine = listen('should arrive when binary data sent as Buffer (polling)', opts, function(port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });

        socket.on('open', function () {
          socket.on('message', function(msg) {
            for (var i = 0; i < binaryData.length; i++) {
              var num = msg.readInt8(i);
              expect(num).to.be(i);
            }
            done();
          });
        });
      });
Example #17
0
          socket.on('upgrading', function (to) {
            // we want to make sure for the sake of this test that we have a buffer
            expect(to.name).to.equal('websocket');
            upgrades++;

            // force send a few packets to ensure we test buffer transfer
            lastSent++;
            socket.send(lastSent);
            lastSent++;
            socket.send(lastSent);

            expect(socket.writeBuffer).to.not.be.empty();
          });
Example #18
0
      var engine = listen('should upgrade', function (port) {
        // it takes both to send 50 to verify
        var ready = 1, closed = 1;
        function finish () {
          setTimeout(function () {
            socket.close();
          }, 10);
        }

        // client
        var socket = new eioc.Socket('ws://localhost:%d'.s(port));
        socket.on('open', function () {
          var lastSent = 0, lastReceived = 0, upgrades = 0;
          var interval = setInterval(function () {
            lastSent++;
            socket.send(lastSent);
            if (50 == lastSent) {
              clearInterval(interval);
              --ready || finish();
            }
          }, 2);
          socket.on('upgrading', function (to) {
            // we want to make sure for the sake of this test that we have a buffer
            expect(to.name).to.equal('websocket');
            upgrades++;

            // force send a few packets to ensure we test buffer transfer
            lastSent++;
            socket.send(lastSent);
            lastSent++;
            socket.send(lastSent);

            expect(socket.writeBuffer).to.not.be.empty();
          });
          socket.on('upgrade', function (to) {
            expect(to.name).to.equal('websocket');
            upgrades++;
          });
          socket.on('message', function (msg) {
            lastReceived++;
            expect(lastReceived).to.eql(msg);
          });
          socket.on('close', function (reason) {
            expect(reason).to.be('forced close');
            expect(lastSent).to.be(50);
            expect(lastReceived).to.be(50);
            expect(upgrades).to.be(2);
            --closed || done();
          });
        });
      });
Example #19
0
 var engine = listen({ allowUpgrades: false }, function (port) {
   var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
   var totalEvents = 2;
   socket.on('open', function() {
     socket.send('a');
     socket.send('b');
     // writeBuffer should be nonempty, with 'a' still in it
     expect(socket.writeBuffer.length).to.eql(2);
   });
   socket.transport.on('drain', function() {
     expect(socket.writeBuffer.length).to.eql(--totalEvents);
     totalEvents || done();
   });
 });
Example #20
0
 socket.on('open', function() {
   socket.on('close', function (reason) {
     expect(socket.writeBuffer.length).to.be(1);
     expect(socket.callbackBuffer.length).to.be(1);
     setTimeout(function() {
       expect(socket.writeBuffer.length).to.be(0);
       expect(socket.callbackBuffer.length).to.be(0);
     }, 10);
     done();
   });
   socket.writeBuffer.push({ type: 'message', data: 'foo'});
   socket.callbackBuffer.push(function() {});
   socket.onError('');
 });
Example #21
0
      var engine = listen('should arrive from server to client (multiple)', { allowUpgrades: false }, function (port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port))
          , expected = ['a', 'b', 'c']
          , i = 0;

        socket.on('open', function () {
          socket.on('message', function (msg) {
            expect(msg).to.be(expected[i++]);
            if (i == 3) {
              done();
            }
          });
        });
      });
Example #22
0
      var engine = listen('should arrive from server to client (multiple)', opts, function (port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] })
          , expected = ['a', 'b', 'c']
          , i = 0;

        socket.on('open', function () {
          socket.on('message', function (msg) {
            expect(msg).to.be(expected[i++]);
            if (i == 3) {
              done();
            }
          });
        });
      });
Example #23
0
      var engine = listen('should trigger on server if the client does not pong', opts, function (port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port))
          , total = 1;

        function onClose (reason, err) {
          expect(reason).to.be('ping timeout');
          --total || done();
        }

        socket.on('open', function () {
          // override onPacket to simulate an inactive server after handshake
          socket.onPacket = socket.sendPacket = function(){};
          socket.on('close', onClose);
        });
      });
Example #24
0
      var engine = listen('should trigger when client closes', { allowUpgrades: false }, function (port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port))
          , total = 2;

        socket.on('open', function () {
          socket.on('close', function (reason) {
            expect(reason).to.be('forced close');
            done();
          });

          setTimeout(function () {
            socket.close();
          }, 10);
        });
      });
Example #25
0
      var engine = listen('should trigger when client closes', opts, function (port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] })
          , total = 1;

        socket.on('open', function () {
          socket.on('close', function (reason) {
            expect(reason).to.be('forced close');
            --total || done();
          });

          setTimeout(function () {
            socket.close();
          }, 10);
        });
      });
Example #26
0
      var engine = listen('should trigger early with connection `transport close` after missing pong', opts, function (port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port));
        var clientCloseReason = null;

        socket.on('open', function () {
          socket.on('close', function (reason) {
            clientCloseReason = reason;
          });
        });

        setTimeout(function() {
          expect(clientCloseReason).to.be('transport close');
          done();
        }, 300);
      });
Example #27
0
function connect() {
	client = new eio.Socket((protocol === 'https:' ? 'wss:' : 'ws:') + '//' + host, {
		jsonp: 'document' in window && 'createElement' in window.document // Disable JSONP in non-web environments, e.g.- react-native
	});

	client.on('close', disconnected);

	client.on('open', () => {
		backOff = 1;
		bus.emit('change', {
			state: { connectionStatus: 'online', backOff }
		});
	});

	client.on('message', onMessage);
}
Example #28
0
 socket.on('open', function () {
   socket.close();
   // we wait until complete to see if we get an uncaught EPIPE
   setTimeout(function(){
     done();
   }, 100);
 });
Example #29
0
      var engine = listen( { allowUpgrades: false, transports: ['polling'] }, function (port) {
        var socket = new eioc.Socket('ws://localhost:' + port, { transports: ['polling'], forceJSONP: true, upgrade: false});
        engine.on('connection', function (conn) {
          conn.on('message', function (msg) {
            conn.send(msg);
          });
        });

        socket.on('open', function() {
          socket.send(binaryData);
          socket.on('message', function (msg) {
            for (var i = 0; i < msg.length; i++) expect(msg[i]).to.be(i);
            done();
          });
        });
      });
Example #30
0
      var engine = listen('should arrive when binary data sent as Buffer (polling)', opts, function(port) {
        var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });

        socket.binaryType = 'arraybuffer';
        socket.on('open', function() {
          socket.on('message', function(msg) {
            expect(msg instanceof ArrayBuffer).to.be(true);
            var intArray = new Int8Array(msg);
            for (var i = 0; i < binaryData.length; i++) {
              expect(intArray[i]).to.be(i);
            }

            done();
          });
        });
      });