socket.svelte.ts

Declarations
#

8 declarations

view source

FailedMessage
#

QueuedMessage
#

Socket
#

socket.svelte.ts view source

Socket class for WebSocket connection management with auto-reconnect and message queueing.

inheritance

extends:
  • Cell<typeof SocketJson>

ws

type WebSocket | null

open

type boolean

status

type AsyncStatus

last_send_time

type number | null

last_receive_time

type number | null

last_connect_time

type number | null

heartbeat_timeout

type NodeJS.Timeout | null

reconnect_count

type number

reconnect_attempt

type number

reconnect_timeout

type NodeJS.Timeout | null

current_reconnect_delay

type number

message_queue

type Array<QueuedMessage>

failed_messages

type SvelteMap<string, FailedMessage>

connected

type boolean

readonly

can_send

type boolean

readonly

has_queued_messages

type boolean

readonly

queued_message_count

type number

readonly

failed_message_count

type number

readonly

connection_duration

type number | null

readonly

connection_duration_rounded

type number | null

readonly

constructor

type new (options: SocketOptions): Socket

options

connect

Connects to the WebSocket server.

type (url?: string | null): void

url

The WebSocket URL to connect to

type string | null
default null
returns void

disconnect

Disconnects from the WebSocket server.

type (code?: number): void

code

The close code to use (default: 1000 - normal closure)

type number
default DEFAULT_CLOSE_CODE
returns void

send

Sends a message through the WebSocket.

type (data: object): boolean

data

The data to send

type object
returns boolean

True if the message was sent immediately, false if queued or failed

update_url

Updates the connection URL and reconnects if currently connected.

type (url: string): void

url

The new WebSocket URL

type string
returns void

send_heartbeat

Sends a ping message for heartbeat purposes

type (): Promise<void>

returns Promise<void>

retry_queued_messages

Retry sending all queued messages.

type (): void

returns void

clear_failed_messages

Clear the failed messages list

type (): void

returns void

maybe_reconnect

type (): void

returns void

cancel_reconnect

Cancel any pending reconnection attempt.

type (): void

returns void

add_message_handler

Add a message handler and return a function to remove it.

type (handler: SocketActionHandler): () => void

handler

The message handler to add

returns () => void

A function that removes the handler when called

add_error_handler

Add an error handler and return a function to remove it.

type (handler: SocketErrorHandler): () => void

handler

The error handler to add

returns () => void

A function that removes the handler when called

SocketActionHandler
#

SocketErrorHandler
#

SocketJson
#

socket.svelte.ts view source

ZodObject<{ id: ZodDefault<$ZodBranded<ZodUUID, "Uuid">>; created: ZodDefault<$ZodBranded<ZodISODateTime, "Datetime">>; ... 6 more ...; auto_reconnect: ZodDefault<...>; }, $strict>

SocketJsonInput
#

socket.svelte.ts view source

{ id?: string | undefined; created?: string | undefined; updated?: string | undefined; url?: string | null | undefined; url_input?: string | undefined; heartbeat_interval?: number | undefined; reconnect_delay?: number | undefined; reconnect_delay_max?: number | undefined; auto_reconnect?: boolean | undefined; }

SocketOptions
#

Depends on
#

Imported by
#