Skip to content

Commit 3c5777a

Browse files
committed
Upgrade to latest version of socket.io. Fixes #1847
1 parent a7c14c8 commit 3c5777a

File tree

4 files changed

+6817
-6619
lines changed

4 files changed

+6817
-6619
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*! https://mths.be/utf8js v2.1.2 by @mathias */
2+
3+
/**
4+
* @license AngularJS v1.4.14
5+
* (c) 2010-2015 Google, Inc. http://angularjs.org
6+
* License: MIT
7+
*/
8+
9+
/**
10+
* @license AngularJS v1.8.2
11+
* (c) 2010-2020 Google LLC. http://angularjs.org
12+
* License: MIT
13+
*/

packages/browser-sync/lib/sockets.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ module.exports.init = function(server, clientEvents, bs) {
3434

3535
var socketIoConfig = socketConfig.socketIoOptions;
3636
socketIoConfig.path = socketConfig.path;
37+
// set pingTimeout from clients.heartbeatTimeout after heartbeat reversal in engine.io@4
38+
// https://socket.io/blog/engine-io-4-release/#Heartbeat-mechanism-reversal
39+
socketIoConfig.pingTimeout = socketConfig.clients.heartbeatTimeout;
40+
// enable cors for any domain after socket.io@3
41+
// https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#cors-handling
42+
socketIoConfig.cors = {
43+
origins: (origin, callback) => callback(null, origin)
44+
}
3745

46+
// create instance of socket.io Server
3847
var io = socket(server, socketIoConfig);
48+
// move internal sockets property back to connected to maintain backwards compatibility after socket.io@3
49+
// https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#namespaceconnected-is-renamed-to-namespacesockets-and-is-now-a-map
3950

40-
// Override default namespace.
41-
io.sockets = io.of(socketConfig.namespace);
42-
43-
io.set("heartbeat interval", socketConfig.clients.heartbeatTimeout);
44-
45-
// Breaking change was introduced https://socket.io/blog/socket-io-2-4-0/
46-
io.origins((_, callback) => {
47-
callback(null, true);
48-
});
51+
io.connected = io.sockets
52+
io.sockets = io.of(socketConfig.namespace)
4953

5054
/**
5155
* Listen for new connections

0 commit comments

Comments
 (0)