Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复 React Devtools 会监听所有 WebSocket 链接的问题 (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Jun 28, 2020
1 parent 69be3c6 commit 875182d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/remax-plugin-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"url": "https://github.com/remaxjs/remax/issues"
},
"dependencies": {
"@remax/react-devtools-core": "^4.7.0",
"@remax/react-devtools-core": "^4.7.1",
"@remax/shared": "2.5.5",
"webpack-inject-plugin": "^1.5.4"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,43 @@ export default class WebSocket {
onerror?: any;
onclose?: any;
onmessage?: any;
ws: any;

constructor(url: string) {
this.readyState = ReadyState.CONNECTING;

this.ws = global.connectSocket({
global.connectSocket({
url,
});

this.ws.onOpen(() => {
global.onSocketOpen(() => {
this.readyState = ReadyState.OPEN;
if (typeof this.onopen === 'function') {
this.onopen();
}
});

this.ws.onError((res: any) => {
global.onSocketError((res: any) => {
if (typeof this.onerror === 'function') {
this.onerror(res);
}
});

this.ws.onClose(() => {
global.onSocketClose(() => {
this.readyState = ReadyState.CLOSED;
if (typeof this.onclose === 'function') {
this.onclose();
}
});

this.ws.onMessage((res: any) => {
global.onSocketMessage((res: any) => {
if (typeof this.onmessage === 'function') {
this.onmessage(res);
}
});
}

send(payload: any) {
this.ws.send({
global.sendSocketMessage({
data: payload,
});
}
Expand Down
13 changes: 7 additions & 6 deletions packages/remax-plugin-devtools/src/WebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,44 @@ export default class WebSocket {
onerror?: any;
onclose?: any;
onmessage?: any;
ws: any;

constructor(url: string) {
this.readyState = ReadyState.CONNECTING;

global.connectSocket({
this.ws = global.connectSocket({
url,
});

global.onSocketOpen(() => {
this.ws.onOpen(() => {
this.readyState = ReadyState.OPEN;
if (typeof this.onopen === 'function') {
this.onopen();
}
});

global.onSocketError((res: any) => {
this.ws.onError((res: any) => {
if (typeof this.onerror === 'function') {
this.onerror(res);
}
});

global.onSocketClose(() => {
this.ws.onClose(() => {
this.readyState = ReadyState.CLOSED;
if (typeof this.onclose === 'function') {
this.onclose();
}
});

global.onSocketMessage((res: any) => {
this.ws.onMessage((res: any) => {
if (typeof this.onmessage === 'function') {
this.onmessage(res);
}
});
}

send(payload: any) {
global.sendSocketMessage({
this.ws.send({
data: payload,
});
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2682,10 +2682,10 @@
object-assign "^4.1.1"
postcss "^6.0.19"

"@remax/react-devtools-core@^4.7.0":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@remax/react-devtools-core/-/react-devtools-core-4.7.0.tgz#ba643d7220a654f136d9bb9fdf47cf4c1e6c2f2a"
integrity sha512-KY8kIuJADkTMOe+o0wozhHD+2Fp7503j1MVe3Ndt3aVhGS9bRVwkQ+mA+v0SXxfmA77cD14LYCTPdHDKiYlpRg==
"@remax/react-devtools-core@^4.7.1":
version "4.7.1"
resolved "https://registry.yarnpkg.com/@remax/react-devtools-core/-/react-devtools-core-4.7.1.tgz#e1caacf8b83733db65111b4c6800b7c6f67a85d4"
integrity sha512-9kS22dkKvgOmOjVwfkOeLJWxr9XwY2HTbhErdfHPQDnCtHN9RUoloeGfWoXo11tKs/EzpH6GProbM9uVBCzqLQ==
dependencies:
shell-quote "^1.6.1"
ws "^7"
Expand Down

1 comment on commit 875182d

@vercel
Copy link

@vercel vercel bot commented on 875182d Jun 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.