Skip to content
Open
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion src/gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export interface ServerPayload {
height: number
width: number
windows: SerializedWindow[]
session?: string
active?: boolean
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

/*
* The gate class abstracts a host connection
*/
export class Gate {
sessionId?: string
activeW: Window
addr: string
boarding: boolean
Expand Down Expand Up @@ -154,6 +156,16 @@ export class Gate {
const e = this.e.querySelector(".tabbar-names") as HTMLElement
e.style.setProperty("--indicator-color", color)
}

private newSessionId(): string {
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
const bytes = new Uint8Array(16)
crypto.getRandomValues(bytes)
return Array.from(bytes).map(b => b.toString(16).padStart(2, "0")).join("")
}
return Math.random().toString(16).slice(2) + Math.random().toString(16).slice(2)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/*
* onSessionState(state) is called when the connection
* state changes.
Expand Down Expand Up @@ -691,7 +703,8 @@ export class Gate {
const container = this.e.querySelector(".windows-container") as HTMLDivElement
return { windows: windows,
width: container.clientWidth,
height: container.clientHeight }
height: container.clientHeight,
session: this.sessionId }
}
storeState() {
/* TODO: restore the restore to last state
Expand Down