diff --git a/rivetkit-typescript/packages/rivetkit/src/common/inline-websocket-adapter.ts b/rivetkit-typescript/packages/rivetkit/src/common/inline-websocket-adapter.ts index 921eb42041..028cb7e927 100644 --- a/rivetkit-typescript/packages/rivetkit/src/common/inline-websocket-adapter.ts +++ b/rivetkit-typescript/packages/rivetkit/src/common/inline-websocket-adapter.ts @@ -50,6 +50,9 @@ export class InlineWebSocketAdapter implements UniversalWebSocket { readyState: 1, }); + // Set __adapter on WSContext so handleRawWebSocket.onMessage can route messages back + (this.#wsContext as any).__adapter = this; + // Initialize the connection // // Defer initialization to allow event listeners to be attached first @@ -207,6 +210,12 @@ export class InlineWebSocketAdapter implements UniversalWebSocket { this.close(1011, "Internal error during initialization"); } } + /** + * Handle message from actor (called via __adapter from handleRawWebSocket.onMessage) + */ + _handleMessage(event: MessageEvent) { + this.#handleMessage(event.data); + } /** * Handle messages received from the server via the WSContext