Skip to content

Commit d6165ee

Browse files
committed
feat: remove server-core-integration ddp sockjs compatibility
1 parent 350aa05 commit d6165ee

4 files changed

Lines changed: 7 additions & 63 deletions

File tree

packages/server-core-integration/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"@koa/router": "^15.3.0",
7474
"@sofie-automation/shared-lib": "26.3.0-2",
7575
"ejson": "^2.2.3",
76-
"got": "^11.8.6",
7776
"koa": "^3.1.1",
7877
"tslib": "^2.8.1",
7978
"underscore": "^1.13.7",

packages/server-core-integration/src/lib/ddpClient.ts

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import WebSocket from 'ws'
1010
import * as EJSON from 'ejson'
1111
import { EventEmitter } from 'events'
12-
import got from 'got'
1312
import { ProtectedString } from '@sofie-automation/shared-lib/dist/lib/protectedString'
1413

1514
export 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(/^http/, '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 {

packages/server-core-integration/src/lib/ddpConnector.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export class DDPConnector extends EventEmitter<DDPConnectorEvents> {
3535
path: this._options.path || '',
3636
ssl: this._options.ssl || false,
3737
tlsOpts: this._options.tlsOpts || {},
38-
useSockJs: true,
3938
autoReconnect: false, // we'll handle reconnections ourselves
4039
autoReconnectTimer: 1000,
4140
maintainCollections: true,

packages/yarn.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7170,7 +7170,6 @@ __metadata:
71707170
"@types/koa": "npm:^3.0.1"
71717171
"@types/ws": "npm:^8.5.10"
71727172
ejson: "npm:^2.2.3"
7173-
got: "npm:^11.8.6"
71747173
koa: "npm:^3.1.1"
71757174
tslib: "npm:^2.8.1"
71767175
underscore: "npm:^1.13.7"

0 commit comments

Comments
 (0)