99import WebSocket from 'ws'
1010import * as EJSON from 'ejson'
1111import { EventEmitter } from 'events'
12- import got from 'got'
1312import { ProtectedString } from '@sofie-automation/shared-lib/dist/lib/protectedString'
1413
1514export interface DDPTLSOptions {
@@ -42,7 +41,6 @@ export interface DDPConnectorOptions {
4241 autoReconnect ?: boolean // default: true
4342 autoReconnectTimer ?: number
4443 tlsOpts ?: DDPTLSOptions
45- useSockJs ?: boolean
4644 url ?: string
4745 maintainCollections ?: boolean
4846 ddpVersion ?: '1' | 'pre2' | 'pre1'
@@ -357,10 +355,6 @@ export class DDPClient extends EventEmitter<DDPClientEvents> {
357355 public get ssl ( ) : boolean {
358356 return this . sslInt
359357 }
360- private useSockJSInt ! : boolean
361- public get useSockJS ( ) : boolean {
362- return this . useSockJSInt
363- }
364358 private autoReconnectInt ! : boolean
365359 public get autoReconnect ( ) : boolean {
366360 return this . autoReconnectInt
@@ -420,7 +414,6 @@ export class DDPClient extends EventEmitter<DDPClientEvents> {
420414 this . pathInt = opts . path
421415 this . sslInt = opts . ssl || this . port === 443
422416 this . tlsOpts = opts . tlsOpts || { }
423- this . useSockJSInt = opts . useSockJs || false
424417 this . autoReconnectInt = opts . autoReconnect === false ? false : true
425418 this . autoReconnectTimerInt = opts . autoReconnectTimer || 500
426419 this . maintainCollectionsInt = opts . maintainCollections || true
@@ -693,14 +686,7 @@ export class DDPClient extends EventEmitter<DDPClientEvents> {
693686 } )
694687 }
695688
696- if ( this . useSockJS ) {
697- this . makeSockJSConnection ( ) . catch ( ( e ) => {
698- this . emit ( 'failed' , e )
699- } )
700- } else {
701- const url = this . buildWsUrl ( )
702- this . makeWebSocketConnection ( url )
703- }
689+ this . makeWebSocketConnection ( this . buildWsUrl ( ) )
704690 }
705691
706692 private endPendingMethodCalls ( ) : void {
@@ -727,53 +713,14 @@ export class DDPClient extends EventEmitter<DDPClientEvents> {
727713 }
728714 }
729715
730- private async makeSockJSConnection ( ) : Promise < void > {
731- const protocol = this . ssl ? 'https://' : 'http://'
732- if ( this . path && ! this . path ?. endsWith ( '/' ) ) {
733- this . pathInt = this . path + '/'
734- }
735- const url = `${ protocol } ${ this . host } :${ this . port } /${ this . path || '' } sockjs/info`
736-
737- try {
738- const response = await got ( url , {
739- headers : this . getHeadersWithDefaults ( ) ,
740- https : {
741- certificateAuthority : this . tlsOpts . ca ,
742- key : this . tlsOpts . key ,
743- certificate : this . tlsOpts . cert ,
744- checkServerIdentity : this . tlsOpts . checkServerIdentity ,
745- rejectUnauthorized : this . tlsOpts . rejectUnauthorized !== false ,
746- } ,
747- responseType : 'json' ,
748- } )
749- // Info object defined here(?): https://github.com/sockjs/sockjs-node/blob/master/lib/info.js
750- const info = response . body as { base_url : string }
751- if ( ! info || ! info . base_url ) {
752- const url = this . buildWsUrl ( )
753- this . makeWebSocketConnection ( url )
754- } else if ( info . base_url . indexOf ( 'http' ) === 0 ) {
755- const url = ( info . base_url + '/websocket' ) . replace ( / ^ h t t p / , 'ws' )
756- this . makeWebSocketConnection ( url )
757- } else {
758- const path = info . base_url + '/websocket'
759- const url = this . buildWsUrl ( path )
760- this . makeWebSocketConnection ( url )
761- }
762- } catch ( err ) {
763- this . recoverNetworkError ( err )
764- }
765- }
766-
767- private buildWsUrl ( path ?: string ) : string {
768- let url : string
769- path = path || this . path || 'websocket'
770- const protocol = this . ssl ? 'wss://' : 'ws://'
771- if ( this . url && ! this . useSockJS ) {
772- url = this . url
716+ private buildWsUrl ( ) : string {
717+ if ( this . url ) {
718+ return this . url
773719 } else {
774- url = `${ protocol } ${ this . host } :${ this . port } ${ path . indexOf ( '/' ) === 0 ? path : '/' + path } `
720+ const path = this . path || 'websocket'
721+ const protocol = this . ssl ? 'wss://' : 'ws://'
722+ return `${ protocol } ${ this . host } :${ this . port } ${ path . indexOf ( '/' ) === 0 ? path : '/' + path } `
775723 }
776- return url
777724 }
778725
779726 private makeWebSocketConnection ( url : string ) : void {
0 commit comments