@haex-space/vault-sdk 4.8.1 → 4.10.0
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/README.md +61 -0
- package/dist/{client-CNbwFQjB.d.ts → client-DTxLSJrk.d.mts} +194 -4
- package/dist/{client-DOAj36ga.d.mts → client-s0eCQoWA.d.ts} +194 -4
- package/dist/index.d.mts +54 -7
- package/dist/index.d.ts +54 -7
- package/dist/index.js +215 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +211 -2
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +209 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +209 -1
- package/dist/react.mjs.map +1 -1
- package/dist/runtime/nuxt.plugin.client.js +206 -1
- package/dist/runtime/nuxt.plugin.client.js.map +1 -1
- package/dist/runtime/nuxt.plugin.client.mjs +206 -1
- package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
- package/dist/svelte.d.mts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +209 -1
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +209 -1
- package/dist/svelte.mjs.map +1 -1
- package/dist/{types-3iifP-Q1.d.mts → types-BZVkX0Wf.d.mts} +24 -2
- package/dist/{types-3iifP-Q1.d.ts → types-BZVkX0Wf.d.ts} +24 -2
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +209 -1
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +209 -1
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -43,6 +43,23 @@ declare const MODEL_JOB_EVENTS: {
|
|
|
43
43
|
readonly COMPLETED: "haextension:model-job:completed";
|
|
44
44
|
};
|
|
45
45
|
type ModelJobEvent = typeof MODEL_JOB_EVENTS[keyof typeof MODEL_JOB_EVENTS];
|
|
46
|
+
/**
|
|
47
|
+
* Events of peer channels (`client.peers`, holzi spec 057). The SDK's
|
|
48
|
+
* `peers.on` takes the names without the `peers:` prefix.
|
|
49
|
+
*/
|
|
50
|
+
declare const PEERS_EVENTS: {
|
|
51
|
+
/** The outcome of an invitation, once per invitation (inviting side). */
|
|
52
|
+
readonly INVITE_STATUS: "peers:invite-status";
|
|
53
|
+
/** A channel opened after the user accepted an invitation in holzi's prompt (invited side). */
|
|
54
|
+
readonly CHANNEL_OPENED: "peers:channel-opened";
|
|
55
|
+
/** A device joined one of this device's lobbies by code (host). */
|
|
56
|
+
readonly JOINED: "peers:joined";
|
|
57
|
+
/** A message on a channel; `data` is Base64 on the bridge. */
|
|
58
|
+
readonly MESSAGE: "peers:message";
|
|
59
|
+
/** A channel ended: closed, lost or timed out. */
|
|
60
|
+
readonly CHANNEL_CLOSED: "peers:channel-closed";
|
|
61
|
+
};
|
|
62
|
+
type PeersEvent = typeof PEERS_EVENTS[keyof typeof PEERS_EVENTS];
|
|
46
63
|
/**
|
|
47
64
|
* Events for external client communication (browser extensions, CLI tools, servers, etc.)
|
|
48
65
|
*/
|
|
@@ -412,6 +429,11 @@ interface ExtensionManifest {
|
|
|
412
429
|
target: string;
|
|
413
430
|
action?: "read";
|
|
414
431
|
}[];
|
|
432
|
+
/** Channels to frames of this extension in other vaults (`client.peers`): `{ target: "*", action?: "connect" }`. */
|
|
433
|
+
peers?: {
|
|
434
|
+
target: "*";
|
|
435
|
+
action?: "connect";
|
|
436
|
+
}[];
|
|
415
437
|
};
|
|
416
438
|
homepage?: string | null;
|
|
417
439
|
description?: string | null;
|
|
@@ -512,5 +534,5 @@ declare class HaexVaultSdkError extends Error {
|
|
|
512
534
|
};
|
|
513
535
|
}
|
|
514
536
|
|
|
515
|
-
export {
|
|
516
|
-
export type { ApplicationContext as A, ClaimRequirement as C, DatabaseQueryResult as D, ExtensionInfo as E, FileChangeEvent as F, HaexHubConfig as H, IdentityClaim as I, MailEvent as K, ManifestI18nEntry as L, Migration as M, ManifestTool as N, ManifestToolEffect as O, PermissionResponse as P, ModelJobEvent as Q, RequestOptions as R, SearchResult as S, NotificationEvent as U,
|
|
537
|
+
export { HostErrorCode as B, MAIL_EVENTS as G, MODEL_JOB_EVENTS as J, NOTIFICATION_EVENTS as T, PEERS_EVENTS as V, PermissionErrorCode as _, PermissionStatus as a0, SHELL_EVENTS as a1, TABLE_SEPARATOR as a6, getTableName as a7, isPermissionDeniedError as a8, isPermissionError as a9, isPermissionPromptError as aa, EXTERNAL_EVENTS as c, DEFAULT_TIMEOUT as j, ErrorCode as p, HAEXTENSION_EVENTS as v, HaexVaultSdkError as y };
|
|
538
|
+
export type { PermissionPromptError as $, ApplicationContext as A, ClaimRequirement as C, DatabaseQueryResult as D, ExtensionInfo as E, FileChangeEvent as F, HaexHubConfig as H, IdentityClaim as I, MailEvent as K, ManifestI18nEntry as L, Migration as M, ManifestTool as N, ManifestToolEffect as O, PermissionResponse as P, ModelJobEvent as Q, RequestOptions as R, SearchResult as S, NotificationEvent as U, WebRequestOptions as W, PeersEvent as X, PermissionDeniedError as Y, PermissionErrorBase as Z, ExtensionManifest as a, SearchQuery as a2, SearchRequestEvent as a3, ShellEvent as a4, SyncTablesUpdatedEvent as a5, HaexHubEvent as b, MigrationResult as d, WebResponse as e, EventCallback as f, DatabasePermissionRequest as g, SignedClaimPresentation as h, ContextChangedEvent as i, DatabaseColumnInfo as k, DatabaseExecuteParams as l, DatabasePermission as m, DatabaseQueryParams as n, DatabaseTableInfo as o, ExtensionRuntimeMode as q, ExternalEvent as r, FileChangePayload as s, FileChangeType as t, FilteredSyncTablesResult as u, HaexHubRequest as w, HaexHubResponse as x, HaextensionEvent as z };
|
|
@@ -43,6 +43,23 @@ declare const MODEL_JOB_EVENTS: {
|
|
|
43
43
|
readonly COMPLETED: "haextension:model-job:completed";
|
|
44
44
|
};
|
|
45
45
|
type ModelJobEvent = typeof MODEL_JOB_EVENTS[keyof typeof MODEL_JOB_EVENTS];
|
|
46
|
+
/**
|
|
47
|
+
* Events of peer channels (`client.peers`, holzi spec 057). The SDK's
|
|
48
|
+
* `peers.on` takes the names without the `peers:` prefix.
|
|
49
|
+
*/
|
|
50
|
+
declare const PEERS_EVENTS: {
|
|
51
|
+
/** The outcome of an invitation, once per invitation (inviting side). */
|
|
52
|
+
readonly INVITE_STATUS: "peers:invite-status";
|
|
53
|
+
/** A channel opened after the user accepted an invitation in holzi's prompt (invited side). */
|
|
54
|
+
readonly CHANNEL_OPENED: "peers:channel-opened";
|
|
55
|
+
/** A device joined one of this device's lobbies by code (host). */
|
|
56
|
+
readonly JOINED: "peers:joined";
|
|
57
|
+
/** A message on a channel; `data` is Base64 on the bridge. */
|
|
58
|
+
readonly MESSAGE: "peers:message";
|
|
59
|
+
/** A channel ended: closed, lost or timed out. */
|
|
60
|
+
readonly CHANNEL_CLOSED: "peers:channel-closed";
|
|
61
|
+
};
|
|
62
|
+
type PeersEvent = typeof PEERS_EVENTS[keyof typeof PEERS_EVENTS];
|
|
46
63
|
/**
|
|
47
64
|
* Events for external client communication (browser extensions, CLI tools, servers, etc.)
|
|
48
65
|
*/
|
|
@@ -412,6 +429,11 @@ interface ExtensionManifest {
|
|
|
412
429
|
target: string;
|
|
413
430
|
action?: "read";
|
|
414
431
|
}[];
|
|
432
|
+
/** Channels to frames of this extension in other vaults (`client.peers`): `{ target: "*", action?: "connect" }`. */
|
|
433
|
+
peers?: {
|
|
434
|
+
target: "*";
|
|
435
|
+
action?: "connect";
|
|
436
|
+
}[];
|
|
415
437
|
};
|
|
416
438
|
homepage?: string | null;
|
|
417
439
|
description?: string | null;
|
|
@@ -512,5 +534,5 @@ declare class HaexVaultSdkError extends Error {
|
|
|
512
534
|
};
|
|
513
535
|
}
|
|
514
536
|
|
|
515
|
-
export {
|
|
516
|
-
export type { ApplicationContext as A, ClaimRequirement as C, DatabaseQueryResult as D, ExtensionInfo as E, FileChangeEvent as F, HaexHubConfig as H, IdentityClaim as I, MailEvent as K, ManifestI18nEntry as L, Migration as M, ManifestTool as N, ManifestToolEffect as O, PermissionResponse as P, ModelJobEvent as Q, RequestOptions as R, SearchResult as S, NotificationEvent as U,
|
|
537
|
+
export { HostErrorCode as B, MAIL_EVENTS as G, MODEL_JOB_EVENTS as J, NOTIFICATION_EVENTS as T, PEERS_EVENTS as V, PermissionErrorCode as _, PermissionStatus as a0, SHELL_EVENTS as a1, TABLE_SEPARATOR as a6, getTableName as a7, isPermissionDeniedError as a8, isPermissionError as a9, isPermissionPromptError as aa, EXTERNAL_EVENTS as c, DEFAULT_TIMEOUT as j, ErrorCode as p, HAEXTENSION_EVENTS as v, HaexVaultSdkError as y };
|
|
538
|
+
export type { PermissionPromptError as $, ApplicationContext as A, ClaimRequirement as C, DatabaseQueryResult as D, ExtensionInfo as E, FileChangeEvent as F, HaexHubConfig as H, IdentityClaim as I, MailEvent as K, ManifestI18nEntry as L, Migration as M, ManifestTool as N, ManifestToolEffect as O, PermissionResponse as P, ModelJobEvent as Q, RequestOptions as R, SearchResult as S, NotificationEvent as U, WebRequestOptions as W, PeersEvent as X, PermissionDeniedError as Y, PermissionErrorBase as Z, ExtensionManifest as a, SearchQuery as a2, SearchRequestEvent as a3, ShellEvent as a4, SyncTablesUpdatedEvent as a5, HaexHubEvent as b, MigrationResult as d, WebResponse as e, EventCallback as f, DatabasePermissionRequest as g, SignedClaimPresentation as h, ContextChangedEvent as i, DatabaseColumnInfo as k, DatabaseExecuteParams as l, DatabasePermission as m, DatabaseQueryParams as n, DatabaseTableInfo as o, ExtensionRuntimeMode as q, ExternalEvent as r, FileChangePayload as s, FileChangeType as t, FilteredSyncTablesResult as u, HaexHubRequest as w, HaexHubResponse as x, HaextensionEvent as z };
|
package/dist/vue.d.mts
CHANGED
package/dist/vue.d.ts
CHANGED
package/dist/vue.js
CHANGED
|
@@ -459,6 +459,18 @@ var MODEL_JOB_EVENTS = {
|
|
|
459
459
|
/** A job of this frame ended: completed, failed or cancelled. */
|
|
460
460
|
COMPLETED: "haextension:model-job:completed"
|
|
461
461
|
};
|
|
462
|
+
var PEERS_EVENTS = {
|
|
463
|
+
/** The outcome of an invitation, once per invitation (inviting side). */
|
|
464
|
+
INVITE_STATUS: "peers:invite-status",
|
|
465
|
+
/** A channel opened after the user accepted an invitation in holzi's prompt (invited side). */
|
|
466
|
+
CHANNEL_OPENED: "peers:channel-opened",
|
|
467
|
+
/** A device joined one of this device's lobbies by code (host). */
|
|
468
|
+
JOINED: "peers:joined",
|
|
469
|
+
/** A message on a channel; `data` is Base64 on the bridge. */
|
|
470
|
+
MESSAGE: "peers:message",
|
|
471
|
+
/** A channel ended: closed, lost or timed out. */
|
|
472
|
+
CHANNEL_CLOSED: "peers:channel-closed"
|
|
473
|
+
};
|
|
462
474
|
var EXTERNAL_EVENTS = {
|
|
463
475
|
/** External request from authorized client */
|
|
464
476
|
REQUEST: "haextension:external:request",
|
|
@@ -793,7 +805,32 @@ var MODEL_COMMANDS = {
|
|
|
793
805
|
/** Starts a job; the result follows as an event */
|
|
794
806
|
start: "extension_model_job_start",
|
|
795
807
|
/** Cancels a running job of this frame */
|
|
796
|
-
cancel: "extension_model_job_cancel"
|
|
808
|
+
cancel: "extension_model_job_cancel",
|
|
809
|
+
/** Asks for a grant before the first job; nothing goes to a model */
|
|
810
|
+
requestAccess: "extension_model_access_request",
|
|
811
|
+
/** Opens the host's page of this extension's models */
|
|
812
|
+
openSettings: "extension_model_settings_open"
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
// src/commands/peers.ts
|
|
816
|
+
init_cjs_shims();
|
|
817
|
+
var PEER_COMMANDS = {
|
|
818
|
+
/** Invites a contact; the outcome follows as `peers:invite-status` */
|
|
819
|
+
invite: "extension_peers_invite",
|
|
820
|
+
/** Withdraws an open invitation on all devices of the contact */
|
|
821
|
+
inviteCancel: "extension_peers_invite_cancel",
|
|
822
|
+
/** Opens a lobby and returns its join code */
|
|
823
|
+
lobbyOpen: "extension_peers_lobby_open",
|
|
824
|
+
/** Closes a lobby; its code stops working, its channels stay open */
|
|
825
|
+
lobbyClose: "extension_peers_lobby_close",
|
|
826
|
+
/** Joins a lobby by its code; waits at most 15 s for the host */
|
|
827
|
+
join: "extension_peers_join",
|
|
828
|
+
/** Closes a channel of an own lobby and keeps the device out of that lobby */
|
|
829
|
+
remove: "extension_peers_remove",
|
|
830
|
+
/** Sends a fast or a reliable message over a channel */
|
|
831
|
+
send: "extension_peers_send",
|
|
832
|
+
/** Closes a channel on both sides */
|
|
833
|
+
close: "extension_peers_close"
|
|
797
834
|
};
|
|
798
835
|
|
|
799
836
|
// src/commands/mail.ts
|
|
@@ -2019,6 +2056,24 @@ var ModelsAPI = class {
|
|
|
2019
2056
|
);
|
|
2020
2057
|
return answer.models;
|
|
2021
2058
|
}
|
|
2059
|
+
/**
|
|
2060
|
+
* Asks for a grant before the first job (holzi spec 055 US9) and resolves with the allowed
|
|
2061
|
+
* models that fit `needs`. Without one, the host asks the user as it would for a job, and the
|
|
2062
|
+
* SDK waits for the answer. Rejects with `no_capable_model` (8001) when no model of the host
|
|
2063
|
+
* fits and with a denial (1002) when the user refused. Nothing is sent to a model, and consent
|
|
2064
|
+
* for a destination outside this device is asked with the first job that sends data.
|
|
2065
|
+
*/
|
|
2066
|
+
async requestAccessAsync(request) {
|
|
2067
|
+
const answer = await this.client.request(
|
|
2068
|
+
MODEL_COMMANDS.requestAccess,
|
|
2069
|
+
{ ...request }
|
|
2070
|
+
);
|
|
2071
|
+
return answer.models;
|
|
2072
|
+
}
|
|
2073
|
+
/** Opens the host's page of this extension's models, where the user chooses models and effort. */
|
|
2074
|
+
async openSettingsAsync() {
|
|
2075
|
+
await this.client.request(MODEL_COMMANDS.openSettings, {});
|
|
2076
|
+
}
|
|
2022
2077
|
/** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
|
|
2023
2078
|
async startAsync(job) {
|
|
2024
2079
|
const answer = await this.client.request(MODEL_COMMANDS.start, {
|
|
@@ -2091,6 +2146,158 @@ var ModelsAPI = class {
|
|
|
2091
2146
|
}
|
|
2092
2147
|
};
|
|
2093
2148
|
|
|
2149
|
+
// src/api/peers.ts
|
|
2150
|
+
init_cjs_shims();
|
|
2151
|
+
init_vaultKey();
|
|
2152
|
+
var PEER_ERROR_KINDS = {
|
|
2153
|
+
contact_unknown: "PEER_CONTACT_UNKNOWN",
|
|
2154
|
+
invite_not_open: "PEER_INVITE_UNKNOWN",
|
|
2155
|
+
channel_unknown: "PEER_CHANNEL_CLOSED",
|
|
2156
|
+
channel_closed: "PEER_CHANNEL_CLOSED",
|
|
2157
|
+
too_large: "PEER_PAYLOAD_TOO_LARGE",
|
|
2158
|
+
lobby_closed: "PEER_LOBBY_CLOSED",
|
|
2159
|
+
not_admitted: "PEER_NOT_ALLOWED",
|
|
2160
|
+
limit: "PEER_LIMIT",
|
|
2161
|
+
network_unavailable: "PEER_NETWORK_UNAVAILABLE",
|
|
2162
|
+
invalid_input: "PEER_INVALID_INPUT"
|
|
2163
|
+
};
|
|
2164
|
+
var PeerError = class extends Error {
|
|
2165
|
+
constructor(code, reason, message, details = {}, options) {
|
|
2166
|
+
super(message, options);
|
|
2167
|
+
this.code = code;
|
|
2168
|
+
this.reason = reason;
|
|
2169
|
+
this.details = details;
|
|
2170
|
+
this.name = "PeerError";
|
|
2171
|
+
this.kind = PEER_ERROR_KINDS[reason];
|
|
2172
|
+
if (typeof details.limit === "number") this.limit = details.limit;
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
function isPeerErrorReason(value) {
|
|
2176
|
+
return typeof value === "string" && Object.hasOwn(PEER_ERROR_KINDS, value);
|
|
2177
|
+
}
|
|
2178
|
+
function toPeerError(error) {
|
|
2179
|
+
if (typeof error !== "object" || error === null) return error;
|
|
2180
|
+
const { code, message, details } = error;
|
|
2181
|
+
if (typeof code !== "number" || typeof details !== "object" || details === null) return error;
|
|
2182
|
+
const reason = details.reason;
|
|
2183
|
+
if (!isPeerErrorReason(reason)) return error;
|
|
2184
|
+
return new PeerError(
|
|
2185
|
+
code,
|
|
2186
|
+
reason,
|
|
2187
|
+
typeof message === "string" ? message : reason,
|
|
2188
|
+
details,
|
|
2189
|
+
{ cause: error }
|
|
2190
|
+
);
|
|
2191
|
+
}
|
|
2192
|
+
var EVENT_NAMES = {
|
|
2193
|
+
"invite-status": PEERS_EVENTS.INVITE_STATUS,
|
|
2194
|
+
"channel-opened": PEERS_EVENTS.CHANNEL_OPENED,
|
|
2195
|
+
joined: PEERS_EVENTS.JOINED,
|
|
2196
|
+
message: PEERS_EVENTS.MESSAGE,
|
|
2197
|
+
"channel-closed": PEERS_EVENTS.CHANNEL_CLOSED
|
|
2198
|
+
};
|
|
2199
|
+
function decodeEvent(type, data) {
|
|
2200
|
+
if (typeof data !== "object" || data === null) return void 0;
|
|
2201
|
+
if (type !== "message") return data;
|
|
2202
|
+
const message = data;
|
|
2203
|
+
if (typeof message.channelId !== "string" || typeof message.data !== "string") return void 0;
|
|
2204
|
+
let decoded;
|
|
2205
|
+
try {
|
|
2206
|
+
decoded = base64ToArrayBuffer(message.data);
|
|
2207
|
+
} catch {
|
|
2208
|
+
return void 0;
|
|
2209
|
+
}
|
|
2210
|
+
if (arrayBufferToBase64(decoded) !== message.data) return void 0;
|
|
2211
|
+
return {
|
|
2212
|
+
channelId: message.channelId,
|
|
2213
|
+
data: decoded,
|
|
2214
|
+
reliable: message.reliable === true
|
|
2215
|
+
};
|
|
2216
|
+
}
|
|
2217
|
+
var PeersAPI = class {
|
|
2218
|
+
constructor(client) {
|
|
2219
|
+
this.client = client;
|
|
2220
|
+
/** Largest fast message (`reliable: false`) in bytes. */
|
|
2221
|
+
this.MAX_FAST_BYTES = 1024;
|
|
2222
|
+
/** Largest reliable message in bytes. */
|
|
2223
|
+
this.MAX_RELIABLE_BYTES = 65536;
|
|
2224
|
+
/** Largest `payload` of an invitation or a join, as JSON, in bytes. */
|
|
2225
|
+
this.MAX_PAYLOAD_BYTES = 4096;
|
|
2226
|
+
}
|
|
2227
|
+
async call(method, params) {
|
|
2228
|
+
try {
|
|
2229
|
+
return await this.client.request(method, params);
|
|
2230
|
+
} catch (error) {
|
|
2231
|
+
throw toPeerError(error);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
/** Invites a contact; the outcome follows as `invite-status` with this `inviteId`. */
|
|
2235
|
+
async inviteAsync(contactId, payload) {
|
|
2236
|
+
const answer = await this.call(PEER_COMMANDS.invite, { contactId, payload });
|
|
2237
|
+
return { inviteId: answer.inviteId };
|
|
2238
|
+
}
|
|
2239
|
+
/** Withdraws an open invitation on all devices of the contact; no `invite-status` follows. */
|
|
2240
|
+
async cancelInviteAsync(inviteId) {
|
|
2241
|
+
await this.call(PEER_COMMANDS.inviteCancel, { inviteId });
|
|
2242
|
+
}
|
|
2243
|
+
/**
|
|
2244
|
+
* Opens a lobby; `lobbyId` is 1–64 characters of `[A-Za-z0-9._-]`. The join code is opaque:
|
|
2245
|
+
* hand it on as it is.
|
|
2246
|
+
*/
|
|
2247
|
+
async openLobbyAsync(lobbyId, visibility) {
|
|
2248
|
+
const answer = await this.call(PEER_COMMANDS.lobbyOpen, { lobbyId, visibility });
|
|
2249
|
+
return { joinCode: answer.joinCode };
|
|
2250
|
+
}
|
|
2251
|
+
/** Closes a lobby: its code stops working, its channels stay open. An unknown lobby is fine. */
|
|
2252
|
+
async closeLobbyAsync(lobbyId) {
|
|
2253
|
+
await this.call(PEER_COMMANDS.lobbyClose, { lobbyId });
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2256
|
+
* Joins a lobby by its code with a self-chosen `displayName` (1–64 characters). The host
|
|
2257
|
+
* answers within 15 s; a lobby that cannot be joined for any reason rejects as `lobby_closed`.
|
|
2258
|
+
*/
|
|
2259
|
+
async joinAsync(joinCode, displayName, payload) {
|
|
2260
|
+
const answer = await this.call(PEER_COMMANDS.join, {
|
|
2261
|
+
joinCode,
|
|
2262
|
+
displayName,
|
|
2263
|
+
payload
|
|
2264
|
+
});
|
|
2265
|
+
return { channelId: answer.channelId, lobbyId: answer.lobbyId };
|
|
2266
|
+
}
|
|
2267
|
+
/** Closes a channel of an own lobby and keeps that device (and vault) out of the lobby. */
|
|
2268
|
+
async removeAsync(channelId) {
|
|
2269
|
+
await this.call(PEER_COMMANDS.remove, { channelId });
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* Sends bytes over a channel: fast (default, at most {@link MAX_FAST_BYTES}, may be lost) or
|
|
2273
|
+
* `reliable` (at most {@link MAX_RELIABLE_BYTES}, in order; 16 may wait per channel).
|
|
2274
|
+
*/
|
|
2275
|
+
async sendAsync(channelId, data, options = {}) {
|
|
2276
|
+
await this.call(PEER_COMMANDS.send, {
|
|
2277
|
+
channelId,
|
|
2278
|
+
data: { $bytes: arrayBufferToBase64(data) },
|
|
2279
|
+
reliable: options.reliable ?? false
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
/** Closes a channel; both sides get `channel-closed` with `reason: "closed"`. */
|
|
2283
|
+
async closeAsync(channelId) {
|
|
2284
|
+
await this.call(PEER_COMMANDS.close, { channelId });
|
|
2285
|
+
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Listens for one of the peers events (`invite-status`, `channel-opened`, `joined`, `message`,
|
|
2288
|
+
* `channel-closed`); `message.data` arrives as bytes. Returns an unsubscribe function.
|
|
2289
|
+
*/
|
|
2290
|
+
on(type, handler) {
|
|
2291
|
+
const name = EVENT_NAMES[type];
|
|
2292
|
+
const wrapped = (event) => {
|
|
2293
|
+
const decoded = decodeEvent(type, event.data);
|
|
2294
|
+
if (decoded) handler(decoded);
|
|
2295
|
+
};
|
|
2296
|
+
this.client.on(name, wrapped);
|
|
2297
|
+
return () => this.client.off(name, wrapped);
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
|
|
2094
2301
|
// src/api/mail.ts
|
|
2095
2302
|
init_cjs_shims();
|
|
2096
2303
|
var MailAPI = class {
|
|
@@ -3208,6 +3415,7 @@ var HaexVaultSdk = class {
|
|
|
3208
3415
|
this.passwords = new PasswordsAPI(this);
|
|
3209
3416
|
this.contacts = new ContactsAPI(this);
|
|
3210
3417
|
this.models = new ModelsAPI(this);
|
|
3418
|
+
this.peers = new PeersAPI(this);
|
|
3211
3419
|
this.mail = new MailAPI(this);
|
|
3212
3420
|
this.notifications = new NotificationsAPI(this);
|
|
3213
3421
|
this.tab = new TabAPI(this);
|