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: websocket outbound transport #1788

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions packages/core/src/transport/WsOutboundTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,14 @@ export class WsOutboundTransport implements OutboundTransport {
const isNewSocket = !this.hasOpenSocket(socketId)
const socket = await this.resolveSocket({ socketId, endpoint, connectionId })

return new Promise<void>((resolve, reject) =>
socket.send(Buffer.from(JSON.stringify(payload)), (err) => {
// If the socket was created for this message and we don't have return routing enabled
// We can close the socket as it shouldn't return messages anymore
if (isNewSocket && !outboundPackage.responseRequested) {
socket.close()
}

if (err) return reject(err)
resolve()
})
)
// If the socket was created for this message and we don't have return routing enabled
// We can close the socket as it shouldn't return messages anymore
// make sure to use the socket in a manner that is compliant with the https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
// (React Native) and https://github.com/websockets/ws (NodeJs)
socket.send(Buffer.from(JSON.stringify(payload)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We technically could send just a string instead of a buffer with both these interfaces, but it should not matter that much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the method sync in RN? And if we don't provide a callback, is it sync in NodeJS as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't checked it, but there is likely an overload to not provide a callback as you don't have to handle the res/err if you don't want. But yeah it would be good to do a test run with this in both environments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be fine. It's also the behavior that was there up until 2-3 weeks ago.

if (isNewSocket && !outboundPackage.responseRequested) {
socket.close()
}
}

private hasOpenSocket(socketId: string) {
Expand Down
Loading