Skip to content

Commit fd10c2a

Browse files
committed
feat: ws reconnect report connection info
1 parent a120d5e commit fd10c2a

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

packages/connection/src/browser/ws-channel-handler.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { WSChannel, MessageString } from '../common/ws-channel';
1010
export class WSChannelHandler {
1111
public connection: WebSocket;
1212
private channelMap: Map<number | string, WSChannel> = new Map();
13+
private channelCloseEventMap: Map<number | string, { code: number; reason: string }> = new Map();
1314
private logger = console;
1415
public clientId: string;
1516
private heartbeatMessageTimer: NodeJS.Timer | null;
@@ -79,7 +80,14 @@ export class WSChannelHandler {
7980
if (this.channelMap.size) {
8081
this.channelMap.forEach((channel) => {
8182
channel.onOpen(() => {
82-
this.reporterService && this.reporterService.point(REPORT_NAME.CHANNEL_RECONNECT);
83+
const closeEvent = this.channelCloseEventMap.get(channel.id);
84+
const connectInfo = window.navigator.connection;
85+
this.reporterService &&
86+
this.reporterService.point(REPORT_NAME.CHANNEL_RECONNECT, REPORT_NAME.CHANNEL_RECONNECT, {
87+
closeEvent,
88+
connectInfo,
89+
channelPath: channel.channelPath,
90+
});
8391
this.logger && this.logger.log(`channel reconnect ${this.clientId}:${channel.channelPath}`);
8492
});
8593
channel.open(channel.channelPath);
@@ -91,6 +99,14 @@ export class WSChannelHandler {
9199
});
92100
}
93101
});
102+
103+
this.connection.addEventListener('close', (event) => {
104+
if (this.channelMap.size) {
105+
this.channelMap.forEach((channel) => {
106+
channel.close(event.code, event.reason);
107+
});
108+
}
109+
});
94110
});
95111
}
96112
private getChannelSend = (connection) => (content: string) => {
@@ -110,6 +126,10 @@ export class WSChannelHandler {
110126
channel.onOpen(() => {
111127
resolve(undefined);
112128
});
129+
channel.onClose((code: number, reason: string) => {
130+
this.channelCloseEventMap.set(channelId, { code, reason });
131+
this.logger.log('channel close: ', code, reason);
132+
});
113133
channel.open(channelPath);
114134
});
115135

0 commit comments

Comments
 (0)