Skip to content

Commit

Permalink
fix(js): Allow JS to use custom WebSocket implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jun 29, 2023
1 parent b82483b commit f7fad26
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion js/src/SmartConnect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function wsConnect(publicAPI, model) {
urls: model.config.sessionURL,
secret: model.config.secret,
retry: model.config.retry,
wsProxy: model.config.iframe || model.config.wsProxy,
});
model.subscriptions.push(
wsConnection.onConnectionReady(publicAPI.readyForwarder)
Expand Down Expand Up @@ -137,7 +138,7 @@ function smartConnect(publicAPI, model) {
function cleanUp(timeout) {
if (session) {
if (timeout > 0) {
session.call("application.exit.later", [timeout]);
session.call('application.exit.later', [timeout]);
}
session.close();
}
Expand Down
9 changes: 7 additions & 2 deletions js/src/WebsocketConnection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ function WebsocketConnection(publicAPI, model) {
}
}
try {
model.connection = new WebSocket(transports[0].url);
if (model.wsProxy) {
model.connection = new WSLINK.WebSocket(transports[0].url);
} else {
model.connection = new WebSocket(transports[0].url);
}
} catch (err) {
// If the server isn't running, we still don't enter here on Chrome -
// console shows a net::ERR_CONNECTION_REFUSED error inside WebSocket
Expand Down Expand Up @@ -111,7 +115,7 @@ function WebsocketConnection(publicAPI, model) {
model.session &&
timeout > 0
) {
model.session.call("application.exit.later", [timeout]);
model.session.call('application.exit.later', [timeout]);
}
if (model.connection) {
model.connection.close();
Expand All @@ -127,6 +131,7 @@ const DEFAULT_VALUES = {
connection: null,
session: null,
retry: false,
wsProxy: false, // Use WSLINK.WebSocket if true else native WebSocket
};

export function extend(publicAPI, model, initialValues = {}) {
Expand Down

0 comments on commit f7fad26

Please sign in to comment.