Socket.IO 1.2.0

Socket.IO 1.2.0 is now live with important bug fixes and a few API updates. We couldn’t have made this happen without the help of old and new contributors. A big hand to everyone who participated in the making of this release. Thank you!

Below you can find more details on the changes and some code examples.

Server

  • Fixed the npm main property in the chat example (GH#1766) [BrianGeppert]
  • Some grammar fixes to the chat example strings (GH#1784) [matthewcanty]
  • Fixed room autopruning (memory leak fix) (GH#2 GH#12) [hallucynogenyc & rase-]
  • Added tests to check room autopruning (GH#1792) [rase-]
  • Fixed the backwards compatibility option for the resource option when used through .set (GH#1690) [rase-]
  • Replaced the server constructor without the new keyword in README with createServer to avoid confusion (GH#1626) [thanpolas]
  • Fixed grammar issues in the README (GH#1788) [jamesanthonyferguson]
  • The origins option now takes a function so allowed origins can dynamically change at run time (GH#1777) [akamensky]
  • Fixed the Server#close example (GH#1773) [AjayMT]
  • Fixed typo in README code example (GH#280) [reem]
  • Added missing support for XSS filters on IE (GH#254) [pawelatomic]
  • Allow upgrades if a socket is still in closing state (GH#285) [lpinca & 3rd-Eden]
  • Updated the debug module in socket.io-adapter (GH#7) [keskival]
  • Fixed jsonp tests for transport close deferring (GH#289) [rase-]
  • Fixed the install issue of the indexOf module (GH#16) [rase-]

Client

  • Fixed binary transport check if the content-type header contains a charset (GH#342) [bimusiek]
  • When upgrading wait for it to finish before closing transport (GH#356) [nkzawa]
  • Fixed close defer tests (GH#346) [rase-]
  • Fixed “jsonp polling iframe removal error” on connection close (GH#349) [aaronk6]
  • Fixed namespace tests after dependency upgrade in socket.io server [rauchg]
  • Possibility to use a relative url without schema (GH#754) [toshipon]
  • Fixed manual reconnection via connect function (now public API) (GH#732) [nkzawa]
  • Updated repository url (GH#762) [haqii]
  • Delaying transport closing until the drain event to send all packets left in the buffer (GH#351, GH#352) [nkzawa & rase-]
  • Now supports PhantomJS (GH#34) [divdavem]
  • Fixed an error in strict mode (GH#355) [nkzawa]
  • Had priority XHR over XDR (GH#341) [yujiosaka]
  • Enabled to stop reconnection attempts (GH#766) [nkzawa]
  • Fixed reconnection after reconnecting manually (GH#767) [nkzawa]
  • Fixed reconnection tests (GH#768) [rase-]

socket.io-redis

  • Prettier badges (GH#12) [Krinkle]
  • Readme updates to instruct in Redis authentication (GH#24) [Siedrix]

Here are examples of the new API functionality:

You can now specify a function to detect the origins instead of using the string representation (though the string representation still works as usual):

var sockets = io({
  origins: function (origin, fn) {
    if (origin == 'http://foo.example') {
      return fn(null, true);
    }
    return fn(null, false);
  }
});

Relative urls without protocol now work when initializing the client:

var socket = io('//localhost:3000');

You can also now manage reconnection manually:

var socket = io({ forceNew: true });

socket.once('connect', function() {
  socket.disconnect();
});

socket.once('disconnect', function() {
  socket.once('connect', function() {
    console.log('Connected for the second time!');
  });
  socket.connect();
});

As usual, you can get the new client through our CDN:

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