Skip to content
Closed
Show file tree
Hide file tree
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
12 changes: 5 additions & 7 deletions engine/sdks/typescript/runner/src/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { MessageId, RequestId } from "@rivetkit/engine-runner-protocol";
import type { Logger } from "pino";
import {
parse as uuidparse,

Check warning on line 5 in engine/sdks/typescript/runner/src/tunnel.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

Several of these imports are unused.

Check warning on line 5 in engine/sdks/typescript/runner/src/tunnel.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

Several of these imports are unused.

Check warning on line 5 in engine/sdks/typescript/runner/src/tunnel.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

Several of these imports are unused.

Check warning on line 5 in engine/sdks/typescript/runner/src/tunnel.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

Several of these imports are unused.

Check warning on line 5 in engine/sdks/typescript/runner/src/tunnel.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

Several of these imports are unused.

Check warning on line 5 in engine/sdks/typescript/runner/src/tunnel.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

Several of these imports are unused.

Check warning on line 5 in engine/sdks/typescript/runner/src/tunnel.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

Several of these imports are unused.
stringify as uuidstringify,
v4 as uuidv4,
} from "uuid";
Expand Down Expand Up @@ -317,15 +317,15 @@
},
});
},
(code?: number, reason?: string, hibernate: boolean = false) => {
(code?: number, reason?: string) => {
// Send close through tunnel if engine doesn't already know it's closed
if (!engineAlreadyClosed) {
this.#sendMessage(requestId, {
tag: "ToServerWebSocketClose",
val: {
code: code || null,
reason: reason || null,
hibernate,
hibernate: false,
},
});
}
Expand Down Expand Up @@ -397,7 +397,7 @@
// TODO: Switch this with runner WS
if (!this.#runner.__webSocketReady()) {
this.log?.warn({
msg: "cannot send tunnel message, socket not connected to engine",
msg: "cannot send tunnel message, socket not connected to engine. tunnel data dropped.",
requestId: idToStr(requestId),
message: stringifyToServerTunnelMessageKind(messageKind),
});
Expand Down Expand Up @@ -513,10 +513,7 @@
const webSocket = actor.webSockets.get(requestIdStr);
if (webSocket) {
// Close the WebSocket connection
webSocket._closeWithHibernate(
1000,
"Message acknowledgment timeout",
);
webSocket.close(1000, "ws.ack_timeout");

// Clean up from webSockets map
actor.webSockets.delete(requestIdStr);
Expand Down Expand Up @@ -1070,6 +1067,7 @@
if (actor) {
const adapter = actor.webSockets.get(requestIdStr);
if (adapter) {
// We don't need to send a close response
adapter._handleClose(
requestId,
close.code || undefined,
Expand Down
19 changes: 5 additions & 14 deletions engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@
/** @experimental */
public readonly request: Request,
sendCallback: (data: ArrayBuffer | string, isBinary: boolean) => void,
closeCallback: (
code?: number,
reason?: string,
hibernate?: boolean,
) => void,
closeCallback: (code?: number, reason?: string) => void,
) {
this.#tunnel = tunnel;
this.#actorId = actorId;
Expand Down Expand Up @@ -233,7 +229,7 @@
code?: number,
reason?: string,
): void {
this.#closeInner(code, reason, false, true);
this.#closeInner(code, reason, true);
}

_handleError(error: Error): void {
Expand All @@ -246,12 +242,8 @@
this.#fireEvent("error", event);
}

_closeWithHibernate(code?: number, reason?: string): void {
this.#closeInner(code, reason, true, true);
}

_closeWithoutCallback(code?: number, reason?: string): void {
this.#closeInner(code, reason, false, false);
this.#closeInner(code, reason, false);
}

#fireEvent(type: string, event: any): void {
Expand Down Expand Up @@ -328,7 +320,6 @@
#closeInner(
code: number | undefined,
reason: string | undefined,
hibernate: boolean,
callback: boolean,
): void {
if (
Expand All @@ -342,7 +333,7 @@

// Send close through tunnel
if (callback) {
this.#closeCallback(code, reason, hibernate);
this.#closeCallback(code, reason);
}

// Update state and fire event
Expand Down Expand Up @@ -500,13 +491,13 @@
}

close(code?: number, reason?: string): void {
this.#closeInner(code, reason, false, true);
this.#closeInner(code, reason, true);
}

addEventListener(
type: string,
listener: (event: any) => void,
options?: boolean | any,

Check warning on line 500 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 500 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 500 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 500 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 500 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.
): void {
if (typeof listener === "function") {
let listeners = this.#eventListeners.get(type);
Expand All @@ -521,7 +512,7 @@
removeEventListener(
type: string,
listener: (event: any) => void,
options?: boolean | any,

Check warning on line 515 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 515 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 515 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 515 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.
): void {
if (typeof listener === "function") {
const listeners = this.#eventListeners.get(type);
Expand All @@ -531,7 +522,7 @@
}
}

dispatchEvent(event: any): boolean {

Check warning on line 525 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 525 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 525 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 525 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 525 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 525 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.
// TODO:
return true;
}
Expand All @@ -547,12 +538,12 @@
readonly CLOSED = 3;

// Additional methods for compatibility
ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void {

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 541 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.
// Not implemented for tunnel - could be added if needed
if (cb) cb(new Error("Ping not supported in tunnel adapter"));
}

pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void {

Check warning on line 546 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 546 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 546 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 546 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 546 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 546 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 546 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.

Check warning on line 546 in engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedFunctionParameters

This parameter is unused.
// Not implemented for tunnel - could be added if needed
if (cb) cb(new Error("Pong not supported in tunnel adapter"));
}
Expand Down
Loading