Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 4ee657d

Browse files
committed
refactor
1 parent 44ba94c commit 4ee657d

4 files changed

Lines changed: 10 additions & 17 deletions

File tree

src/v2/core/Socket/SocketConnection.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export class SocketConnection {
1717
private queue: { transaction: Transaction, promise: PromiseObject<any, any> }[] = []
1818
private queueTimer: Timer = new Timer()
1919
protected WebSocket: WebSocketWrapper
20-
private callListener: (listenerId: string, params?: any[]) => any[]
20+
private callListener: (listenerId: string, params?: any[]) => void
2121
private connectionProgress: Transaction | null = null
2222
private disconnectionProgress: Transaction | null = null
2323
private XAPI: XAPI
2424

25-
constructor(url: string, callListener: (listenerId: string, params?: any[]) => any[], socketId: string, XAPI: XAPI) {
25+
constructor(url: string, callListener: (listenerId: string, params?: any[]) => void, socketId: string, XAPI: XAPI) {
2626
this.socketId = socketId
2727
this.callListener = callListener
2828
this.XAPI = XAPI
@@ -51,13 +51,11 @@ export class SocketConnection {
5151
this.lastReceivedMessage = new Time()
5252
try {
5353
const message = JSON.parse(json.toString().trim())
54+
this.XAPI.counter.count(['data', 'SocketConnection', 'incomingData'], json.length)
5455

55-
try {
56-
this.handleMessage(message, new Time(), json, socketId)
57-
} catch (e) {
58-
console.error(e)
59-
}
56+
this.handleMessage(message, new Time(), json, socketId)
6057
} catch (e) {
58+
this.XAPI.counter.count(['error', 'SocketConnection', 'handleMessage'])
6159
this.callListener('handleMessage', [{
6260
command: null,
6361
error: e,

src/v2/core/Socket/SocketConnections.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class SocketConnections extends Listener {
3636
json: params.json,
3737
})
3838
} else {
39-
this.XAPI.counter.count(['data', 'SocketConnections', 'incomingData'], params.json.length)
4039
elapsedMs !== undefined && this.XAPI.counter.count(['data', 'SocketConnection', 'responseTime', 'handleMessage',
4140
transaction.state.command || 'undefined_command'],
4241
elapsedMs
@@ -89,7 +88,7 @@ export class SocketConnections extends Listener {
8988
const socketId = `${new Date().getTime()}${this.socketIdIncrement.id}`
9089
this.connections[socketId] = new SocketConnection(
9190
this.url,
92-
(listenerId: string, params?: any[]) => this.fetchListener(listenerId, params),
91+
(listenerId: string, params?: any[]) => this.callListener(listenerId, params),
9392
socketId,
9493
this.XAPI
9594
)

src/v2/core/Stream/StreamConnection.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export class StreamConnection {
1515
public streamId: string
1616
private queue: { transaction: Transaction }[] = []
1717
private queueTimer: Timer = new Timer()
18-
private callListener: (listenerId: string, params?: any[]) => any[]
18+
private callListener: (listenerId: string, params?: any[]) => void
1919
private connectionProgress: Transaction | null = null
2020
private disconnectionProgress: Transaction | null = null
2121
private XAPI: XAPI
2222

23-
constructor(url: string, session: string, callListener: (listenerId: string, params?: any[]) => any[], streamId: string, socketId: string, XAPI: XAPI) {
23+
constructor(url: string, session: string, callListener: (listenerId: string, params?: any[]) => void, streamId: string, socketId: string, XAPI: XAPI) {
2424
this.session = session
2525
this.socketId = socketId
2626
this.streamId = streamId
@@ -52,11 +52,7 @@ export class StreamConnection {
5252
const message = JSON.parse(json.toString().trim())
5353
this.XAPI.counter.count(['data', 'StreamConnection', 'incomingData'], json.length)
5454

55-
try {
56-
this.callListener(`command_${message.command}`, [message.data, new Time(), json, streamId])
57-
} catch (e) {
58-
console.error(e)
59-
}
55+
this.callListener(`command_${message.command}`, [message.data, new Time(), json, streamId])
6056
} catch (e) {
6157
this.XAPI.counter.count(['error', 'StreamConnection', 'handleMessage'])
6258
this.callListener(`handleMessage`, [{error: e, time: new Time(), json, streamId}])

src/v2/core/Stream/StreamConnections.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class StreamConnections extends Listener {
4848
streamIdIncrement = new Increment()
4949
public async connect(timeoutMs: number, session: string, socketId: string): Promise<string> {
5050
const streamId = `${new Date().getTime()}${this.streamIdIncrement.id}`
51-
this.connections[streamId] = new StreamConnection(this.url, session, (listenerId: string, params?: any[]) => this.fetchListener(listenerId, params), streamId, socketId, this.XAPI)
51+
this.connections[streamId] = new StreamConnection(this.url, session, (listenerId: string, params?: any[]) => this.callListener(listenerId, params), streamId, socketId, this.XAPI)
5252
await this.connections[streamId].connect(timeoutMs)
5353
return streamId
5454
}

0 commit comments

Comments
 (0)