@arbidocs/react 0.5.177 → 0.5.178

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.
@@ -0,0 +1,78 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useRoomContext } from "@livekit/components-react";
3
+ import { ConnectionState, RoomEvent } from "livekit-client";
4
+ import { CALL_MEDIA_PROTOCOL, decryptCallMedia } from "@arbidocs/client";
5
+ import { CallMediaPlayer, checkedCallMedia } from "./call-media-player.js";
6
+ function useCallMedia(enabled, key) {
7
+ const room = useRoomContext();
8
+ const [players, setPlayers] = useState(/* @__PURE__ */ new Map());
9
+ useEffect(() => {
10
+ if (!enabled || !key || typeof AudioContext === "undefined") return;
11
+ const context = new AudioContext();
12
+ const live = /* @__PURE__ */ new Map();
13
+ const chains = /* @__PURE__ */ new Map();
14
+ let disposed = false;
15
+ const advertise = () => {
16
+ if (!disposed && context.state === "running" && room.state === ConnectionState.Connected) {
17
+ void room.localParticipant.setAttributes({ "arbi.call_media": CALL_MEDIA_PROTOCOL }).catch(() => void 0);
18
+ }
19
+ };
20
+ const changed = () => {
21
+ if (!disposed) setPlayers(new Map(live));
22
+ };
23
+ const received = (bytes, from, _kind, topic) => {
24
+ if (topic !== CALL_MEDIA_PROTOCOL || !from || from.attributes["arbi.call_assistant"] !== "true")
25
+ return;
26
+ const identity = from.identity;
27
+ const chain = chains.get(identity) ?? Promise.resolve();
28
+ chains.set(
29
+ identity,
30
+ chain.then(async () => {
31
+ if (disposed) return;
32
+ const message = checkedCallMedia(await decryptCallMedia(bytes, key), identity);
33
+ let player = live.get(identity);
34
+ if (!player) {
35
+ player = new CallMediaPlayer(context, changed);
36
+ live.set(identity, player);
37
+ }
38
+ if (context.state !== "running") await context.resume();
39
+ if (context.state !== "running") throw new Error("Call audio is unavailable");
40
+ player.push(message);
41
+ }).catch(() => {
42
+ live.get(identity)?.reset(true);
43
+ void room.localParticipant.setAttributes({ "arbi.call_media": "" }).catch(() => void 0);
44
+ })
45
+ );
46
+ };
47
+ const removed = (participant) => {
48
+ live.get(participant.identity)?.reset();
49
+ live.delete(participant.identity);
50
+ changed();
51
+ };
52
+ room.on(RoomEvent.DataReceived, received);
53
+ room.on(RoomEvent.ParticipantDisconnected, removed);
54
+ room.on(RoomEvent.Connected, advertise);
55
+ room.on(RoomEvent.Reconnected, advertise);
56
+ void context.resume().then(() => {
57
+ advertise();
58
+ }).catch(() => void 0);
59
+ return () => {
60
+ disposed = true;
61
+ room.off(RoomEvent.DataReceived, received);
62
+ room.off(RoomEvent.ParticipantDisconnected, removed);
63
+ room.off(RoomEvent.Connected, advertise);
64
+ room.off(RoomEvent.Reconnected, advertise);
65
+ if (room.state === ConnectionState.Connected) {
66
+ void room.localParticipant.setAttributes({ "arbi.call_media": "" }).catch(() => void 0);
67
+ }
68
+ for (const player of live.values()) player.reset();
69
+ void context.close();
70
+ setPlayers(/* @__PURE__ */ new Map());
71
+ };
72
+ }, [enabled, key, room]);
73
+ return players;
74
+ }
75
+ export {
76
+ useCallMedia
77
+ };
78
+ //# sourceMappingURL=useCallMedia.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/calls/livekit/useCallMedia.ts"],
4
+ "sourcesContent": ["/** Separately encrypted data-channel media, played on one audio/control clock. */\nimport { useEffect, useState } from 'react'\nimport { useRoomContext } from '@livekit/components-react'\nimport { ConnectionState, RoomEvent, type RemoteParticipant } from 'livekit-client'\nimport { CALL_MEDIA_PROTOCOL, decryptCallMedia } from '@arbidocs/client'\nimport { CallMediaPlayer, checkedCallMedia } from './call-media-player'\n\nexport function useCallMedia(enabled: boolean, key: Uint8Array | null) {\n const room = useRoomContext()\n const [players, setPlayers] = useState<ReadonlyMap<string, CallMediaPlayer>>(new Map())\n useEffect(() => {\n if (!enabled || !key || typeof AudioContext === 'undefined') return\n const context = new AudioContext()\n const live = new Map<string, CallMediaPlayer>()\n const chains = new Map<string, Promise<void>>()\n let disposed = false\n const advertise = () => {\n if (!disposed && context.state === 'running' && room.state === ConnectionState.Connected) {\n void room.localParticipant\n .setAttributes({ 'arbi.call_media': CALL_MEDIA_PROTOCOL })\n .catch(() => undefined)\n }\n }\n const changed = () => {\n if (!disposed) setPlayers(new Map(live))\n }\n const received = (\n bytes: Uint8Array,\n from?: RemoteParticipant,\n _kind?: unknown,\n topic?: string\n ) => {\n if (\n topic !== CALL_MEDIA_PROTOCOL ||\n !from ||\n from.attributes['arbi.call_assistant'] !== 'true'\n )\n return\n const identity = from.identity\n const chain = chains.get(identity) ?? Promise.resolve()\n chains.set(\n identity,\n chain\n .then(async () => {\n if (disposed) return\n const message = checkedCallMedia(await decryptCallMedia(bytes, key), identity)\n let player = live.get(identity)\n if (!player) {\n player = new CallMediaPlayer(context, changed)\n live.set(identity, player)\n }\n if (context.state !== 'running') await context.resume()\n if (context.state !== 'running') throw new Error('Call audio is unavailable')\n player.push(message)\n })\n .catch(() => {\n live.get(identity)?.reset(true)\n // A browser unable to play synchronized media keeps its ordinary LiveKit audio.\n void room.localParticipant\n .setAttributes({ 'arbi.call_media': '' })\n .catch(() => undefined)\n })\n )\n }\n const removed = (participant: RemoteParticipant) => {\n live.get(participant.identity)?.reset()\n live.delete(participant.identity)\n changed()\n }\n room.on(RoomEvent.DataReceived, received)\n room.on(RoomEvent.ParticipantDisconnected, removed)\n room.on(RoomEvent.Connected, advertise)\n room.on(RoomEvent.Reconnected, advertise)\n void context\n .resume()\n .then(() => {\n advertise()\n })\n .catch(() => undefined)\n return () => {\n disposed = true\n room.off(RoomEvent.DataReceived, received)\n room.off(RoomEvent.ParticipantDisconnected, removed)\n room.off(RoomEvent.Connected, advertise)\n room.off(RoomEvent.Reconnected, advertise)\n if (room.state === ConnectionState.Connected) {\n void room.localParticipant.setAttributes({ 'arbi.call_media': '' }).catch(() => undefined)\n }\n for (const player of live.values()) player.reset()\n void context.close()\n setPlayers(new Map())\n }\n }, [enabled, key, room])\n return players\n}\n"],
5
+ "mappings": "AACA,S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switchedOn = useFeature("calls");
2689
2689
  return serverEnabled && (switchedOn || !experimental);
