@ikonai/sdk 1.0.57 → 1.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app-messaging.d.ts +51 -0
- package/client/connection-state.d.ts +19 -3
- package/client/ikon-client.d.ts +15 -7
- package/index.d.ts +1 -0
- package/index.js +244 -196
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ProtocolMessage } from '../../../shared/protocol/src/index.ts';
|
|
2
|
+
import { IkonClient } from './client/ikon-client';
|
|
3
|
+
/**
|
|
4
|
+
* Describes one app-local Teleport message type, tying together the opcode and
|
|
5
|
+
* the encode/decode functions emitted by `ikon app teleport build` for a
|
|
6
|
+
* `Schema/*.tp` type. Build one from the generated module's exports, e.g.:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { STROKE_INPUT_OPCODE, toProtocolMessageStrokeInput, fromProtocolMessageStrokeInputAsync,
|
|
10
|
+
* type StrokeInput } from './generated/protocol/stroke-input';
|
|
11
|
+
*
|
|
12
|
+
* const StrokeInputMessage: AppMessageType<StrokeInput> = {
|
|
13
|
+
* opcode: STROKE_INPUT_OPCODE,
|
|
14
|
+
* toProtocolMessage: toProtocolMessageStrokeInput,
|
|
15
|
+
* fromProtocolMessage: fromProtocolMessageStrokeInputAsync,
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface AppMessageType<T> {
|
|
20
|
+
/** The message's `GROUP_APP_LOCAL` opcode (the `X_OPCODE` constant). */
|
|
21
|
+
readonly opcode: number;
|
|
22
|
+
/** Generated `toProtocolMessageX` — encodes a native value into a wire message. */
|
|
23
|
+
toProtocolMessage(value: T, senderId: number): ProtocolMessage;
|
|
24
|
+
/** Generated `fromProtocolMessageXAsync` — decodes a wire message to the native value. */
|
|
25
|
+
fromProtocolMessage(message: ProtocolMessage): Promise<T> | T;
|
|
26
|
+
}
|
|
27
|
+
/** Handle returned by {@link AppMessaging.on}; call {@link close} to unsubscribe. */
|
|
28
|
+
export interface AppMessageSubscription {
|
|
29
|
+
close(): void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Typed app↔server custom-message helper, the browser counterpart of the C#
|
|
33
|
+
* `app.SendMessage<T>` / `app.OnMessage<T>`. Sends and receives an app's own
|
|
34
|
+
* `Schema/*.tp` types as native objects over the app-local Teleport channel
|
|
35
|
+
* (`GROUP_APP_LOCAL`) — no JSON marshalling. Use it for high-frequency side
|
|
36
|
+
* data (strokes, cursors, game state) alongside the declarative reactive UI.
|
|
37
|
+
*/
|
|
38
|
+
export declare class AppMessaging {
|
|
39
|
+
private readonly client;
|
|
40
|
+
constructor(client: IkonClient);
|
|
41
|
+
/** Send a typed app message to the server. */
|
|
42
|
+
send<T>(type: AppMessageType<T>, value: T): void;
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to inbound app messages of one type (filtered by its opcode).
|
|
45
|
+
* The handler receives the decoded native payload and the sender's session id.
|
|
46
|
+
* Dispose the returned handle to unsubscribe.
|
|
47
|
+
*/
|
|
48
|
+
on<T>(type: AppMessageType<T>, handler: (payload: T, senderId: number) => void): AppMessageSubscription;
|
|
49
|
+
}
|
|
50
|
+
/** Create an {@link AppMessaging} helper bound to a client. */
|
|
51
|
+
export declare function appMessaging(client: IkonClient): AppMessaging;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Connection state managed by IkonClient.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* Live states (currently emitted by the runtime):
|
|
5
|
+
* - `waitingForExternalConnectUrl` — preview mode, waiting for the parent window to post a connect URL.
|
|
6
|
+
* - `connecting` — actively trying to connect. The `isConnectingSlow` boolean on the React layer flips true after a timeout.
|
|
7
|
+
* - `connected` — successfully connected.
|
|
8
|
+
* - `reconnecting` — was connected, lost the socket, retrying.
|
|
9
|
+
* - `offline` — gave up. The companion `error` field (or `IkonClient.lastError`) carries an optional message.
|
|
10
|
+
*
|
|
11
|
+
* Deprecated states are kept in the union so existing string-equality checks in user code keep type-checking;
|
|
12
|
+
* the runtime no longer transitions into them.
|
|
4
13
|
*/
|
|
5
|
-
export type ConnectionState =
|
|
14
|
+
export type ConnectionState =
|
|
15
|
+
/** @deprecated No longer emitted. Initial state is now `connecting`. */
|
|
16
|
+
'idle' | 'waitingForExternalConnectUrl' | 'connecting'
|
|
17
|
+
/** @deprecated No longer emitted. Use `useIkonApp().isConnectingSlow` (boolean) instead. */
|
|
18
|
+
| 'connectingSlow' | 'connected' | 'reconnecting' | 'offline'
|
|
19
|
+
/** @deprecated No longer emitted. Offline-with-error is now `offline` with the message on `useIkonApp().error`. */
|
|
20
|
+
| 'offlineError';
|
|
6
21
|
/**
|
|
7
22
|
* Check if the state indicates the client is actively trying to connect.
|
|
8
23
|
*/
|
|
@@ -12,10 +27,11 @@ export declare function isConnecting(state: ConnectionState): boolean;
|
|
|
12
27
|
*/
|
|
13
28
|
export declare function isConnected(state: ConnectionState): boolean;
|
|
14
29
|
/**
|
|
15
|
-
* Check if the state indicates the client is offline
|
|
30
|
+
* Check if the state indicates the client is offline.
|
|
16
31
|
*/
|
|
17
32
|
export declare function isOffline(state: ConnectionState): boolean;
|
|
18
33
|
/**
|
|
19
34
|
* Check if the state indicates an error condition.
|
|
35
|
+
* @deprecated The runtime no longer emits `offlineError`. Read `useIkonApp().error` to detect offline-with-error.
|
|
20
36
|
*/
|
|
21
37
|
export declare function isError(state: ConnectionState): boolean;
|
package/client/ikon-client.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export type StateHandler = (state: ConnectionState) => void;
|
|
|
66
66
|
*
|
|
67
67
|
* Features:
|
|
68
68
|
* - Manages connection lifecycle
|
|
69
|
-
* - Provides UI-friendly connection states (
|
|
69
|
+
* - Provides UI-friendly connection states (waitingForExternalConnectUrl, connecting, connected, reconnecting, offline)
|
|
70
70
|
* - Handles timeouts for connection establishment
|
|
71
71
|
* - Passes protocol messages to application via callback
|
|
72
72
|
* - Multi-channel support (core, audio, video on separate connections)
|
|
@@ -96,7 +96,7 @@ export declare class IkonClient {
|
|
|
96
96
|
private authResponse;
|
|
97
97
|
private _connectUrl;
|
|
98
98
|
private currentState;
|
|
99
|
-
private
|
|
99
|
+
private _connectStarted;
|
|
100
100
|
private connectionTimer;
|
|
101
101
|
private messageSubscribers;
|
|
102
102
|
private subscriberHandlers;
|
|
@@ -105,7 +105,14 @@ export declare class IkonClient {
|
|
|
105
105
|
private stateSubscribers;
|
|
106
106
|
private abortController;
|
|
107
107
|
private readonly config;
|
|
108
|
-
private readonly
|
|
108
|
+
private readonly _slowConnectionThresholdMs;
|
|
109
|
+
/**
|
|
110
|
+
* Time (ms) after which a still-`connecting` session should be considered "slow"
|
|
111
|
+
* by the React layer (see `useIkonApp().isConnectingSlow`). The SDK no longer
|
|
112
|
+
* transitions state for it — exposed here so the React timer can honor the
|
|
113
|
+
* config value if the host overrides it.
|
|
114
|
+
*/
|
|
115
|
+
get slowConnectionThresholdMs(): number;
|
|
109
116
|
private readonly connectionTimeoutMs;
|
|
110
117
|
private readonly actionAckTimeoutMs;
|
|
111
118
|
private readonly _pendingActionAcks;
|
|
@@ -203,8 +210,8 @@ export declare class IkonClient {
|
|
|
203
210
|
constructor(config: IkonClientConfig);
|
|
204
211
|
private _lastError;
|
|
205
212
|
/**
|
|
206
|
-
* Get the error that
|
|
207
|
-
* Returns undefined
|
|
213
|
+
* Get the error that drove the client into the `offline` state, if any.
|
|
214
|
+
* Returns undefined when offline-without-error or when not in offline state.
|
|
208
215
|
*/
|
|
209
216
|
get lastError(): Error | undefined;
|
|
210
217
|
private _sessionId;
|
|
@@ -343,8 +350,9 @@ export declare class IkonClient {
|
|
|
343
350
|
*/
|
|
344
351
|
private setState;
|
|
345
352
|
/**
|
|
346
|
-
*
|
|
347
|
-
*
|
|
353
|
+
* Go offline with an associated error message stored on `lastError`.
|
|
354
|
+
* Used for unrecoverable SDK internal errors. The state itself is `offline`; the error
|
|
355
|
+
* is surfaced via the companion field so consumers don't need a separate state to handle.
|
|
348
356
|
*/
|
|
349
357
|
private setErrorState;
|
|
350
358
|
private connectProtocol;
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { IkonClient, type ProtocolMessageHandler, type StateHandler, type ProtocolMessageSubscriptionOptions, type ProtocolMessagePort, type ProtocolSendPort, type WebRTCTrackMapInfo } from './client/ikon-client';
|
|
2
|
+
export { AppMessaging, appMessaging, type AppMessageType, type AppMessageSubscription } from './app-messaging';
|
|
2
3
|
export type { IkonClientConfig, LocalConfig, ApiKeyConfig, SessionTokenConfig, CloudConnectionConfig, CommonConnectionConfig, TimeoutConfig, BackendType, AudioConfig, VideoConfig, MediaSessionConfig, WebRtcConfig } from './client/ikon-client-config';
|
|
3
4
|
export type { ConnectionState } from './client/connection-state';
|
|
4
5
|
export { isConnecting, isConnected, isOffline, isError } from './client/connection-state';
|