Skip to content

Commit 5217fd8

Browse files
authored
refactor: change sockjs to ws for customclient
1 parent 54976c9 commit 5217fd8

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

test/fixtures/custom-client/CustomSockJSClient.js renamed to test/fixtures/custom-client/CustomWebSocketClient.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@
22

33
const SockJS = require("sockjs-client/dist/sockjs");
44

5-
module.exports = class SockJSClient {
5+
module.exports = class WebSocketClient {
66
constructor(url) {
7-
this.sock = new SockJS(
8-
url.replace(/^ws:/i, "http://").replace(/^wss:/i, "https://"),
9-
);
7+
this.client = new WebSocket(url);
8+
this.client.onerror = (error) => {
9+
console.error(error);
10+
};
1011
}
1112

1213
onOpen(f) {
13-
this.sock.onopen = () => {
14+
this.client.onopen = () => {
1415
console.log("open");
1516
f();
1617
};
1718
}
1819

1920
onClose(f) {
20-
this.sock.onclose = () => {
21+
this.client.onclose = () => {
2122
console.log("close");
2223
f();
2324
};
2425
}
2526

2627
// call f with the message string as the first argument
2728
onMessage(f) {
28-
this.sock.onmessage = (e) => {
29+
this.client.onmessage = (e) => {
2930
const obj = JSON.parse(e.data);
3031
console.log(obj.type);
3132
f(e.data);

test/fixtures/provide-plugin-custom/foo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
// 'npm run prepare' must be run for this to work during testing
4-
const CustomClient = require("../../fixtures/custom-client/CustomSockJSClient");
4+
const CustomClient = require("../custom-client/CustomWebSocketClient");
55

66
window.expectedClient = CustomClient;
77
// eslint-disable-next-line camelcase, no-undef

0 commit comments

Comments
 (0)