Socket.IO 1.1.0 发布

jopen 10年前

今天Socket.IO的1.1.0版本发布。修复了大量的bug和一些新的补充。本次发布得益于超过20贡献者的工作。

Server

  • hasBin no longer iterates over object prototypes (GH#1645) [kevin-roark]
  • Enhanced font styles in the chat example app (GH1653) [acusti]
  • Fixed etag header in server socket.io.js (GH#1655) [ysmood]
  • Fixed repo url in package.json (GH#1673) [bryanburgers]
  • Improved namespace and disconnection tests (GH) [guille]
  • Fixed possible crash on reconnect due to referencing deleted object property (GH#1682) [kevin-roark]
  • Emitting error packet when connecting to non-existing namespace (GH#1688) [fdellabetta]
  • Fixed room removal logic when leaving a room, props (GH#1697) [Marreck]
  • Faster git checkout in travis and SVG travis badge, (GH#1714, GH#1713) [PeterDaveHello]
  • No double utf8 encoding of packets on websocket transport (GH#322) [rase-]
  • Fixed binary decode memory leak (GH#27,GH#28) [christophwitzko, rase-]
  • Better utf8 error handling (GH#29) [nkzawa]
  • Fixed memory leak in websocket usage (GH, GH) [guille, nicokaiser]
  • Possibility to cleanly close the server (GH#1646) [narcisoguillen]
  • Declaring namespaces without the / prefix possible (GH#1729) [asyncanup]
  • The remoteAddress property on the connection is now cached so it should always be accessible (GH#270) [rase-]

Client

  • Better utf8 error handling (GH#316) [nkzawa]
  • reconnect_failed event is now fired only once in socket.io-client (GH#708) [rase-]
  • autoConnect option in socket.io-client, making it possible to disable connecting without explicitly calling manager.open (GH#680, GH#728) [FredyC, nkzawa]
  • Our tests are faster and better than ever using the travis build matrix (GH, GH#335) [tootallnate, rase-, guille]
  • It is now possible to disable JSONP as a transport (GH#314) [rase-]
  • You can now use XDomainRequest to avoid loading bar flashing in IE8 (GH#331 GH#333 GH#334) [yujiosaka]

以下是您可以使用新功能做了一些例子:

现在可以干净地关闭socket.io服务器,如下所示:

var app = require('http').createServer();  var io = require('socket.io')(app);  var fs = require('fs');    app.listen(3333, function() {    io.close();  });

命名空间可以不需要/前缀来声明:

var app = require('http').createServer();  var io = require('socket.io')(app);    // '' and '/' are equal  io.of('').on('connection', function(){    // Connecting to '/' will do the trick  });  // 'abc' and '/abc' are equal  io.of('abc').on('connection', function(){    // Connecting to '/abc' will do the trick  });

现在有一个自动连接的socket.io客户端选项,从而可以禁用连接没有显式调用manager.open。

var manager = io.Manager('http://localhost:9823', { autoConnect: false });  setTimeout(function(){    manager.open(); // Won't start connecting until now  }, 500);

我们的测试比以往任何时候都更快,更好使用travis构建矩阵!
cllp5tsgpta+.png

You can find the example build here!

The remoteAddress property on the connection is now cached so it should always be accessible. It can be accessed either in the handshake object, or directly from engine.io:

io.on('connection', function(socket){    console.log(socket.handshake.address);    console.log(socket.client.conn.remoteAddress);  });

It is now possible to disable JSONP as a transport. If disabled (by settings to false) an error will be emitted (saying “No transports available”) if no other transports can form a connection. If another transport is available for opening a connection (e.g. WebSocket) that transport will be used instead.

var socket = require('engine.io-client')('ws://localhost', { jsonp: false });  socket.on('open', function(){    socket.on('message', function(data){});    socket.on('close', function(){});  });

You can now use XDomainRequest to avoid loading bar flashing in IE8:

var socket = require('engine.io-client')('ws://localhost', { enablesXDR: true });  socket.on('open', function(){    socket.on('message', function(data){});    socket.on('close', function(){});  });

The option defaults to false because XDomainRequest has a known flaw of not sending cookies.

Socket.IO-client 1.1.0 can be found in the Socket.IO CDN:

<script src="https://cdn.socket.io/socket.io-1.1.0.js"></script>

A big thank you to everyone who participated in the making of the release by reporting issues, getting involved in discussion, and/or contributing code. Keep being awesome, and stay tuned for more updates!