2690
2690
  }
2691
+ function useCallAvatarsEnabled() {
2692
+ const explicitlyConfigured = !!chunk5QOZLKAY_cjs.useArbiHost().features?.callAvatars;
2693
+ const feature = useFeature("callAvatars");
2694
+ const config = useCallsConfig();
2695
+ const { data: settings } = useUserSettings();
2696
+ return explicitlyConfigured && feature && config?.avatar_available === true && settings?.developer === true;
2697
+ }
2691
2698
  function useCanHostCalls() {
2692
2699
  const callsEnabled = useCallsEnabled();
2693
2700
  const entitled = useIsEntitled("host_calls");
@@ -2894,6 +2901,7 @@ exports.upsertChat = upsertChat;
2894
2901
  exports.useAccountClient = useAccountClient;
2895
2902
  exports.useAvatarCrop = useAvatarCrop;
2896
2903
  exports.useCall = useCall;
2904
+ exports.useCallAvatarsEnabled = useCallAvatarsEnabled;
2897
2905
  exports.useCallInviteLinks = useCallInviteLinks;
2898
2906
  exports.useCallRecording = useCallRecording;
2899
2907
  exports.useCallRecordings = useCallRecordings;
@@ -2924,5 +2932,5 @@ exports.useUserSettings = useUserSettings;
2924
2932
  exports.wipeOfflineMail = wipeOfflineMail;
2925
2933
  exports.wrapTrackKey = wrapTrackKey;
2926
2934
  exports.writeSamples = writeSamples;
2927
- //# sourceMappingURL=chunk-C5O4BH7B.cjs.map
2928
- //# sourceMappingURL=chunk-C5O4BH7B.cjs.map
2935
+ //# sourceMappingURL=chunk-VCYRQZ3R.cjs.map
2936
+ //# sourceMappingURL=chunk-VCYRQZ3R.cjs.map