@decentnetwork/beagle 0.1.32 → 0.1.33

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.
@@ -1,4 +1,4 @@
1
- window.__DK_UI_VERSION="0.1.31";
1
+ window.__DK_UI_VERSION="0.1.32";
2
2
  const ICON_PATHS = {
3
3
  // ---- tab bar (the four must feel like one set) ----
4
4
  users: '<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
@@ -3858,10 +3858,44 @@ function useCallController(selfId, onCallLog) {
3858
3858
  React.useEffect(() => {
3859
3859
  activeRef.current = active;
3860
3860
  }, [active]);
3861
+ const claimTabId = React.useRef(Math.random().toString(36).slice(2));
3862
+ const claimBus = React.useRef(null);
3863
+ React.useEffect(() => {
3864
+ let ch = null;
3865
+ try {
3866
+ ch = new BroadcastChannel("dk-call-claim");
3867
+ } catch (e) {
3868
+ return void 0;
3869
+ }
3870
+ claimBus.current = ch;
3871
+ ch.onmessage = (ev) => {
3872
+ const m = ev.data || {};
3873
+ if (!m || m.tabId === claimTabId.current || m.type !== "claimed")
3874
+ return;
3875
+ const inc = incomingRef.current;
3876
+ if (inc && (inc.callId === m.callId || inc.peerId === m.peerId))
3877
+ setIncoming(null);
3878
+ };
3879
+ return () => {
3880
+ try {
3881
+ ch.close();
3882
+ } catch (e) {
3883
+ }
3884
+ claimBus.current = null;
3885
+ };
3886
+ }, []);
3887
+ const broadcastClaim = React.useCallback((inc, action) => {
3888
+ try {
3889
+ if (claimBus.current)
3890
+ claimBus.current.postMessage({ type: "claimed", tabId: claimTabId.current, callId: inc.callId, peerId: inc.peerId, action });
3891
+ } catch (e) {
3892
+ }
3893
+ }, []);
3861
3894
  const accept = React.useCallback(() => {
3862
3895
  const pending = incomingRef.current;
3863
3896
  if (!pending)
3864
3897
  return;
3898
+ broadcastClaim(pending, "accepted");
3865
3899
  setIncoming(null);
3866
3900
  setActive({ callId: pending.callId, peerId: pending.peerId, video: pending.video, direction: "incoming", state: "connecting" });
3867
3901
  waitEngine().then((eng) => {
@@ -3873,10 +3907,12 @@ function useCallController(selfId, onCallLog) {
3873
3907
  const reject = React.useCallback(() => {
3874
3908
  const eng = engineRef.current;
3875
3909
  const inc = incomingRef.current;
3910
+ if (inc)
3911
+ broadcastClaim(inc, "rejected");
3876
3912
  if (eng && inc)
3877
3913
  eng.reject(inc.callId);
3878
3914
  setIncoming(null);
3879
- }, []);
3915
+ }, [broadcastClaim]);
3880
3916
  const hangup = React.useCallback(() => {
3881
3917
  const eng = engineRef.current;
3882
3918
  const a = activeRef.current;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/beagle",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "Beagle — P2P chat, file transfer and calls for regular users, on the Decent Network. No admin privilege required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",