Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #113 from Jxck/master

#99 `packet` event
  • Loading branch information...
commit 95f0614626606079ebe24ae4f4b99caad7ac5238 2 parents 92df787 + 46f3104
@rauchg rauchg authored
Showing with 35 additions and 0 deletions.
  1. +4 −0 lib/socket.js
  2. +31 −0 test/server.js
View
4 lib/socket.js
@@ -76,6 +76,10 @@ Socket.prototype.onOpen = function () {
Socket.prototype.onPacket = function (packet) {
if ('open' == this.readyState) {
+ // export packet event
+ debug('packet');
+ this.emit('packet', packet);
+
// Reset ping timeout on any packet, incoming data is a good sign of
// other side's liveness
this.setPingTimeout();
View
31 test/server.js
@@ -910,6 +910,37 @@ describe('server', function () {
});
});
+ describe('packet', function() {
+ it('should emit when socket receives packet', function (done) {
+ var engine = listen({ allowUpgrades: false }, function (port) {
+ var socket = new eioc.Socket('ws://localhost:%d'.s(port));
+ engine.on('connection', function (conn) {
+ conn.on('packet', function (packet) {
+ expect(packet.type).to.be('message');
+ expect(packet.data).to.be('a');
+ done();
+ });
+ });
+ socket.on('open', function () {
+ socket.send('a');
+ });
+ });
+ });
+
+ it('should emit when receives ping', function (done) {
+ var engine = listen({ allowUpgrades: false, pingInterval: 4 }, function (port) {
+ var socket = new eioc.Socket('ws://localhost:%d'.s(port));
+ engine.on('connection', function (conn) {
+ conn.on('packet', function (packet) {
+ conn.close();
+ expect(packet.type).to.be('ping');
+ done();
+ });
+ });
+ });
+ });
+ });
+
describe('upgrade', function () {
it('should upgrade', function (done) {
var engine = listen(function (port) {
Please sign in to comment.
Something went wrong with that request. Please try again.