@kehto/services 0.12.0 → 0.12.3
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 +7 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -87,7 +87,9 @@ runtime.registerService(
|
|
|
87
87
|
services: () => [],
|
|
88
88
|
read: () => [87],
|
|
89
89
|
write: (_sessionId, _target, _data) => {},
|
|
90
|
-
subscribe: (
|
|
90
|
+
subscribe: (sessionId, target, ctx) => {
|
|
91
|
+
ctx.emit({ type: 'notification', sessionId, target, data: [87] });
|
|
92
|
+
},
|
|
91
93
|
unsubscribe: (_sessionId, _target) => {},
|
|
92
94
|
close: (_sessionId) => {},
|
|
93
95
|
}),
|
|
@@ -439,6 +441,9 @@ Each factory returns a `ServiceHandler` registrable via `runtime.registerService
|
|
|
439
441
|
### Media NAP
|
|
440
442
|
- `createMediaService` — owner-aware `media.session.create` / `update` / `destroy` / `media.state` / `media.capabilities` + `media.command` push envelopes (`media:control`). Napplet-owned sessions mirror to `navigator.mediaSession` by default; shell-owned creates are rejected until a host playback/fetch bridge is supplied. Implement the `HostMediaBridge` interface to swap in native backends. See [Media Service](#media-service) for the full contract.
|
|
441
443
|
|
|
444
|
+
### BLE NAP
|
|
445
|
+
- `createBleService` — `ble.open`, `ble.services`, `ble.read`, `ble.write`, `ble.subscribe`, `ble.unsubscribe`, `ble.close` + host-pushed `ble.event` envelopes. Hook contexts include `ctx.emit(event)`, so host Bluetooth notification listeners can forward `notification`, `state`, and `closed` events to the requesting napplet without replacing the reference handler.
|
|
446
|
+
|
|
442
447
|
### WebRTC NAP
|
|
443
448
|
- `createWebrtcService` — `webrtc.open`, `webrtc.send`, `webrtc.close` + host-pushed `webrtc.event` envelopes. The reference handler owns only the NAP request/result bookkeeping; host bridges own signaling, SDP, ICE, peer connection lifecycle, and policy.
|
|
444
449
|
|
|
@@ -449,7 +454,7 @@ Each factory returns a `ServiceHandler` registrable via `runtime.registerService
|
|
|
449
454
|
- `createAudioService` — `audio:*` inc-emit topic handler. Browser-agnostic registry of per-window audio sources; host wires `onChange` to update transport UI.
|
|
450
455
|
|
|
451
456
|
### Types
|
|
452
|
-
`AudioSource`, `AudioServiceOptions`, `Notification`, `NotificationServiceOptions`, `IdentityServiceOptions`, `RelayPoolServiceOptions`, `CacheServiceOptions`, `CoordinatedRelayOptions`, `KeysServiceOptions`, `MediaServiceOptions`, `NotifyServiceOptions`, `ThemeServiceOptions`, `ThemeService`, `WebrtcServiceOptions`, `WebrtcServiceContext`.
|
|
457
|
+
`AudioSource`, `AudioServiceOptions`, `Notification`, `NotificationServiceOptions`, `IdentityServiceOptions`, `RelayPoolServiceOptions`, `CacheServiceOptions`, `CoordinatedRelayOptions`, `KeysServiceOptions`, `MediaServiceOptions`, `NotifyServiceOptions`, `ThemeServiceOptions`, `ThemeService`, `BleServiceOptions`, `BleServiceContext`, `WebrtcServiceOptions`, `WebrtcServiceContext`.
|
|
453
458
|
|
|
454
459
|
## API Reference
|
|
455
460
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ServiceHandler, Signer } from '@kehto/runtime';
|
|
2
2
|
import { IdentityGetProfileMessage, IdentityGetProfileResultMessage, IdentityGetFollowsMessage, IdentityGetFollowsResultMessage, IdentityGetListMessage, IdentityGetListResultMessage, IdentityGetZapsMessage, IdentityGetZapsResultMessage, IdentityGetMutesMessage, IdentityGetMutesResultMessage, IdentityGetBlockedMessage, IdentityGetBlockedResultMessage, IdentityGetBadgesMessage, IdentityGetBadgesResultMessage } from '@napplet/nap/identity/types';
|
|
3
|
-
import { NostrFilter, NostrEvent, EventTemplate, LinkOpenOptions, LinkOpenResult, ListSupport, ListRef, ListItem, ListOptions, ListMutationResult, SerialOpenRequest, SerialOpenResult, BleOpenRequest, BleOpenResult, BleService, BleAttribute, BleWriteOptions, WebrtcEvent, WebrtcOpenRequest, WebrtcOpenResult, CommonProfileTarget, CommonProfileResult, CommonFollowsResult, CommonActionResult, CommonReaction, CommonReportTarget, CommonReportReason } from '@napplet/core';
|
|
3
|
+
import { NostrFilter, NostrEvent, EventTemplate, LinkOpenOptions, LinkOpenResult, ListSupport, ListRef, ListItem, ListOptions, ListMutationResult, SerialOpenRequest, SerialOpenResult, BleEvent, BleOpenRequest, BleOpenResult, BleService, BleAttribute, BleWriteOptions, WebrtcEvent, WebrtcOpenRequest, WebrtcOpenResult, CommonProfileTarget, CommonProfileResult, CommonFollowsResult, CommonActionResult, CommonReaction, CommonReportTarget, CommonReportReason } from '@napplet/core';
|
|
4
4
|
import { MediaMetadata, MediaAction } from '@napplet/nap/media/types';
|
|
5
5
|
export { MediaAction } from '@napplet/nap/media/types';
|
|
6
6
|
import { NotifySendMessage } from '@napplet/nap/notify/types';
|
|
@@ -2521,6 +2521,8 @@ declare function createSerialService(options?: SerialServiceOptions): ServiceHan
|
|
|
2521
2521
|
interface BleServiceContext {
|
|
2522
2522
|
/** Window id of the requesting napplet. */
|
|
2523
2523
|
windowId: string;
|
|
2524
|
+
/** Emit a runtime-owned BLE event back to the requesting napplet. */
|
|
2525
|
+
emit(event: BleEvent): void;
|
|
2524
2526
|
}
|
|
2525
2527
|
/** Options for {@link createBleService}. */
|
|
2526
2528
|
interface BleServiceOptions {
|
package/dist/index.js
CHANGED
|
@@ -3199,12 +3199,20 @@ function unsupported2(resultType, id) {
|
|
|
3199
3199
|
error: `${resultType.replace(".result", "")} unavailable`
|
|
3200
3200
|
};
|
|
3201
3201
|
}
|
|
3202
|
+
function createContext(windowId, send) {
|
|
3203
|
+
return {
|
|
3204
|
+
windowId,
|
|
3205
|
+
emit(event) {
|
|
3206
|
+
send({ type: "ble.event", event });
|
|
3207
|
+
}
|
|
3208
|
+
};
|
|
3209
|
+
}
|
|
3202
3210
|
function createBleService(options = {}) {
|
|
3203
3211
|
return {
|
|
3204
3212
|
descriptor: BLE_DESCRIPTOR,
|
|
3205
3213
|
handleMessage(windowId, message, send) {
|
|
3206
3214
|
const id = message.id ?? "";
|
|
3207
|
-
const context =
|
|
3215
|
+
const context = createContext(windowId, send);
|
|
3208
3216
|
if (message.type === "ble.open") {
|
|
3209
3217
|
if (!options.open) {
|
|
3210
3218
|
send(unsupported2("ble.open.result", id));
|
|
@@ -3344,7 +3352,7 @@ function unsupported3(resultType, id) {
|
|
|
3344
3352
|
error: `${resultType.replace(".result", "")} unavailable`
|
|
3345
3353
|
};
|
|
3346
3354
|
}
|
|
3347
|
-
function
|
|
3355
|
+
function createContext2(windowId, send) {
|
|
3348
3356
|
return {
|
|
3349
3357
|
windowId,
|
|
3350
3358
|
emit(event) {
|
|
@@ -3357,7 +3365,7 @@ function createWebrtcService(options = {}) {
|
|
|
3357
3365
|
descriptor: WEBRTC_DESCRIPTOR,
|
|
3358
3366
|
handleMessage(windowId, message, send) {
|
|
3359
3367
|
const id = message.id ?? "";
|
|
3360
|
-
const context =
|
|
3368
|
+
const context = createContext2(windowId, send);
|
|
3361
3369
|
if (message.type === "webrtc.open") {
|
|
3362
3370
|
if (!options.open) {
|
|
3363
3371
|
send(unsupported3("webrtc.open.result", id));
|