Skip to content

Commit f7035c8

Browse files
authored
Merge branch 'master' into refactor/cli-flags
2 parents 425b535 + 2dd1093 commit f7035c8

File tree

6 files changed

+134
-64
lines changed

6 files changed

+134
-64
lines changed

client-src/clients/SockJSClient.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const BaseClient = require('./BaseClient');
77
module.exports = class SockJSClient extends BaseClient {
88
constructor(url) {
99
super();
10-
this.sock = new SockJS(url);
10+
const sockUrl = url.replace(/^(?:chrome-extension|file)/i, 'http');
11+
this.sock = new SockJS(sockUrl);
1112

1213
this.sock.onerror = (err) => {
1314
log.error(err);

client-src/clients/WebsocketClient.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const BaseClient = require('./BaseClient');
88
module.exports = class WebsocketClient extends BaseClient {
99
constructor(url) {
1010
super();
11-
this.client = new WebSocket(url.replace(/^http/, 'ws'));
11+
const wsUrl = url.replace(/^(?:http|chrome-extension|file)/i, 'ws');
12+
this.client = new WebSocket(wsUrl);
1213

1314
this.client.onerror = (err) => {
1415
log.error(err);

package-lock.json

Lines changed: 108 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"url": "^0.11.0",
6464
"util": "^0.12.3",
6565
"webpack-dev-middleware": "^4.0.2",
66-
"ws": "^7.4.1"
66+
"ws": "^7.4.2"
6767
},
6868
"devDependencies": {
6969
"@babel/cli": "^7.12.10",
@@ -85,7 +85,7 @@
8585
"eslint-plugin-import": "^2.22.1",
8686
"execa": "^5.0.0",
8787
"file-loader": "^6.2.0",
88-
"html-webpack-plugin": "^4.5.0",
88+
"html-webpack-plugin": "^4.5.1",
8989
"husky": "^4.3.6",
9090
"jest": "^26.6.3",
9191
"jest-circus": "^26.6.3",

test/client/clients/SockJSClient.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ describe('SockJSClient', () => {
7272
done();
7373
}, 3000);
7474
});
75+
it('should change the protocol from chrome-extension to http', (done) => {
76+
const client = new SockJSClient('chrome-extension://localhost');
77+
expect(client.sock.url).toEqual('http://localhost');
78+
done();
79+
});
80+
it('should change the protocol from file to http', (done) => {
81+
const client = new SockJSClient('file://localhost');
82+
expect(client.sock.url).toEqual('http://localhost');
83+
done();
84+
});
7585
});
7686

7787
afterAll((done) => {

test/client/clients/WebsocketClient.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ describe('WebsocketClient', () => {
6565
done();
6666
}, 3000);
6767
});
68+
it('should change the protocol from chrome-extension to http', (done) => {
69+
const client = new WebsocketClient('chrome-extension://localhost/');
70+
expect(client.client.url).toEqual('ws://localhost/');
71+
done();
72+
});
73+
it('should change the protocol from file to http', (done) => {
74+
const client = new WebsocketClient('file://localhost/');
75+
expect(client.client.url).toEqual('ws://localhost/');
76+
done();
77+
});
6878
});
6979

7080
afterAll((done) => {

0 commit comments

Comments
 (0)