Skip to content

Commit 2ff6e4c

Browse files
committed
fix: compatibility for old android versions
1 parent 6c8ab56 commit 2ff6e4c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/plugins/websocket/www/websocket.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,21 @@ class WebSocketInstance extends EventTarget {
5858

5959
if (event.type === 'close') {
6060
this.readyState = WebSocketInstance.CLOSED;
61-
const closeEvent = new CloseEvent('close', { code: event.data?.code, reason: event.data?.reason });
61+
const closeData = event && event.data ? event.data : {};
62+
const closeEvent = new CloseEvent('close', {
63+
code: closeData.code,
64+
reason: closeData.reason,
65+
});
6266
if (this.onclose) this.onclose(closeEvent);
6367
this.dispatchEvent(closeEvent);
6468
}
6569

6670
if (event.type === 'error') {
67-
const errorEvent = new Event('error', { message: event?.data });
71+
const errorMessage = event && event.data ? event.data : undefined;
72+
const errorEvent = new Event('error');
73+
if (errorMessage !== undefined) {
74+
errorEvent.message = errorMessage;
75+
}
6876
if (this.onerror) this.onerror(errorEvent);
6977
this.dispatchEvent(errorEvent);
7078
}

0 commit comments

Comments
 (0)