Skip to content

Commit

Permalink
fix: websocket outbound transport (#1788)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Auer <[email protected]>
  • Loading branch information
auer-martin authored Mar 8, 2024
1 parent d2b5cd9 commit ed06d00
Showing 1 changed file with 8 additions and 12 deletions.
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)))
if (isNewSocket && !outboundPackage.responseRequested) {
socket.close()
}
}

private hasOpenSocket(socketId: string) {
Expand Down

0 comments on commit ed06d00

Please sign in to comment.