@@ -345,28 +345,32 @@ var SocketIOServer = function(spec, portal, observer) {
345
345
// A Socket.IO server has a unique reconnection key. Client cannot reconnect to another Socket.IO server in the cluster.
346
346
var reconnection_key = require ( 'crypto' ) . randomBytes ( 64 ) . toString ( 'hex' ) ;
347
347
var sioOptions = { } ;
348
+ // TODO: remove allowEIO3
349
+ sioOptions . allowEIO3 = true ;
348
350
if ( spec . pingInterval ) {
349
351
sioOptions . pingInterval = spec . pingInterval * 1000 ;
350
352
}
351
353
if ( spec . pingTimeout ) {
352
354
sioOptions . pingTimeout = spec . pingTimeout * 1000 ;
353
355
}
354
-
355
- var startInsecure = function ( port , cors ) {
356
- var server = require ( 'http' ) . createServer ( ) . listen ( port ) ;
357
- io = require ( 'socket.io' ) . listen ( server , sioOptions ) ;
358
- io . origins ( ( origin , callback ) => {
359
- if ( cors . indexOf ( origin ) < 0 && cors . indexOf ( '*' ) < 0 ) {
356
+ if ( spec . cors ) {
357
+ sioOptions . cors = { credentials : true } ;
358
+ sioOptions . cors . origin = ( origin , callback ) => {
359
+ if ( spec . cors . indexOf ( origin ) < 0 && spec . cors . indexOf ( '*' ) < 0 ) {
360
360
return callback ( 'origin not allowed' , false ) ;
361
361
}
362
-
363
362
callback ( null , true ) ;
364
- } ) ;
363
+ } ;
364
+ }
365
+
366
+ var startInsecure = function ( port ) {
367
+ var server = require ( 'http' ) . createServer ( ) . listen ( port ) ;
368
+ io = require ( 'socket.io' ) ( server , sioOptions ) ;
365
369
run ( ) ;
366
370
return Promise . resolve ( 'ok' ) ;
367
371
} ;
368
372
369
- var startSecured = function ( port , cors , keystorePath , forceTlsv12 ) {
373
+ var startSecured = function ( port , keystorePath , forceTlsv12 ) {
370
374
return new Promise ( function ( resolve , reject ) {
371
375
var cipher = require ( './cipher' ) ;
372
376
var keystore = path . resolve ( path . dirname ( keystorePath ) , cipher . kstore ) ;
@@ -378,13 +382,7 @@ var SocketIOServer = function(spec, portal, observer) {
378
382
option . secureOptions = ( constants . SSL_OP_NO_TLSv1 | constants . SSL_OP_NO_TLSv1_1 ) ;
379
383
}
380
384
var server = require ( 'https' ) . createServer ( option ) . listen ( port ) ;
381
- io = require ( 'socket.io' ) . listen ( server , sioOptions ) ;
382
- io . origins ( ( origin , callback ) => {
383
- if ( cors . indexOf ( origin ) < 0 && cors . indexOf ( '*' ) < 0 ) {
384
- return callback ( 'origin not allowed' , false ) ;
385
- }
386
- callback ( null , true ) ;
387
- } ) ;
385
+ io = require ( 'socket.io' ) ( server , sioOptions ) ;
388
386
run ( ) ;
389
387
resolve ( 'ok' ) ;
390
388
} else {
@@ -430,9 +428,9 @@ var SocketIOServer = function(spec, portal, observer) {
430
428
431
429
that . start = function ( ) {
432
430
if ( ! spec . ssl ) {
433
- return startInsecure ( spec . port , spec . cors ) ;
431
+ return startInsecure ( spec . port ) ;
434
432
} else {
435
- return startSecured ( spec . port , spec . cors , spec . keystorePath , spec . forceTlsv12 ) ;
433
+ return startSecured ( spec . port , spec . keystorePath , spec . forceTlsv12 ) ;
436
434
}
437
435
} ;
438
436
0 commit comments