Skip to content

Commit

Permalink
fix(WebSocketTransport): encode all query string params
Browse files Browse the repository at this point in the history
Resolves an issue where the react-native websocket constructor crashes
due to space characters being included in the ws url (in web and nodejs
the websocket constructor will just url encode it automatically).
  • Loading branch information
owenpearson committed May 22, 2023
1 parent d9573c2 commit 61ec742
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/common/lib/transport/websockettransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ class WebSocketTransport extends Transport {
}

createWebSocket(uri: string, connectParams: Record<string, string>) {
let paramCount = 0;
if (connectParams) {
for (const key in connectParams) uri += (paramCount++ ? '&' : '?') + key + '=' + connectParams[key];
}
this.uri = uri;
return new Platform.Config.WebSocket(uri);
this.uri = uri + Utils.toQueryString(connectParams);
return new Platform.Config.WebSocket(this.uri);
}

toString() {
Expand Down Expand Up @@ -66,6 +62,7 @@ class WebSocketTransport extends Transport {
return;
}
const connectParams = params.getConnectParams(authParams);
console.log({connectParams});
try {
const wsConnection = (self.wsConnection = self.createWebSocket(wsUri, connectParams));
wsConnection.binaryType = Platform.Config.binaryType;
Expand Down

0 comments on commit 61ec742

Please sign in to comment.