stayge-ws-client-sdk
    Preparing search index...

    Interface WebSocketClient

    WebSocket client interface for handling real-time communication with the server. Provides methods for connection management, topic subscription, and event handling.

    interface WebSocketClient {
        addEventListener<T>(args: EventListenerParams<T>): void;
        checkConnection(): boolean;
        connect(args: ConnectOptions): void;
        disconnect(): void;
        onConnect(args: { callback: () => void }): void;
        onDisconnect(args: { callback: () => void }): void;
        onError(args: { callback: (error: WsError) => void }): void;
        onMessage<T>(
            args: { callback: (topic: string, payload: T) => void; topic: string },
        ): void;
        removeEventListener<T>(args: EventListenerParams<T>): void;
        setHeartbeatInterval(intervalMs: number): void;
        subscribe(args: { token: string; topic: string }): void;
        unsubscribe(args: { topic: string }): void;
    }
    Index

    Methods

    • 현재 연결 상태를 즉시 반환하고, 필요하면 heartbeat 타이머를 재가동합니다.

      반환값은 내부 ws.readyState 기반입니다. 연결이 OPEN 이면 true, 그 외(연결 시도 중 / 종료 중 / 종료됨 / 미연결)에는 false 입니다.

      추가로, 연결이 OPEN 인데 SDK 내부 heartbeat 타이머가 동작 중이 아니면 타이머를 다시 시작합니다. 모바일에서 백그라운드 진입 시 JS 타이머가 정지/스로틀되어 ping 사이클이 멈춘 경우, 포그라운드 복귀(AppState→active) 직후 이 메서드를 호출하면 연결 상태를 확인하면서 동시에 heartbeat 감지를 즉시 재가동할 수 있습니다.

      • heartbeat 가 비활성화된(connect({ heartbeat: false })) 경우에는 타이머를 시작하지 않고 상태만 반환합니다.

      Returns boolean

      연결이 OPEN 상태면 true, 그 외에는 false

    • Registers a callback function to be called when the WebSocket connection is established.

      Parameters

      • args: { callback: () => void }

        Callback registration arguments

        • callback: () => void

          Function to be called on successful connection

      Returns void

    • Registers a callback function to be called when the WebSocket connection is closed.

      Parameters

      • args: { callback: () => void }

        Callback registration arguments

        • callback: () => void

          Function to be called when connection is closed

      Returns void

    • Registers a callback function to handle WebSocket errors.

      Parameters

      • args: { callback: (error: WsError) => void }

        Callback registration arguments

        • callback: (error: WsError) => void

          Function to be called when an error occurs

      Returns void

    • Registers a callback function to handle incoming messages.

      Type Parameters

      • T

      Parameters

      • args: { callback: (topic: string, payload: T) => void; topic: string }

        Callback registration arguments

        • callback: (topic: string, payload: T) => void

          Function to be called when a message is received

        • topic: string

          The topic of the received message

      Returns void

    • Updates the heartbeat ping interval at runtime.

      적용 동작:

      • heartbeat 가 활성화된 상태에서만 동작합니다. connect({ heartbeat: false }) 로 비활성화된 경우에는 호출이 무시됩니다.
      • 현재 ping 타이머가 동작 중이면 새 주기로 재시작합니다.

      Parameters

      • intervalMs: number

        새로운 ping 전송 주기 (밀리초). 양수여야 합니다.

      Returns void

    • Subscribes to a specific topic with authentication token.

      Parameters

      • args: { token: string; topic: string }

        Subscription arguments

        • token: string

          Authentication token for the subscription

        • topic: string

          The topic to subscribe to

      Returns void

    • Unsubscribes from a previously subscribed topic.

      Parameters

      • args: { topic: string }

        Unsubscription arguments

        • topic: string

          The topic to unsubscribe from

      Returns void