Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support file: and chrome-extension: protocols in client #2954

Merged
merged 1 commit into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion client-src/clients/SockJSClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const BaseClient = require('./BaseClient');
module.exports = class SockJSClient extends BaseClient {
constructor(url) {
super();
this.sock = new SockJS(url);
const sockUrl = url.replace(/^(?:chrome-extension|file)/i, 'http');
this.sock = new SockJS(sockUrl);

this.sock.onerror = (err) => {
log.error(err);
Expand Down
3 changes: 2 additions & 1 deletion client-src/clients/WebsocketClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const BaseClient = require('./BaseClient');
module.exports = class WebsocketClient extends BaseClient {
constructor(url) {
super();
this.client = new WebSocket(url.replace(/^http/, 'ws'));
const wsUrl = url.replace(/^(?:http|chrome-extension|file)/i, 'ws');
this.client = new WebSocket(wsUrl);

this.client.onerror = (err) => {
log.error(err);
Expand Down
10 changes: 10 additions & 0 deletions test/client/clients/SockJSClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ describe('SockJSClient', () => {
done();
}, 3000);
});
it('should change the protocol from chrome-extension to http', (done) => {
const client = new SockJSClient('chrome-extension://localhost');
expect(client.sock.url).toEqual('http://localhost');
done();
});
it('should change the protocol from file to http', (done) => {
const client = new SockJSClient('file://localhost');
expect(client.sock.url).toEqual('http://localhost');
done();
});
});

afterAll((done) => {
Expand Down
10 changes: 10 additions & 0 deletions test/client/clients/WebsocketClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ describe('WebsocketClient', () => {
done();
}, 3000);
});
it('should change the protocol from chrome-extension to http', (done) => {
const client = new WebsocketClient('chrome-extension://localhost/');
expect(client.client.url).toEqual('ws://localhost/');
done();
});
it('should change the protocol from file to http', (done) => {
const client = new WebsocketClient('file://localhost/');
expect(client.client.url).toEqual('ws://localhost/');
done();
});
});

afterAll((done) => {
Expand Down