Compare commits

...

358 Commits

Author SHA1 Message Date
Sravan 1ece8e1061 System bars: lock in Option 1 (brand-blue bars) on iOS + Android
User picked the brand-blue look for both platforms. Apply .sysbar-blue on any
native platform; set white icons via the safe-area plugin on Android and via
@capacitor/status-bar on iOS. capacitor.config statusBarStyle/navigationBarStyle
-> DARK (light icons) so native builds match before JS runs. iOS is live, so this
web change reaches it immediately — verify on an iPhone.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-19 18:13:55 +05:30
Sravan 03de639e1a Android system bars — Option 2 preview: white bars + brand separator line
Swap the class to sysbar-sep (thin 1.5px brand line under the status bar + above
the nav bar, bars stay white) and icons back to dark. Second of the two looks for
the user to compare; pick one after this.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-19 18:09:39 +05:30
Sravan 133208ae3f Android system bars — Option 1 preview: brand-blue bars + white icons
Fill the status/nav inset regions with brand blue (#1F3B73) via html.sysbar-blue
pseudo-elements and switch the bar icons to light so they read on blue. This is
one of two looks for the user to compare on-device; Option 2 (white + separator)
is already in the CSS and swaps in by changing the class + icon style.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-19 18:07:31 +05:30
Sravan 703cf1fcf0 TEMP: keyboard diagnostics for the Android repeat-open gap
Behavior-neutral console logging on keyboard show/hide (kb height, innerHeight,
clientHeight, visualViewport height, --kb) to determine whether the Android
WebView resizes (interactive-widget) or relies on the manual --kb lift, and to
spot any residual between the first and second open. Remove once fixed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-19 18:00:47 +05:30
Sravan 9d5af66a0e Android: dark system-bar icons (visible on the white app)
Under Android edge-to-edge the status/nav bar icons default to light (white) and
vanished on the white app (clock/battery/nav invisible). Set SafeArea
statusBarStyle/navigationBarStyle to LIGHT (= dark content on a light background)
in capacitor.config.json, and add a runtime SafeArea.setSystemBarsStyle call in
home.html so already-installed APKs get dark icons on relaunch (no rebuild). iOS
unaffected (its status bar already shows dark content on white).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-18 00:24:39 +05:30
Sravan ab6d8161ee push: accept FCM_SERVICE_ACCOUNT_B64 (base64 service-account key)
Base64 is a single env-safe token, so the FCM service-account key can live in
.env without the quoting/interpolation hazards of inline JSON. Falls back to the
existing FCM_SERVICE_ACCOUNT (inline JSON or file path). No behavior change when
neither is set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-18 00:04:31 +05:30
Sravan c013536e2b Android: wire Firebase google-services.json into the build (client half)
Commit the client Firebase config (bizgaze-connect, package com.bizgaze.connect)
and have the Codemagic Android step copy it into android/app/ so the google-services
Gradle plugin applies and FirebaseApp initializes — fixing the root cause of the
"Default FirebaseApp is not initialized" crash. google-services.json is client-side
(ships in the APK), safe for this private repo. The service-account key stays OUT of
git (.gitignore: *firebase-adminsdk*.json / *service-account*.json) — it goes on the
server as FCM_SERVICE_ACCOUNT separately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-17 19:22:22 +05:30
Sravan ba75dc8daa Android: fix black gap above keyboard (SafeArea/SystemBars config)
The safe-area plugin logged: set SystemBars.insetsHandling to "disable". Under
Android edge-to-edge (targetSdk 36) this + offsetForKeyboardInsetBug were causing
a black strip between the input and the soft keyboard on the login view. Set
SystemBars.insetsHandling="disable" and SafeArea.offsetForKeyboardInsetBug=true.
Native config — takes effect on the next Android build; verify on device.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-15 21:57:35 +05:30
Sravan a4726dd10c Fix Android crash: don't register push without Firebase
On Android, PushNotifications.register() calls FirebaseMessaging.getInstance(),
which throws "Default FirebaseApp is not initialized" when the build has no
google-services.json. Capacitor runs the plugin method on its own thread, so the
exception is an UNCAUGHT NATIVE crash a JS try/catch can't stop — the app died
right after sign-in and on every relaunch.

Gate Android push registration on a new server flag: /api/meetings/config now
returns fcm (push.fcmReady() = FCM_SERVICE_ACCOUNT present). setupNativePush skips
register() on Android unless fcm is true. Web-side fix — deploys without a rebuild;
push auto-enables once Firebase (client google-services.json + server FCM) is set up.
iOS/APNs unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-15 21:55:09 +05:30
Sravan b03a32b10d Android CI: use JDK 21 (Capacitor 8 Android requires it)
@capacitor/android is ^8; Capacitor 8's Android toolchain (AGP 8.7 / Gradle 8.11)
requires JDK 21. The workflow used java: 17, which fails the Gradle build before an
APK is produced. Bump to java: 21.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-08 16:36:47 +05:30
Sravan e39828ed56 Android CI: fail the build on a Gradle error + surface the real cause
The build step ended with `find … *.apk`, which exits 0 even when Gradle failed
and no APK exists — so Codemagic marked a failed Gradle run as a green build with
no artifact. Now: capture gradle output, use PIPESTATUS to detect failure, print
the "What went wrong" / FAILURE block, exit non-zero, and assert an APK exists.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-08 16:35:39 +05:30
Sravan 35ce641046 Android CI: run on mac_mini_m2 (linux_x2 not on the billing plan)
The android-apk workflow requested linux_x2, which Codemagic rejected with
"selected instance type is not available with the current billing plan". Switch
to mac_mini_m2 — the same instance the iOS workflow already uses on this account;
Codemagic's macOS images include the Android SDK + JDK. Also make the SDK path
(ANDROID_SDK_ROOT -> ANDROID_HOME fallback) and the google-services base64 decode
(GNU --decode / BSD -D) portable to the macOS image.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-08 16:08:52 +05:30
Sravan 1efb2e4314 Fix: message text not selectable on desktop
#msgs .bubble had a blanket user-select:none (added to suppress iOS's long-press
magnifier), which also blocked mouse text-selection on desktop. Scope the
none to touch devices only (@media (hover:none)); keep it in multi-select mode.
Desktop can now highlight/copy message text. Verified: desktop=auto,
touch=none, sel-mode=none.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 19:23:21 +05:30
Sravan 677d418ed0 Fix: dragging multiple files into a chat only sent the first
The conversation drop handler read dataTransfer.files[0] (a single file), so a
multi-file drag-and-drop uploaded just one. Iterate every dropped file, matching
the file-picker path. Verified in-browser: dropping 3 files queues + sends all 3.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 18:22:57 +05:30
Sravan 07c728bf6a Android CI build + delete-chat (self-only) + SFU copy refresh
- codemagic.yaml: add an Android workflow that builds an installable debug
  APK (Linux instance, no signing needed to test) — the Android equivalent of
  the iOS TestFlight loop. mobile/scripts/android-patch.js injects the
  camera/mic/notification permissions into the CI-generated manifest (android/
  is gitignored, same as ios/).
- Delete chat (self-only): new POST /api/messages/clear bulk-hides a whole DM
  (or group) for the requester via the existing per-user message_hidden
  mechanism — the other party keeps their copy entirely. "Delete chat" button
  added to the DM contact-info panel; chat-cleared synced to my other devices.
  Verified end-to-end on Postgres (A clears -> empty for A, B untouched).
- Meetings copy: SFU is live, so drop the "coming soon" / "small group (mesh)"
  wording on the welcome card and the Meetings header.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 17:12:42 +05:30
Sravan 948eae249f App Store: add 13-inch iPad screenshots (universal build requires them)
The Capacitor build is universal (iPhone + iPad), so App Store Connect requires
iPad screenshots. Added three 2064x2752 (13" iPad) shots rendered on the app's
two-pane iPad layout (chat sidebar + open conversation, meetings, schedule),
anonymized. No rebuild needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 16:13:55 +05:30
Sravan 88a6b6a21e App Store: add screen-sharing screenshot (6 total)
06-screenshare.png — a meeting with a shared screen (a slide + chart on the
stage, "Sharing" badge, participant tiles, controls), rendered on the real call
UI at 1320x2868 and anonymized. Updated the submission pack's screenshot order to
include it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 14:51:15 +05:30
Sravan 620039a2ff iOS remote support: Share Screen -> Connect Screen over LiveKit (core)
Rebuild the iOS remote-support screen share the RIGHT way: keep the exact
Share/Connect UX + session (consent + symmetric session-ended), swap only the
media to LiveKit since WKWebView can't getDisplayMedia. (Replaces the earlier
"route to a meeting" detour, which was reverted.)

Flow: customer taps Share Screen -> gets a 6-digit code (unchanged UI) -> helper
enters it in Connect Screen -> on the customer's "Allow", the app publishes the
screen natively (ReplayKit -> LiveKit) into a per-session room and tells the
agent it's a LiveKit session -> connect.html joins that room and shows the screen
in its existing viewer (recording/controls intact). Chat runs over the session
socket (no P2P data channel in this mode). Either side ending fires the existing
session-ended -> both tear down (symmetric disconnect).

- signaling.js: relay 'rs-livekit' + 'rs-chat' between the two ends.
- home.html: parent bridge so the /share iframe can drive startMeetingScreenShare/
  stop on the native plugin (+ a capability handshake).
- share.html (iOS): publish via native LiveKit instead of getDisplayMedia; chat
  over WS; hide mic (voice = next iteration) + remote-control (impossible on iOS).
- connect.html: LiveKit viewer for iOS-shared sessions, reusing the P2P viewer.

Web-only, no new build (reuses the shipped startMeetingScreenShare). Desktop
Share/Connect P2P unchanged. Two-way voice is the planned follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 13:16:06 +05:30
Sravan 224a2800c5 Revert "iOS "Share Screen": route to a screen-share meeting (remote-support on iPhone)"
This reverts commit eb685b42ca.
2026-08-22 12:21:36 +05:30
Sravan ba51a3c5d7 Revert "iOS Share Screen: show the code and wait; start sharing when the helper joins"
This reverts commit 1a089c0349.
2026-08-22 12:21:36 +05:30
Sravan 1a089c0349 iOS Share Screen: show the code and wait; start sharing when the helper joins
Fix the confusing flow: tapping Share Screen dumped the user straight into a
meeting and auto-shared, with the join code hard to find. Now it shows a clear
full-screen "Share your screen" step with the big 6-digit code + Copy + a
"Waiting for them to join…" spinner (and Cancel). The native screen broadcast
starts only when the helper actually joins with that code (meeting-peer-joined) —
matching the remote-support mental model.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 12:00:14 +05:30
Sravan eb685b42ca iOS "Share Screen": route to a screen-share meeting (remote-support on iPhone)
The remote-support Share/Connect tabs use P2P WebRTC (screen + voice + chat) that
WKWebView can't capture, so "Share Screen" never worked on iPhone. Rather than
rebuild the whole P2P session on LiveKit, route iOS "Share Screen" to a
screen-share MEETING (chosen with the user): tapping Share Screen on iOS starts
an instant meeting, auto-starts the native ReplayKit screen share (the path just
verified on device), and toasts the join code. A helper joins by code (Meeting)
to watch — and gets voice + chat for free. Viewing already works in the webview,
so only the SHARE side is rerouted; desktop keeps the full P2P remote-support
flow, and iOS Safari (no app) is unchanged.

Web-only, no new build (reuses the shipped startMeetingScreenShare native method).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 11:36:48 +05:30
Sravan 467a8b9c6e iOS meeting screen share: publish ReplayKit broadcast into the SFU room
Gap: on iOS, screen share only worked in native CallKit calls. In a scheduled /
code-joined SFU meeting the webview called setScreenShareEnabled() ->
getDisplayMedia(), which WKWebView does not implement, so it failed silently.
Production meetings are real LiveKit rooms, so we can publish natively instead.

Fix (native ReplayKit -> same LiveKit room as a dedicated screen participant):
- server: /api/meetings/token accepts screen:true -> mints a distinct
  <peerId>-screen identity (LiveKit allows one connection per identity), so the
  native publisher doesn't collide with the webview's own connection.
- native plugin: startMeetingScreenShare/stopMeetingScreenShare + connectScreenRoom
  (a screen-only LiveKit connection: mic off, no camera, no callConnected) that
  reuses the existing broadcast-extension publishing path.
- webview: toggleScreen routes to the native method on iOS SFU meetings; the
  screenShareState listener now drives the SFU case too (and tears the screen
  connection down on the system "Stop Broadcast"); sfuAttach/sfuDetach map the
  '<peerId>-screen' participant's screen track onto the sharer's tile and suppress
  the phantom person tile + the sharer's own self-view.

Web/server deploy now; the native method needs the next Codemagic build to test
on device. Verified: db-smoke 22/22; Swift braces balanced.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 01:01:42 +05:30
Sravan 14eb99edaf App Store: add group-chat + schedule-meeting screenshots (5 total)
Two more anonymized 1320x2868 shots of features that work on iOS: a group
conversation (sender chips, read receipts) and the Schedule-a-call flow
(participant names anonymized). Deliberately did NOT screenshot Share/Connect:
webview screen capture (getDisplayMedia) is unavailable in WKWebView, so the
remote-support screen-share tab doesn't function on iOS — advertising it would
be inaccurate metadata. (Screen share works in native calls via ReplayKit and
fully on desktop.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 00:37:03 +05:30
Sravan 2948e0cfcc App Store assets: 6.9" screenshots + wired privacy/support URLs into submission pack
- mobile/appstore-screenshots/: 3 anonymized 1320x2868 screenshots generated from
  the live app (Chats, a Conversation, Meetings). Real names/faces replaced with
  demo identities, notification banner dismissed, internal roadmap copy removed.
- APPSTORE_SUBMISSION.md: pre-submission checklist now all green; Privacy Policy
  and Support URLs filled with the live /privacy and /support pages; demo login
  and export-compliance noted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 12:46:12 +05:30
Sravan a9d95ed8c6 Add public /privacy and /support pages (App Store required URLs)
App Store submission needs a public Privacy Policy URL and Support URL, reachable
without login. Added branded, self-contained pages served at /privacy and
/support (static.js path mappings, like /home). The privacy policy accurately
describes Biz Connect: BizGaze-account login, messages/media stored on our
servers, call media via LiveKit (only recorded on explicit user action),
on-device transcription (audio never leaves the device), push via APNs/FCM, no
sale of data / no ads, retention, security, and user/GDPR rights. Contact:
support@bizgaze.com (confirm/replace if different).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 12:35:06 +05:30
Sravan 18edc5dbfb Moderation UX: Block on DM contact info + visible report-resolved notice
Tester feedback:
1. "Block contact not on the contact info." The earlier Block button was only on
   the group-sender mini-profile, which a 1:1 chat never opens. A DM's info panel
   is openSharedItems('dm',…) (tap the conversation header). Added a full-width
   "Block contact / Unblock contact" button there.
2. "Reporter gets no notification on resolution." Delivery was actually working
   (verified: the reporter receives the 'report-resolved' event over the chat WS),
   but the client only added a silent bell entry — easy to miss — and a self-
   resolve (same admin reported + resolved) is intentionally skipped. Made it a
   visible toast + ping for an online reporter (report-new likewise toasts admins).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-20 22:39:13 +05:30
Sravan 928119725e Moderation follow-ups: block on contact profile, z-index, account suspend, reporter notify
Addresses tester feedback on the Report/Block feature:

1. Block/Unblock is now on the CONTACT's profile card (openMiniProfile), not only
   in a message's ⋮/long-press menu — you can block someone straight from their
   info popup.
2. Admin Delete/confirm popups were appearing BEHIND the Reports window. The
   moderation modals used z-index 100000 (above bzConfirm's .modal-ov at 9800);
   lowered them to 9750 so the confirm dialog sits on top.
3. Clarified admin action. "Block" is a PERSONAL mute (per guideline 1.2) and does
   not touch login. The report view now offers a real account action instead:
   "Suspend account" (deactivate -> signed out + cannot log in) with a confirm,
   toggling to "Reactivate account" — both reversible in-place, driven by a new
   reportedActive flag on /api/reports. (Uses the existing /api/users/manage
   deactivate/activate.)
4. Resolving a report now notifies the reporter (live 'report-resolved' event +
   background push), and admins get a 'report-new' activity entry.

repos: reports.byId. Verified: moderation suite 18/18 (adds reportedActive +
suspend->login-blocked->reactivate->login-restored).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-20 11:50:55 +05:30
Sravan 10b2251efe Scheduled meetings: deliver a background push (fixes no iOS notification)
Root cause: the scheduled-meeting INVITE (routes.js) and the ~10-min REMINDER
(reminders.js) both notified only via CHAT.pushToUser — the WebSocket channel,
which only reaches an OPEN tab with a live socket. Neither called
PUSH.sendToUser, the path that produces a background APNs/FCM/web-push alert.
On iOS the webview is suspended in the background, so the WS event was simply
missed and no notification appeared. (Chat messages already call PUSH.sendToUser,
which is why chat notices arrive on iOS but meeting ones didn't.)

Fix:
- schedule invite: also PUSH.sendToUser to every invited participant + group
  members (kind:'meeting', id:roomCode) so a closed app is notified.
- reminders.js: also PUSH.sendToUser to all reminder recipients.
- client: a kind:'meeting' notification tap now opens the Meeting tab + its list
  (both the live-tab open-chat handler and the cold-boot openKind path), instead
  of calling selectChat with an unsupported kind.

Also: APPSTORE_SUBMISSION.md §8 updated — the UGC Report/Block gate (guideline
1.2) is now implemented, with a suggested reviewer note.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-19 19:51:25 +05:30
Sravan e4d361f298 Chat moderation: Report message + Block user (App Store guideline 1.2)
Apple requires user-generated-content apps to offer a way to report
objectionable content and block abusive users. The chat had neither, which is
the #1 rejection cause for messaging apps. Added both, server-enforced.

Server:
- schema: message_reports + user_blocks tables.
- repos: reports {add,listForTeam,setStatus}, blocks {add,remove,has,listFor},
  users.adminsOf(); thread + threadByConversation now exclude blocked senders in
  SQL (like message_hidden) so the LIMIT counts only visible rows (no pagination
  stall).
- routes: POST /api/messages/report, /api/users/block|unblock, GET
  /api/users/blocked, GET /api/reports + POST /api/reports/resolve (admin only).
- enforcement: a blocked sender's DM/group messages are persisted but not
  delivered (no live push, no background notification) to anyone who blocked
  them; blocked users can't ring you (/api/calls/dm/start + /api/calls/invite);
  admins can delete reported content (delete route now allows role=admin).

Client (home.html, all platforms via the web UI — no rebuild):
- message menu gains Report (canned-reason picker) + Block/Unblock.
- profile menu: "Blocked users" manager (list + unblock) for everyone;
  "Reported messages" review (delete / block / resolve) for admins.
- blocked DMs hidden from the sidebar; block list loaded on boot.
- reports route to the workspace's OWN admins (org-internal moderation).

Verified: db-smoke 22/22 + a new moderation suite 12/12 (report+admin-list,
non-admin 403, block hides post-block history but sender still sees sent,
blocked call 403, unblock restores history + calling). New flag/ban icons added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-19 19:46:22 +05:30
Sravan 7e3a94b04c iOS splash: quality-branded, crop-safe navy launch screen
The iOS splash read as unbranded for two concrete reasons:
1. The light-mode master (resources/splash.png) was on a WHITE background
   while the SplashScreen plugin paints #16294F navy -> a white->navy->app
   flash on light-mode devices.
2. The logo + "Biz Connect" wordmark spanned ~82% of the 2732 square, but the
   launch storyboard scales it scaleAspectFill; on tall iPhones ~27% of each
   side is cropped, clipping the wordmark edges.

New splash (both light + dark masters, identical navy so there is no flash):
brand navy gradient (#20396f -> #16294f) matching the plugin background, the
C-mark as hero, and the wordmark typeset in Corbel (closest installed match to
the brand geometric wordmark) sized to 1041px -> inside the ~1260px aspectFill
safe zone, so nothing clips on any device.

Also hardened codemagic.yaml: the asset step used `|| echo skipped`, which
silently shipped Capacitor's blank default splash if generation failed. Now it
hard-verifies the generated iOS Splash.imageset exists and fails the build
otherwise. Rides the next Codemagic build (native asset; no server redeploy).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-18 21:06:50 +05:30
Sravan 343724df0f group chat: profile photos missing on a cached re-open (only initials showed)
The instant-paint work renders a group thread from cache BEFORE /api/groups/members
(convoMembers) loads, so senderAvatar had no avatar and drew initials only; the later
network render diffs/skips the unchanged messages, so the photos never came back until
a full reload. Platform-agnostic (desktop + iOS), group-only — matching the report.
Fix: senderAvatar now falls back to the global CONTACTS avatar so the cache paint is
already correct, and openConvo repaints the sender avatars (refreshSenderAvatars) once
convoMembers loads. Web-only; live on next app launch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 14:22:00 +05:30
Sravan 3f41ca857a chat list: clear the stale "message deleted" label when a newer message arrives
The sidebar shows "This message was deleted" whenever a row's last_deleted flag is
set, but the new-message handlers (incoming, my-sent, edit) updated the preview text
and never cleared last_deleted. So once a conversation's last message had been deleted
(server-computed last_deleted=true at load), a NEWER message left the flag stale and
the list kept showing "deleted"/"you deleted this" even though the actual last message
was a normal one. Remote deletes already self-corrected via onChatDeleted->loadSidebar;
this was the in-session new-message path. Now last_deleted is cleared wherever a fresh
non-deleted message becomes the row's last message. Web-only; live on next app launch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 14:08:31 +05:30
Sravan 87a76c09f3 transcript: fix duplicate copy on multi-device + iOS download hijacking the app
- Duplicate ("Transcript shows two times"): finalizeTranscript had a race — for the
  SAME user on two devices (#12 multi-device), both devices leaving at once each
  passed the subscriber membership check across an await before either removed the
  sub, so both wrote a private transcript. Now the subscriber is CLAIMED
  SYNCHRONOUSLY (subs.delete filter) before any await, so only the first writer wins.
  Verified with a concurrency simulation (2 concurrent leaves -> 1 write).
- iOS download: the /mrec transcript link had no `download` attribute, so WKWebView
  NAVIGATED to the file and loaded it inline with no way back (had to force-quit the
  app). Added download + data-mime so browsers download it and the existing native
  click-interceptor catches it: it now saves to the Files folder and opens in native
  Quick Look (view + its own share/save — into Files or Word) instead of hijacking
  the WebView. recDTO now exposes the recording mime.

Web/server only — no native build needed; live on next app launch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 19:47:23 +05:30
Sravan e46ac1e7cc #5 transcript: cover scheduled/web meetings on iOS too (not just native calls)
In a scheduled meeting the WebView owns the mic (the plugin has no LiveKit room), so
the native-call AudioRenderer tap didn't apply. Now the WebView reads its OWN local
mic PCM via Web Audio (the same non-intrusive tap the app already uses for
active-speaker metering — NOT a 2nd getUserMedia, which would fight the call's mic on
iOS and yield silence), downsamples to 16 kHz mono Int16, and forwards it to the
plugin's SFSpeechRecognizer via feedAudio(). Native calls keep the LiveKit tap.
Muted -> the local track carries silence -> nothing transcribed; the feed re-inits
when the mic goes live on unmute.

- Plugin: startTranscription({external:true}) runs the recognizer without a track;
  feedAudio({pcm,rate}) decodes base64 LE Int16 -> Float32 buffer -> recognizer.
- Web: startSR now uses the native recognizer for ALL iOS meetings (native call =
  LiveKit tap, scheduled = PCM feed); desktop/browser unchanged (Web Speech API).

Web deploys now; the plugin's feedAudio/startExternal ride the next Codemagic build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 17:05:56 +05:30
Sravan 68ff3a878b #12 multi-device tiles + #5 native iOS transcript
#12 — same user on two devices now shows as two independent tiles (was: LiveKit
kicked the older connection, "audio jumps to whichever joined last"):
- LiveKit identity is now the per-connection mesh peerId, not the user id.
  /api/meetings/token + guest-token mint identity=peerId when the client supplies
  it (anti-hijack: never mint another live user's peerId). Web maps SFU tracks by
  identity==peerId, keeping peerIdForUid as a fallback for the transition/native.
- Mesh dedup (dropDupPeers) now keys on a stable per-device clientId (persisted,
  sent on meeting-join, echoed by the server) instead of user id — so two real
  devices keep separate tiles while a same-device reconnect ghost still collapses.
  Verified in a real browser: 2 devices -> 2 tiles; same-device reconnect -> 1.
- Native: plugin gains reconnectRoom(); after the native WebView joins the mesh it
  re-homes the LiveKit media onto its peerId identity. syncVideoTiles keys by peerId.
  Token-identity + anti-hijack + clientId echo verified by a server test.

#5 — iOS live transcript (WKWebView has no Web Speech API, so an iOS participant
was never transcribed; desktop already works):
- native-call plugin transcribes the local mic with SFSpeechRecognizer, fed by a
  LiveKit AudioRenderer on the local mic track (reuses the call's open mic — no 2nd
  AVAudioEngine). Finalized segments -> 'transcript' event -> web sends
  meeting-transcript (same server assembly as desktop). startSR/stopSR use the
  native recognizer on native calls; Web Speech API path unchanged elsewhere.
- NSSpeechRecognitionUsageDescription added to the iOS Info.plist.

Native pieces (#12 reconnect, #5 transcript) need a Codemagic build; the web+server
half is verified and deploys now (already fixes the reported laptop+phone case).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 16:36:18 +05:30
Sravan c322448774 #14 edit: PARK the edit on leave and RESUME it on return (Send updates the original)
Previous follow-up kept the in-progress edit text only as a plain draft, so sending
it after returning posted a NEW message instead of updating the original. Now leaving
a chat mid-edit parks {msgId, text, pre-edit draft} in _pendingEdits; reopening the
chat resumes edit MODE (editTarget + "Editing message" bar + the in-progress text)
once the thread is loaded (cache render, then network render as fallback). So Send
runs saveEdit → UPDATES the original message. If the message can't be found in the
loaded page (or was deleted) it falls back to a plain draft so the text isn't lost.

Verified with puppeteer against the live app:
 - edit "hi bob" -> switch to Cara -> back -> edit mode resumes (composer "hi bob
   EDITED", bar showing) -> Send -> thread count stays 1, message.edited_at set:
   PASS (updated original, no new message).
 - plain draft (no edit) switch-and-return still restores: PASS (no regression).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 12:52:38 +05:30
Sravan 354e65acdf #14 follow-up: keep in-progress edit text as a draft when leaving a chat mid-edit
persistCurrentDraft() no longer skips while editing — leaving a chat mid-edit
abandons the edit (openConvo clears editTarget) but now keeps whatever's in the
composer as that chat's draft, so your typing isn't lost. It returns as a normal
draft (sending posts a new message, not an edit). The edit-cancel (X) path still
restores the pre-edit draft, unchanged. Verified with puppeteer: edit "hi bob" ->
"hi bob EDITED" -> switch chats -> back -> composer holds "hi bob EDITED" (PASS).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 12:38:05 +05:30
Sravan 785eeb7fbc #14 draft ROOT CAUSE: openConvo's cancelEdit() wiped the just-opened chat's draft
Reproduced with a real headless browser driving the live app: typing saved the draft
and it survived switching chats, but RETURNING to the chat deleted it. Stack trace
pinned it exactly:
  setDraft(REMOVE) <- _restoreDraftAfterEdit <- cancelEdit <- openConvo:3484 <- selectChat

openConvo ran `clearReply(); cancelEdit(); hideAttach();` on every open. cancelEdit ->
_restoreDraftAfterEdit -> setDraft(selected,'') — and since `selected` is already the
chat being opened, it wiped THAT chat's draft (and blanked the composer) BEFORE the
draft-restore a few lines later could read it. So the draft never survived reopening —
this predated the recent rounds; my _restoreDraftAfterEdit change just made the wipe
explicit. Fix: drop cancelEdit() from openConvo (edit state is already reset at the top
via editTarget=null/_editSavedDraft='', and the shell was just rebuilt fresh). The
edit-cancel button + saveEdit still call cancelEdit normally.

Verified with puppeteer: type in chat A -> open B -> back to A -> "hello draft" restored
(PASS), no setDraft REMOVE on return.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 11:50:20 +05:30
Sravan 25b0b39c49 #14 draft: guarantee the save at leave-time (fixes switch-chats-and-return loss)
Per-keystroke 'input' saves can be missed on mobile (predictive text or a fast
tap-away fires no final input event), which lost the whole draft when you switched
chats and came back. Added persistCurrentDraft() — snapshots the composer value
into the current chat's draft key the instant you leave it (selectChat before the
swap, and showWelcome/back). Restore on open was already correct. Skipped while
editing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 22:39:16 +05:30
Sravan 6ee424db16 Round 4: hidden-msg pagination, iOS audio unlock, iOS long-press callout, draft hardening, pinned-by
Older-messages pagination (couple of chats wouldn't scroll back): the thread query
    returned the latest 40 rows and JS filtered out hidden (delete-for-me) messages
    AFTER the LIMIT, so a chat with a hidden recent message returned <40 → the client
    read that as "no older history." Now excluded in SQL (repos.thread /
    threadByConversation take the viewer id), so a page is always 40 VISIBLE rows.
    Verified locally: hide 3 recent → page still returns 40 (older ones fill in).
#2  iOS in-chat tone was silent: WebAudio context is created suspended and only
    resumes inside a user gesture. Added unlockAudio() on first tap/click (resume +
    0-gain blip), re-armed each gesture so a background→foreground re-suspend recovers.
#9  Long-press "works once then stops" on images was iOS's native touch-callout
    (Save Image / selection magnifier) hijacking the gesture. Disabled
    -webkit-touch-callout/user-select on #msgs bubbles; added a Save action to the
    sheet so image-saving isn't lost.
#13 Pin/unpin WAS being audited (verified: message.pin in /api/audit) — there's just
    no in-app viewer. Surfaced "Pinned by X" in the pinned bar for immediate context.
#14 Hardened draft save: it now runs BEFORE maybeAutocorrect/autoGrow (wrapped) in the
    input handler, so a throw there can't skip persisting the draft.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 22:29:34 +05:30
Sravan c3c4178227 #8 root cause: listByTenant omitted last_seen/status → contacts/conversations sent lastSeen:null
repos.listByTenant selected id,email,name,role,active,avatar_url,created_at but NOT
last_seen or status. So /api/messages/contacts and /api/messages/conversations
always sent lastSeen:null (and status:'active'). Last-seen only ever appeared via
LIVE presence events (broadcastPresence reads the full row) — which is why it
"worked on desktop" (caught live), not on a fresh iOS load, and why round-2's
loadSidebar-on-focus then clobbered the live value → "Offline for all". Verified
locally: contacts now returns the real lastSeen timestamp; db-smoke 22/22.

Also lightened refreshPresenceOnResume: reconnect the socket if it's dead (its
onopen already resyncs the sidebar) but no longer force an unconditional
loadSidebar on every focus — that churn caused the #8 regression and could
momentarily reset an unread badge (#3). Session sliding (touchSession) stays.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 17:28:39 +05:30
Sravan a677675b8f Round 3: session longevity, in-chat tone, pin audit, older-msg loader, long-press sheet, draft fix
Session (New): stop the ~24h auto-logout. SESSION_TTL 24h -> 90d, and /api/me now
    SLIDES the session forward + re-stamps the cookie on every app load / focus /
    6h heartbeat — so an actively-used session never lapses; you only log out by
    choosing to. Login no longer depends on "remember me".
#2  A new message in the chat you're actively viewing now plays a soft, distinct
    in-chat tone (playMsgTone) — no popup — instead of being silent. A different
    chat / a backgrounded chat still gets the alert ping + notification.
#13 Pin/unpin is now written to the audit log (actor + which message, and whose pin
    was removed on an unpin) — the accountability gap when anyone can unpin.
Pagination: a floating "Loading earlier messages…" pill now shows while older
    history is being fetched (loadOlder had no visible indicator).
#9  Mobile long-press now opens a dimmed + blurred bottom ACTION SHEET (quick
    reactions + reply/edit/forward/copy/pin/delete) instead of the flaky hover-style
    reveal that hid behind images and broke after the lightbox opened.
#14 editTarget is cleared on conversation switch — starting an edit then switching
    chats used to leave editTarget set, which silently stopped ALL draft saving.
    Also added Edit to the shared action list so mobile long-press can edit too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 16:38:58 +05:30
Sravan eaea1ccc3f test: wait for the server to LISTEN instead of a fixed 300ms
Cold Postgres boot (connect + apply the full schema) takes a few seconds — the
fixed 300ms that was fine for SQLite's instant in-memory init raced the server
bind and the first fetch hit ECONNREFUSED. Poll BASE/ until it responds (≤30s).

Validated on local PostgreSQL 16: db-smoke 22/22 pass; e2e passes all DB-backed
checks (auth, messages, polls, groups, calls+invite, meetings) then stops at the
known pre-existing WS meeting-joined flake (unrelated to the DB).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 00:29:55 +05:30
Sravan 971a6fdf22 Round 2 fixes from on-device testing (#2,#3,#6,#8,#9,#13,#14,#18 + call re-ring)
#2  Don't ping/notify when you're ACTIVELY viewing a chat (app visible + chat
    open). Alert only when a different chat, OR the open chat while the app is
    minimised (the backgrounded case that used to stay silent).
#3  A reaction to my message now raises an unread badge on that conversation
    (like a new message), not just a notification.
#6  Image lightbox pulls EVERY image in the conversation via /api/messages/media
    (older images aren't in the DOM yet) — nav arrows reach them all. Nav buttons
    always in the DOM; syncArrows shows/hides at the ends and for a single image.
#8  On app resume (visibilitychange / native appStateChange), reconnect the chat
    socket if it isn't OPEN and re-pull the sidebar so online/last-seen refresh —
    iOS freezes the WebView so the socket can be dead while its onclose lags,
    leaving contacts stuck on a stale "Offline".
#9  Real cause was iOS "sticky :hover": a single tap latched :hover and popped the
    action bar. Gate the hover-reveal behind @media (hover:hover) so touch reveals
    actions ONLY via long-press; a plain tap performs the primary action.
#13 Pinned bar gains a "‹ 1 of n ›" pager to walk through multiple pinned messages
    (shown only when more than one is pinned).
#14 Editing a message no longer eats a half-written draft — the real draft is set
    aside on edit start and restored on save/cancel. edited_at is now in the message
    DTO so the "edited" tag survives a reload.
#18 One "Delete" entry opens a branded dialog with "Delete for me" / "Delete for
    everyone" (icons + descriptions) and a ✕/backdrop cancel, replacing the two
    separate menu items.
New: a participant who LEAVES a still-running call is no longer auto-rung back in
    on every socket reconnect. Track who left per call; replayActiveCalls sends
    them noRing state (refreshes the Join affordance without ringing). An explicit
    re-invite clears that and rings again.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 00:22:50 +05:30
Sravan ad48829337 Retire the SQLite backend — Postgres is the only engine
The dual backend (SQLite via db.js + Postgres via schema.pg.sql) was a
maintenance foot-gun: a schema change could land on the SQLite path only and
silently 500 every read on prod (it just did, with #18/#13). Production has run
on Postgres for weeks, so SQLite is retired: ONE schema source of truth
(db/schema.pg.sql), no drift possible.

- dbx.js: default DB_BACKEND=pg; an unknown backend now fails loudly at require
  time instead of silently selecting a stale engine.
- Deleted server/db.js, server/db/sqlite.js, server/db/migrate-sqlite-to-pg.js,
  server/scripts/migrate-bizgaze-only.js (all SQLite-only, none in the runtime
  path — the running server loads db/pg.js).
- Tests (e2e, db-smoke) target Postgres now and fail-fast (skip) unless
  DATABASE_URL points at a disposable test DB — never SQLite, never prod.
- Removed the dead DB_PATH env + fixed misleading SQLite comments in the
  Dockerfile / docker-compose (kept the /data volume: it holds
  uploads/recordings/transcripts/downloads, not just the old data.db).
- CLAUDE.md: stack + repo-layout + run-locally updated for Postgres-only.

Runtime is unaffected (prod already sets DB_BACKEND=pg and pg is a prod dep);
this only removes the unused SQLite path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 08:20:26 +05:30
Sravan f3b6e67c19 HOTFIX: add #18/#13 schema to Postgres (chat history returned empty)
Production runs DB_BACKEND=pg, but the message_hidden table (#18) and
pinned_at/pinned_by columns (#13) were only added to the SQLite migrations in
db.js — never to schema.pg.sql. So thread/conversations/pinned queries hit a
missing relation/column and 500'd, which surfaced as "chat history removed"
(no data was ever deleted — the reads just errored).

pg.js init() runs schema.pg.sql on every boot. Added the message_hidden table
and, because CREATE TABLE IF NOT EXISTS can't add columns to the existing
messages table, idempotent ALTER TABLE ... ADD COLUMN IF NOT EXISTS for
pinned_at/pinned_by. Restores all chat history and re-enables pin + delete-for-me.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 07:53:13 +05:30
Sravan d0863351d2 #13: pin a message
Any participant can pin/unpin a message from its ⋮ menu. Adds pinned_at/pinned_by
columns, /api/messages/pin (toggle, broadcasts chat-pinned) and
/api/messages/pinned (list, newest first, excludes deleted + delete-for-me).
The conversation shows a pinned strip under the header (latest pin + count);
tap it to jump to the message, × to unpin. Live-updates across participants and
devices. Added pin/pinOff Lucide icons.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 23:00:06 +05:30
Sravan 9017d2ff25 #9: mobile — single tap acts, long-press reveals message actions
On touch, tapping a message used to reveal the reply/react/more bar (so the
action needed a second tap). Now a single tap performs the primary action
(open image/file, jump to a reply), and the action bar is revealed by a
~420ms long-press (with a small haptic); movement or an early release cancels,
and a fired long-press suppresses the trailing tap. A tap elsewhere dismisses
the revealed bar. Desktop hover behaviour is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 22:51:35 +05:30
Sravan c1b67d38d3 #16: trim the schedule form when scheduling from a group
A group's members are automatically the meeting's participants, so the
Invite-participants, Invite-by-email and "Guests must be admitted by host"
sections are noise there. openScheduleModal now omits them when a group id is
present (inviteBlock is empty), and the email/participant/lobby handlers are
null-guarded so the save path still works without those fields.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 22:47:15 +05:30
Sravan 276c5e0929 Fix #1 (input-focus zoom), #6 (last-image arrow), #7 (join sound)
#1: focusing a text box zoomed + stretched the whole page on iOS. Several
inputs were < 16px and the existing 16px rule lived in a width-based mobile
@media that misses iPad/landscape (and maximum-scale is unreliable on iOS).
Added a @media (pointer: coarse) rule forcing 16px on every focusable field
for ALL touch devices; desktop is untouched.

#6: the image lightbox used visibility:hidden for the end arrows (invisible but
still occupying space / reading as a ghost button). Switched to display toggling
so there's truly no right arrow at the last image (and no left at the first).

#7: play a soft two-note chime + a brief "<name> joined the call" toast when a
new participant joins the meeting.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 22:44:00 +05:30
Sravan ecc8be3dba Fix #14 (edit leaves a draft) and #8 (last-seen flapping)
#14: after editing a message the edited text reappeared in the composer as a
draft and re-sent as a new message. The input listener saved a draft while
editing, but saveEdit/cancelEdit cleared only the input value, not the stored
draft — so openConvo restored it. Now editing never writes a draft, and
save/cancel clear it.

#8: a contact's subtitle flapped between "last seen …" and "Offline". A
loadSidebar rebuild replaced the row with the server's lastSeen, which is
sometimes null (the disconnect touchSeen is fire-and-forget and can lag the
presence broadcast). Now the client keeps last-seen sticky (never overwrites a
known value with null) and the server never broadcasts a null last-seen for an
offline user.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 22:37:06 +05:30
Sravan e359271157 #10 deleted-last-message preview + #18 delete for me / for everyone
#10: deleting the last message showed "No messages yet" in the chat list.
The sidebar sent an empty last_body for a deleted (content-cleared) row; now
it sends a last_deleted flag and the row renders "This message was deleted"
(or "You deleted this message"), matching the in-thread placeholder.

#18: added "Delete for me" alongside "Delete for everyone". A new message_hidden
table records a per-user hide; the thread + sidebar (last message, unread) filter
out the requesting user's hidden messages, and the hide is echoed to their other
devices (chat-hidden). "Delete for me" is offered on any message; "Delete for
everyone" stays sender-only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 22:31:17 +05:30
Sravan 9e80aee1c6 Fix notification bugs #2 (open+backgrounded chat) and #3 (reactions)
#2: a message arriving in the currently-OPEN chat produced no notification
when the app was minimized. onChatMessage marked the open chat read even
while document.hidden, which fired a notif-clear that closed the very
notification the service worker had just shown. Now the open chat is only
marked read while visible; markOpenChatRead() catches up on focus/visibility
return, and a message received while hidden stays unread with its alert intact.

#3: reacting to a message fired no notification. The react route only pushed
over the live socket (nothing for a closed app) and the client added a silent
bell entry. Now the server sends a native/web push to the message owner, and
onChatReaction pings + shows an OS/in-page popup (unless you're viewing that chat).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 22:23:16 +05:30
Sravan a0f9ab10f2 #15: adding a 3rd person to a 1:1 call promotes it to a persistent group call
When someone is added to a 1:1 (DM) call, promoteDmToGroup() now creates a
real group conversation (named after the participants) and migrates the live
call from dmCalls -> groupCalls, keeping the same room/uuid/history so media
and the transcript continue uninterrupted. Two wins:
 - the call survives anyone leaving (group calls only end when the room empties)
 - an added person who drops can rejoin from the group's active-call banner
   (they're now a member, so replayActiveCalls / group-call resurface it)

/api/calls/invite promotes on a DM call and lets the group-call broadcast ring
the invitees in; it only sends the plain call-invite when NOT promoted. Guarded
so inviting an existing pair-member (memberIds < 3) stays a 1:1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 22:13:41 +05:30
Sravan 100a092ff9 Fix call-cluster bugs #11, #4a, #4b
#11: adding a 3rd person to a 1:1 call then having one participant close
the app disconnected the call for everyone. leaveMeeting() ended a DM room
for ALL peers on any leave; now it only tears down when <2 people remain,
otherwise it falls through to the normal peer-left path (call continues).

#4b: after someone left a call they never reappeared under "Add people".
meeting-peer-left cleaned meetPeers/tiles but not meetPeerUids/meetNames,
so the departed uid stayed in hereUids and was filtered out. Now deleted.

#4a: a guest who enabled mic/cam on the pre-join screen had to re-tap after
being admitted — the choices were applied on a blind 900ms timer that fired
while still in the lobby. Now applied in the meeting-joined handler, after
admission + media connect.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 21:51:49 +05:30
Sravan 0cee72e73c Add a clear "Stop sharing" banner while sharing your screen
The only way to stop a screen share was toggling the share button again —
buried in the ⋮ More menu on mobile. Now a floating "You're sharing your
screen · Stop" banner appears at the top whenever you're sharing (driven by
meetScreen via updateScreenBtn), with a red Stop button that calls
toggleScreen. Works on iOS/desktop/web. Web-only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 16:56:00 +05:30
Sravan c24d5d828a Hole-punch attempt 3: set WebView transparent at startup + scrollView.isOpaque
Previous hole-punch builds showed no video because WKWebView can IGNORE
isOpaque=false when it's set AFTER the page has already rendered (during the
call). Now:
- makeWebViewTransparent() runs once at plugin load (startup): isOpaque=false,
  backgroundColor=.clear, and crucially scrollView.isOpaque=false +
  scrollView.backgroundColor=.clear (an opaque scrollView occludes content
  behind the WebView).
- setHolePunch now just toggles a BLACK backing on the WebView's parent during
  the call (transparency is already applied); restored after.
- Tile frames use host.convert(rect, to: superview) instead of a manual origin
  offset — robust to any WebView inset.

Plugin-only — needs a Codemagic build. If this still shows no video, WKWebView
hole-punch is a dead end here and we revert to native-video-on-top.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 14:13:22 +05:30
Sravan d9ea104b73 Fix hole-punch: put native video BEHIND the WebView, not under its scrollView
Diagnosis: no native video rendered at all (bg went black, but camera AND
screen tiles were empty). WKWebView does NOT composite native subviews placed
under its scrollView through transparent web content — only the webView's own
layer background shows through. So the video was effectively invisible.

Fix (the standard hole-punch): insert the video tiles into the WebView's
SUPERVIEW, BEHIND the (fully transparent) WebView, so the web content paints
on top and the video shows through. Changes:
- makeTileView / syncVideoTiles: insert belowSubview: host (the WebView) in
  host.superview, and offset frames by the WebView's origin (getBoundingClientRect
  is viewport-relative).
- webView.backgroundColor = .clear (was .black — a black webView bg would have
  occluded the video behind it); the VC view's black background is the backing.

Plugin-only change — needs a Codemagic build. Web (transparent chain, zoom,
bz-hasvid) already correct.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 12:29:01 +05:30
Sravan c79d78485b Fix hole-punch regressions: transparency chain, black backing, keyboard
Three fixes for the hole-punch build:
1. White background + shared screen not showing: body and .content both use
   var(--bg) (a light colour) and were still opaque, occluding the native
   video behind the WebView. Make the WHOLE meeting chain transparent under
   .bz-hp (body + .content, on top of .meet-grid/tiles).
2. Backing: also set the view controller's view background to black (saved/
   restored) so any transparent gap reads black, not white — belt-and-braces
   with webView.backgroundColor.
3. Keyboard covering the in-call chat: keyboard resize is "none", so the
   absolutely-positioned meet panels don't move for the keyboard. Lift
   .meet-panel by the reported keyboard height (body.kb-open → bottom:
   calc(var(--kb)+12px)); --kb/kb-open are already set globally by the
   Keyboard listener.

Plugin change (VC background) needs a build; the CSS is web-deployed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 12:13:09 +05:30
Sravan bdd0058c5c Hole-punch: render native video BEHIND a transparent WebView
Permanent fix for the z-order whack-a-mole (controls/menus/panels hiding
behind the native video). Instead of drawing native video ON TOP of the
WebView, draw it BEHIND a transparent WebView so ALL web UI floats on top
naturally — no suppressing, no clamping, no docked-only bar.

Plugin:
- setHolePunch(on): webView.isOpaque=false + black layer bg + clear scroll
  bg (restored on off / call end). Tiles inserted belowSubview:scrollView.
- Dropped native name/mute overlays (the web tile's own .nm/.meet-mute/avatar
  render on top now) and the PaddingLabel.
- Zoom re-plumbed: touches hit the WebView, so native gesture zoom can't work;
  new setTileZoom({uid,scale,tx,ty}) applies a web-forwarded transform to the
  tile's inner video. TileVideoView simplified to a container + applyZoom.

Web:
- bzNativeStartTiles/StopTiles toggle NC.setHolePunch + a body.bz-hp class
  (only when the plugin supports it — old builds keep the suppress fallback).
- Tiles with live native video get .bz-hasvid → CSS makes them transparent +
  hides the web avatar so the video shows through; name/mute/border stay.
- New web-forwarded pinch/pan/double-tap on the shared screen → setTileZoom.
- Suppress-on-overlay + the height clamp now only apply when NOT hole-punched.

Needs a Codemagic build (plugin). Web deployed; no-ops to the prior behavior
on builds without setHolePunch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 11:34:09 +05:30
Sravan f971908d80 Fix: hide native video while a meeting menu/panel is open (z-order)
Native video draws on top of the WebView, so the More/audio menu,
participant panel, meeting chat, modals and the image lightbox all opened
BEHIND the shared screen. Now bzNativeSyncTiles clears the native tiles
whenever any of those overlays is present (.meet-panel/.spk-menu/.modal-ov/
.lightbox), and the menu/panel toggles trigger an immediate sync so there's
no lag; the video returns when they close.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 11:14:41 +05:30
Sravan f2efff394b Fix: dock the meeting bar on native calls (decouple it from the shared screen)
The control bar is a draggable FLOATING bar (position:fixed when moved/
restored) meant to sit over the shared screen — which works on web (video is
DOM) but on a native call the screen is a native overlay ABOVE the WebView,
so the floating bar hides behind it, and its live position fed my height
clamp → dragging it resized/reoriented the screen.

Fix: skip makeDraggable on native calls so the bar stays DOCKED in flow at
the bottom. The grid then reserves space above it and the native shared
screen fills that stable area — bar and screen are independent, controls
stay visible and tappable. (A floating bar that overlays the native video
would require a hole-punch rework.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 11:03:35 +05:30
Sravan 5a140e45a1 Fix: clamp native tile height so shared screen never covers the controls
The CSS-only stage sizing wasn't enough — the shared screen still overlapped
the meeting controls. Since the native video is drawn ON TOP of the WebView,
now clamp each tile's height in bzNativeSyncTiles so it can never extend past
the top of the .meet-bar (control bar) — regardless of how the web lays out
the stage. Robust and web-only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 10:51:32 +05:30
Sravan b35c95a5be Fix: shared screen no longer overlaps the meeting controls
scr-full forced #meetGrid to height:100%, so the stage (and the native
video positioned on its rect) extended down over the control bar. The grid
is already flex:1 — it should fill only the space above the bar. Now the
stage flexes to fill that area (flex:1 1 auto) instead of height:100%, so
the native screen view sits above the controls, not over them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 10:44:29 +05:30
Sravan a561852067 Fix build: TileVideoView composes VideoView (can't subclass a non-open class)
Build error: `cannot inherit from non-open class 'VideoView' outside of its
defining module` — VideoView is public, not open, so it can't be subclassed
in the plugin module. Reworked TileVideoView from a VideoView subclass into a
UIView CONTAINER that holds a VideoView: the container is frame-synced to the
web tile rect, the pinch/pan zoom transform lives on the inner video (so it
never fights the position poll), and the name/mute overlays sit on the
container so they no longer scale with zoom. track/layoutMode are forwarded.

Also silenced the extension warning: SampleHandler now restates
`@unchecked Sendable`.

The broadcast extension itself compiled + linked in the failed build, so the
SPM-linked extension injection + App Group setup are working.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 10:25:46 +05:30
Sravan 27c582bceb Outgoing iOS screen-share via ReplayKit broadcast extension
Lets a native-call user share their iPhone screen (whole device, works
backgrounded). LiveKit 2.15.3 ships the broadcast stack (BroadcastManager +
LKSampleHandler + IPC), so:

- New Broadcast Upload Extension target "BroadcastExtension"
  (com.bizgaze.connect.broadcast): SampleHandler.swift subclasses
  LKSampleHandler; injected by mobile/scripts/add-broadcast-extension.rb
  which also LINKS the LiveKit SPM product into the extension + sets the
  App Group. Sources in mobile/ios-broadcast/.
- Plugin: Room created with ScreenShareCaptureOptions(useBroadcastExtension:
  true); startScreenShare -> BroadcastManager.requestActivation() (system
  picker); stopScreenShare -> requestStop(); BroadcastManagerDelegate ->
  fires screenShareState to the web. LiveKit auto-publishes the track.
- ios-patch.sh: RTCScreenSharingExtension + RTCAppGroupIdentifier keys.
- codemagic.yaml: run the injector + sign the 3rd bundle id (.broadcast).
- home.html: toggleScreen native -> start/stop; screenShareState listener
  reflects state + broadcasts meeting-screen so peers' stage shows it.

REQUIRES a one-time manual Apple portal step: enable the App Group on the
com.bizgaze.connect.broadcast App ID (see mobile/IOS_SETUP.md) or the
archive fails code-signing. SPM-linked extension is new on our CI — expect
build iteration. Web deployed (no-ops on builds without startScreenShare).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-06 21:09:02 +05:30
Sravan aed3d22675 Native screen-share: maximize the shared screen + pinch-to-zoom
Better visibility: on a native call, a shared screen now fills the whole
meeting area and hides the small participant tiles (new .scr-full grid
class, toggled when meetNative && sharing). The plugin renders the screen
over that full-area stage rect.

Zoom: the tile video view is now TileVideoView with pinch-to-zoom + pan
(and double-tap to reset) enabled only while it's showing a screen. While
zoomed the view holds a transform and syncVideoTiles stops overwriting its
frame; name/mute overlays hide during zoom.

Needs a Codemagic build (plugin change). Web deployed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-06 20:56:27 +05:30
Sravan e6d3d2d66a Native video: render others' screen-share on native calls
Last native-video gap: on a native (iOS) call the WebView has no LiveKit
connection, so a screen shared by a web/desktop participant never rendered.
The mesh already flips the sharer's tile into the big "stage" (meeting-
peer-screen -> meetSharers -> sharing-mode), so extend the tile sync: each
tile now carries a `screen` flag (meetSharers.has(id)). The plugin renders
that participant's screen-share track (source .screenShareVideo) on the
tile with layoutMode .fit (contain, no crop) instead of the camera.

Outgoing screen-share from iOS is still unsupported (no getDisplayMedia /
ReplayKit broadcast extension) — toggleScreen now shows a clear toast on
native instead of silently failing.

Needs a Codemagic build (plugin change). Web deployed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-06 16:39:39 +05:30
Sravan a5e2ed8a9d Native video: readable tile labels (red mute, name chip) + flip camera
Label legibility: the name + mute overlays were both white/invisible.
- Mute badge is now a RED (#dc2626) circle with a white mic-slash, matching
  the web tile's .meet-mute, moved to the top-left.
- Name is now white on a dark translucent pill (PaddingLabel) so it stays
  legible over any video, bottom-left.

Front/back camera switch: new NativeCall.switchCamera() flips the local
CameraCapturer front<->back (switchCameraPosition, verified in 2.15.3). New
"Flip camera" button on the meeting bar (switchCamera icon), shown only
while a native call's camera is on (updateFlipBtn). Mirroring auto-corrects
(VideoView mirrorMode .auto only mirrors the front camera).

Needs a Codemagic build (plugin change). Web deployed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-06 15:58:12 +05:30
Sravan 34bdd8ea16 Native video: name + mute labels on the native video tiles
The native video covers the web tile's name/mute badges, so redraw those
natively. syncVideoTiles now also carries each tile's name + muted state;
each tile VideoView gets a bottom-left name label (with shadow for
legibility) and a bottom-right mic-slash badge shown when that participant
is muted. Kept above the video renderer via bringSubviewToFront. Web sends
name/muted from meetNames/meetMuted (and ME.name/!meetMic for __local).

Front/back camera switch + screen-share rendering still deferred.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-06 14:10:54 +05:30
Sravan 4415225407 Native video Increment 2b: remote tiles + self-view on tile; speaker fix
Video (2b): render every participant's camera natively, positioned to
match the web meeting tiles. The web has no LiveKit connection on a native
call, so the plugin draws native VideoViews over the WebView. New
NativeCall.syncVideoTiles({tiles:[{uid,local,x,y,w,h}]}) — the web polls
each tile's getBoundingClientRect + user id (400ms + on camera toggle) and
the plugin places a VideoView (subview of the WKWebView, so CSS-px rects ==
points) for whoever has a live, unmuted camera track; camera-off keeps the
web avatar. Replaces the 2a fixed-corner self-view: your own camera now
renders on the __local tile. Remote video correlated by LiveKit identity ==
meetPeerUids user id. APIs verified vs client-sdk-swift 2.15.3 source:
Room.remoteParticipants[Participant.Identity(from:)], Participant.videoTracks,
TrackPublication.source/.track/.isMuted, Track.Source.camera.

Audio: fix "sound starts on the earpiece until I tap something" — the
LiveKit audio engine starting after CallKit activates the session flips the
route to the receiver. Added an AVAudioSession routeChange observer that
re-asserts the loudspeaker (via preferSpeaker) whenever we land on the
built-in receiver mid-call (headset/BT still win).

Web change is safe on the current (2a) build: syncVideoTiles is absent so
the poll no-ops. Needs a Codemagic build to take effect.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-06 11:59:52 +05:30
Sravan 149e32b8d8 Native video Increment 2a: publish local camera + self-view
Wire the camera button on native calls to the plugin instead of a
"not available" toast. New NativeCall.setCamera({on}) calls LiveKit
localParticipant.setCamera(enabled:) so the iOS user's camera is
published to the room — every web/desktop peer renders it via their
existing SFU subscription. Locally the plugin shows a small rounded
self-view (VideoView) pinned top-right over the WebView.

APIs verified against client-sdk-swift 2.15.3 source: setCamera ->
LocalTrackPublication?, TrackPublication.track, VideoView(.track/.layoutMode),
CameraCaptureOptions(position:.front). Front camera only for now.

Rendering the OTHER participants as native tiles synced to the web
meeting grid is Increment 2b (the fragile part) — next build. Until the
new IPA ships, the web branch falls back to an "update the app" toast.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 23:10:19 +05:30
Sravan f27b7af9e4 Remove temporary push/call/photos debug telemetry
Push, native calling, and Photos save are all confirmed working, so strip
the diagnostic instrumentation: the pdbg() helper and all its call sites in
home.html (native-setup-*, registration-*, perm-*, nc-* call events,
photos-fail) and the matching /api/push-debug route in routes.js. Real
console.log/console.warn lines and all functional logic are kept; a couple
of pdbg-only error paths now log via console.warn instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 23:00:03 +05:30
Sravan 2c1e1c7ca5 Fix Photos save for images + add native Quick Look file preview
Photos/Files bug: the lightbox download handed nativeSaveFile a bare
"/files/<id>" with no name, extension, or mime. Empty mime made
bzSaveToPhotos short-circuit as "notmedia" — so saveToAlbum (and its
permission prompt) never ran, and the image landed in the generic Files
folder as an extension-less blob. Now nativeSaveFile trusts the server's
Content-Type when the mime is unknown and appends a real extension
(bzExtForMime/bzEnsureExt), so images reach the Images folder AND Photos.

File preview: replace the @capacitor/share "share sheet" open with a new
native FileOpener plugin (QLPreviewController). bzOpenFile now prefers a
real Quick Look preview and only falls back to the share sheet if the
plugin isn't in the build. Wired file-opener into mobile/package.json and
the codemagic SPM diagnostics loop.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 21:38:48 +05:30
Sravan b2c2acbbc7 Chat files: native download→open control; diagnose Photos-save failures
3. File attachments on native now work like videos: a download icon (with %),
   tap to download into the app's Files folder, then the icon becomes an "open"
   (external-link) control — tap again to open the file via the iOS share/preview
   sheet (@capacitor/share; Quick Look / open-in). State tracked in the local
   library (bzSyncFileTiles), reconciled at startup. Web/PWA keeps the plain
   <a download> link. Added an externalLink icon.

2. Photos save: bzSaveToPhotos now returns a reason; the toast tells the user to
   allow Photos access in Settings when it's permission-denied (the likely cause
   after repeated reinstall testing), and pdbg logs the reason otherwise (noplugin
   vs error) so we can pinpoint it. media-library plugin Swift is unchanged/correct.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 11:48:47 +05:30
Sravan b68ba94d2a SPM: wire local plugins correctly — add Package.swift to each plugin's files array
Root cause of the SPM runtime regressions (call/chat push when closed, photo save):
our local file: plugins didn't function because their package.json `files` array
omitted "Package.swift", so npm can drop it from node_modules on install → cap sync
can't wire the plugin into the CapApp-SPM package → the plugin isn't loaded at
runtime. Official plugins all list Package.swift in files; ours now do too.

Also add build-log diagnostics (node_modules symlink/copy + Package.swift presence,
and the generated CapApp-SPM/Package.swift) so the wiring is provable, not guessed.

Reapplies the SPM migration (Step B) that was reverted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-03 15:56:13 +05:30
Sravan 7f54182186 Reapply "Capacitor 8 — Step B: migrate iOS from CocoaPods to Swift Package Manager"
This reverts commit 166bea4314.
2026-08-03 15:52:46 +05:30
Sravan 166bea4314 Revert "Capacitor 8 — Step B: migrate iOS from CocoaPods to Swift Package Manager"
This reverts commit 92f1f8f1a3.
2026-08-03 15:43:23 +05:30
Sravan 92f1f8f1a3 Capacitor 8 — Step B: migrate iOS from CocoaPods to Swift Package Manager
Move off CocoaPods (sunsetting; trunk goes read-only Dec 2026) to SPM, the Cap 8
default. This also ends the LiveKit git-pin hack — LiveKit becomes a real SPM dep.

- Each local plugin gets a Package.swift (swift-tools 5.9, iOS 15, capacitor-swift-pm
  from 8.0.0, source path ios/Sources/<Plugin>). native-call additionally declares
  LiveKit: .package(client-sdk-swift, exact 2.15.3) + product "LiveKit".
- native-call Swift: import LiveKitClient -> import LiveKit (SPM product name).
- codemagic.yaml: `cap add ios --packagemanager SPM`; removed the "Install CocoaPods"
  (pod install) step; XCODE_WORKSPACE -> XCODE_PROJECT (App.xcodeproj); build-ipa
  --workspace -> --project. Xcode resolves the Swift packages during archive.
- ios-patch.sh: removed the Podfile LiveKit git-pin injection + Podfile.lock deletion
  (no Podfile under SPM). Info.plist/entitlements/AppDelegate/notif.wav patches stay.
- add-share-extension.rb is SPM-safe (operates on App.xcodeproj, no workspace/Pods refs).

Authored blind (no local Xcode) — expect build iterations on the first SPM build
(cap-add SPM layout, CapApp-SPM plugin wiring, LiveKit SPM resolution, signing).
Fully revertible: git revert -> back to Cap 8 + CocoaPods (working).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-03 11:48:45 +05:30
Sravan 9d0fd93d7e Fix outgoing-call re-ring: never send the cancel push to the caller
Hanging up an UNANSWERED outgoing call re-rang the caller's own phone: the server
sent the "cancel" VoIP push to BOTH parties, and the plugin must reportNewIncomingCall
for every VoIP push (iOS rule) → a phantom ring on the caller who just hung up.
Incoming calls don't hit this (an answered call sends no cancel). Fix: DM cancel goes
only to the callee (not startedBy); group cancel skips the starter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-03 11:38:53 +05:30
Sravan 29106370fd Capacitor 8 upgrade — Step A (keep CocoaPods)
Bump to Capacitor 8 while staying on CocoaPods (decouples the major-version bump
from the SPM switch, per the verified plan). Changes:
- mobile/package.json: all @capacitor/* + @capacitor-community/safe-area + cli → ^8.0.0
  (safe-area 8.0.1 verified Cap 8 compatible; @capacitor/assets stays 3.x, version-agnostic).
- 4 local plugins: @capacitor/core peer/dev dep → ^8.0.0; podspec ios deployment_target 14→15.
- codemagic.yaml: node 20→22 (Cap 8 requires Node 22+); `cap add ios --packagemanager Cocoapods`
  (Cap 8 defaults to SPM — force CocoaPods); fail loudly if no Podfile is generated.
- add-share-extension.rb: fallback deployment target 14→15.
Requirements per the Cap 7→8 guide: Node 22+, Xcode 26+, iOS 15 min. capacitor.config has no
adjustMarginsForEdgeToEdge to remove. LiveKit git-pins + native calling unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-01 18:48:57 +05:30
Sravan fafc480904 Fix crash after multiple calls: always reportNewIncomingCall for every VoIP push
iOS 13+ terminates the app if a PushKit VoIP push doesn't call reportNewIncomingCall
before completion(). My earlier "no re-ring blip" change made the cancel handler SKIP
the report for already-known/ended calls — which is exactly what iOS kills the app
for, surfacing as a crash after several calls (a cancel push for a prior call's UUID).
Revert to ALWAYS report then immediately end: for a still-active/ringing UUID the
report errors harmlessly (no second ring) and reportCall ends it; only a late duplicate
cancel shows a brief, unavoidable blip. A crash is far worse than a blip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-01 13:09:25 +05:30
Sravan f4dbbde558 Native calls: route audio to the speaker by default (was earpiece)
The .voiceChat AVAudioSession mode defaults to the earpiece, so call audio came
out of the earpiece and only settled after mute/unmute toggling. Switch to
.videoChat + .defaultToSpeaker + allow Bluetooth so audio goes to the loudspeaker
by default while wired/BT headsets still win. Add preferSpeaker() (override to
speaker when on the built-in receiver) in didActivate AND after mic toggles (the
route can flip back to earpiece on unmute). Report the chosen route in telemetry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-01 00:50:40 +05:30
Sravan 8c737372de Fix pod install: git-pin LiveKitWebRTC 144.7559.11 too (last SPM-only binary)
LiveKitClient + LiveKitUniFFI now pre-download OK; the last unresolved dep is
LiveKitWebRTC (= 144.7559.11), also SPM-only (CDN only has 125.x). Its repo ships
a podspec at that tag with NO further deps, but its source is an :http release-zip
(not in the git tree), so we pin via :podspec => <podspec URL> (not :git, which
would clone a repo with no xcframework). SwiftProtobuf resolves from the CDN. This
should complete resolution for LiveKit 2.15.3 on CocoaPods.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-01 00:16:59 +05:30
Sravan 21430bd590 Fix pod install: also git-pin LiveKitUniFFI 0.0.6 (LiveKit 2.15.3's SPM-only dep)
--repo-update still failed: "Unable to find a specification for LiveKitUniFFI
(= 0.0.6)". LiveKitUniFFI is genuinely NOT on the CocoaPods CDN (trunk returns
"No pod found") — it's SPM-only — but its repo ships a podspec at tag 0.0.6 with
no further deps (it just downloads its prebuilt XCFramework). So pin it to its
git tag too, alongside LiveKitClient. LiveKitWebRTC 144.x + SwiftProtobuf resolve
from the CDN. This should complete resolution and keep us on CocoaPods (no SPM
migration).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 20:25:35 +05:30
Sravan 46cc2610b9 Fix pod install: --repo-update for LiveKit 2.15.3's transitive deps
Git pin now works (LiveKitClient 2.15.3 pre-downloaded), but the build box's
cached spec repo is stale: "Unable to find a specification for LiveKitUniFFI
(= 0.0.6)". Both LiveKitUniFFI 0.0.6 and LiveKitWebRTC 144.7559.11 are published
on the trunk, so --repo-update on the real pod install refreshes the repo and
resolves them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 20:14:57 +05:30
Sravan bcd5699e2a Fix pod install: drop the stale Podfile.lock that cap-sync's pod install created
The git-tag pin worked, but the build failed: "could not find compatible versions
… In snapshot (Podfile.lock): LiveKitClient (= 2.0.18) … In Podfile: LiveKitClient
(from git, tag 2.15.3)". Cause: `npx cap sync` runs `pod install` internally with
the PRE-pin Podfile, creating a Podfile.lock pinned to 2.0.18; our injected git-tag
source then conflicts with that lock. Fix: rm the Podfile.lock right after injecting
the pin so the real "Install CocoaPods" step re-resolves against tag 2.15.3.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 19:55:10 +05:30
Sravan 2c97f45245 Remove stray scratchpad probe files committed by mistake
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 19:47:36 +05:30
Sravan a92cdd69f8 Native calls: get LiveKit 2.15.3 via git-tag pin (stay on CocoaPods) + audio fix
The LiveKitClient CocoaPod on trunk caps at 2.0.18 (2.1+ is SPM-only), so the
2.15 CallKit audio API was unreachable. BUT the repo still ships a valid podspec
at tag 2.15.3, and its deps (LiveKitWebRTC 144.7559.11, LiveKitUniFFI 0.0.6,
SwiftProtobuf) ARE on trunk. So instead of a risky SPM migration:
- ios-patch.sh injects `pod 'LiveKitClient', :git => <repo>, :tag => '2.15.3'`
  into the generated Podfile (after cap sync, before pod install). The NativeCall
  podspec's '~> 2.0' is satisfied by 2.15.3. Idempotent; hard-fails if it can't
  find the App target so we never silently fall back to 2.0.18.
- Plugin re-adds the CallKit<->LiveKit audio-session coordination, now compilable:
  auto-config OFF + engine OFF at load; configure session + enable engine in
  didActivate; disable in didDeactivate; request mic permission on connect.

Core Room APIs (connect/disconnect/setMicrophone) verified compatible between
2.0.18 and 2.15.3 against the real source.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 19:46:48 +05:30
Sravan c3de5ac8e3 Revert "Native calls: upgrade to LiveKit 2.15 + add CallKit audio-session coordination"
This reverts commit 455d16abcc.
2026-07-31 19:35:57 +05:30
Sravan 455d16abcc Native calls: upgrade to LiveKit 2.15 + add CallKit audio-session coordination
Root cause of the intermittent dead-mic / no-audio / late-speaker: LiveKit's
automatic AVAudioSession config races CallKit's activation. The fix needs the
2.15+ audio API, which the build wasn't getting ('~> 2.0' resolved an older 2.x
from a stale spec cache). So:
- NativeCall.podspec: pin LiveKitClient '~> 2.15'.
- codemagic.yaml: 'pod install --repo-update' so the spec repo knows 2.15.x.
- Plugin: disable LiveKit auto audio-session config + keep the engine OFF; in
  CXProvider didActivate set the session category and enable the engine; in
  didDeactivate disable it. Request mic permission on connect so enabling the
  engine in didActivate doesn't block on undetermined permission.

All AudioManager APIs verified against the raw 2.15.3 source (setEngineAvailability,
AudioEngineAvailability.default/.none, audioSession.isAutomaticConfigurationEnabled).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 19:21:39 +05:30
Sravan 155e89c6c0 Fix iOS build: remove LiveKit AudioManager usage (build resolves older 2.x)
Second failure showed 'AudioManager' has no member 'audioSession' either — even
though the 2.15.3 source has both audioSession and setEngineAvailability. So the
build's CocoaPods is resolving an OLDER 2.x (stale spec repo/cache) that predates
the engine-observer audio API. Rather than keep guessing, drop ALL LiveKit
AudioManager audio-session code and keep the last known-good audio behavior
(LiveKit defaults). The valuable fixes that use only CallKit/AVFoundation stay:
re-ring blip guard, CallKit<->UI mute sync, and the WS reportIncomingCall ring
path. Proper CallKit audio-session coordination is deferred until the pod is
pinned/upgraded to LiveKit 2.15+.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 18:36:20 +05:30
Sravan c472ee2618 Fix iOS build: use LiveKit 2.15.3 audio API (drop nonexistent setEngineAvailability)
The build failed: 'AudioManager' has no member 'setEngineAvailability' — that API
is only on unreleased/main docs, not in the resolved LiveKitClient 2.15.3. Use the
API that actually ships (per audio.md): disable LiveKit's automatic AVAudioSession
configuration (AudioManager.shared.audioSession.isAutomaticConfigurationEnabled =
false) and configure the session ourselves in CXProvider didActivate. Removed all
setEngineAvailability(.none/.default) calls.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 18:24:54 +05:30
Sravan 36edc6de12 Native calls: CallKit audio-session coordination, no re-ring blip, mute sync, WS ring path
Plugin (rides next build):
- Audio: disable LiveKit auto audio-session config + keep the engine OFF, then
  configure the session and start the engine ONLY in CXProvider didActivate
  (stop in didDeactivate). Fixes intermittent dead mic / no audio and the "speaker
  turns on late" routing. Request mic permission on connect so enabling the engine
  in didActivate can't block on undetermined permission (SDK #815).
- Re-ring blip: a cancel push for a call we already ended/known no longer reports
  a NEW incoming call (that was the phantom "rings back for a second"); it ends
  the known call cleanly, and only reports+ends for a truly unknown (cold) call.
- Mute display: answer/outgoing reflect muted-by-default on the CallKit screen;
  setMuted now drives mute THROUGH CallKit so the system screen and the in-app
  meeting UI stay in sync.
- reportIncomingCall: new method to ring CallKit from a WebSocket call event — a
  2nd path alongside the VoIP push for when the app is open (push can be delayed);
  deduped by UUID.

Web (deploys now; the WS ring path activates once the build has the new method):
- onDmCall/onGroupCall call nativeReportIncoming for native incoming calls.
- audioActivated telemetry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 18:09:32 +05:30
Sravan 199c32a319 Native calls: answer MUTED by default (house rule)
Plugin connects the LiveKit room without enabling the mic (nothing captured/
published until the user taps Mic, which is also when iOS asks permission).
Web: meetMic starts false so the mic button shows muted; on callConnected the
web pushes the muted state to the plugin so builds whose plugin still connects
the mic live are muted too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 10:46:13 +05:30
Sravan c2b339e284 Native calls: open the REAL meeting window (join the mesh), drop the bespoke overlay
The custom call overlay was wrong — the native call must use the app's actual
meeting UI. Fix: a native call now JOINS the mesh room like any participant, so
the caller/callee tiles, roster, mute state and the whole answer/end lifecycle
run through the existing (tested) meeting code. The only native-specific bit is
meetNative=true → the WebView does NOT open its own SFU media connection (the
plugin already owns this identity's one LiveKit connection); mic/hang-up bridge
to the plugin. This fixes, via existing server code, all the reported bugs:
- "no meeting window" → the real meeting window opens on answer/outgoing.
- "caller stuck Ringing after pickup" → mesh peer-join clears the waiting tile
  and finishMeetingJoin marks the call answered.
- "call still running after the other side hung up" → mesh leave ends the DM
  for both (signaling leaveMeeting); plus an idempotent endDmCallByRoom backup
  kicks a stuck peer when the ending side's WebSocket is down.
- "accept on one device doesn't stop the other" → markDmAnswered (fired on mesh
  join) emits call-taken to the user's other sockets; deliverLocal fans to all.
- "second-device accept wins / collision" → the other device's ring is dismissed
  so it can't double-join the same identity.

home.html: enterMeeting(code, audioOnly, {native, uuid}); skip sfuConnect when
native; toggleMic->plugin; toggleCam blocked (video is the next phase); leave ->
callkitEnd (guarded against the plugin's endCall re-firing).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 19:31:19 +05:30
Sravan 11f72b2592 Native calls: fix answered-call drop, multi-device ring, add in-app call screen
Root cause of "answered but the call disconnects": native calls carry media
over LiveKit and bypass the mesh, so the server only learned "answered" from a
WebView POST. On a cold/locked answer the app is still launching and that event
was lost, so the 40s unanswered timer fired and cancelled the live call. Fix:
- Plugin: notifyListeners("answerCall", retainUntilConsumed:true) so a killed/
  locked pickup isn't lost before the WebView JS attaches.
- Server markDmAnswered: emit call-taken to the callee's OTHER devices (stop the
  ring; no teardown) and call-answered to the caller (flip UI to connected).
- Server declineDmCall: ignore a decline once the call is answered, so dismissing
  a stale ring on a second device can't kill the live call.

Also adds a UI-only in-app call screen for native calls (caller + callee):
avatar, name, live timer, mute (-> plugin), end (-> CallKit). Native media has
no meeting window of its own; this covers "no meeting window / can't unmute".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 18:23:21 +05:30
Sravan 82c6c9ce0e fix(calls): no duplicate native tile; drop Ringing placeholder; name+DP from roster
Caller saw the native callee TWICE — the outgoing 'Ringing…' placeholder (never cleared,
since a native callee doesn't send the mesh 'answered') plus a separate id-labelled tile.
Now when a native LiveKit participant joins: remove the __waiting placeholder, stop
ringback, and label the tile from CONTACTS (name + DP) instead of the raw user id.

Also (plugin, needs build): connectRoom disconnects any previous LiveKit connection
before joining, so repeated calls never leave duplicate/stale participants in the room.

WebView fix deploys now (no rebuild); the connectRoom fix rides the next build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 17:51:46 +05:30
Sravan 3d35a9ece7 fix(calls): play native LiveKit participants in the WebView meeting (inc 1 interop)
Native (CallKit+LiveKit) participants join the LiveKit room but not our WS mesh, so
peerIdForUid() had no mapping and sfuAttach dropped their track — the web caller stayed
on 'waiting' and never heard the native callee. Now sfuAttach/sfuDetach fall back to
keying the tile+audio by the LiveKit identity ('lk:'+id) when there's no mesh peer, and
stop the ringback. So a native<->web call crosses audio. Served — no rebuild.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 17:39:34 +05:30
Sravan 2d3ab3dbd3 fix(calls): only cancel-push unanswered calls; add native-call telemetry
- Re-ring on disconnect: sendCallCancel now only fires for UNANSWERED calls. An answered
  call ends via the WS event on both (awake) sides; a cancel push was re-ringing the
  device that just hung up.
- Native-call telemetry (temporary): the plugin fires callConnected/callError on its
  LiveKit connection; the WebView reports nc-answer/nc-connected/nc-error/nc-end/
  nc-outgoing to /api/push-debug so we can see from server logs whether the native room
  actually connects (no device console available). Served — no rebuild needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 17:20:32 +05:30
Sravan 3ac5b6e7bd fix(ios): import LiveKitClient (the CocoaPod module name), not LiveKit
Build error 'unable to resolve module dependency: LiveKit' — the LiveKitClient pod
sets no module_name, so CocoaPods names the module after the pod (LiveKitClient). The
SDK compiled/linked fine; only the import statement was wrong. Types (Room, etc.)
unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 16:47:39 +05:30
Sravan e60e80e4bd feat(calls): native-call lifecycle endpoints + WebView steps aside (inc 1)
Complete the WebView/server side of native LiveKit calls:
- routes.js: /api/calls/answered (markDmAnswered) + /api/calls/end (endCallByRoom) so
  the server learns a NATIVE call was answered/ended (native media runs over LiveKit,
  bypassing our mesh/WS lifecycle). Additive no-ops for WebView/mesh calls.
- home.html: for native calls the WebView no longer joins the room (one connection per
  identity — the plugin holds it). answerCall -> POST /api/calls/answered + clear invite;
  endCall -> /api/calls/end (answered) or /api/calls/decline (still ringing). Outgoing
  DM/group calls fetch a LiveKit token and hand it to NativeCall.reportOutgoingCall
  instead of enterMeeting. Removed the old callHandoff mic-repush.

Server deploys now; the plugin (native LiveKit) needs a Codemagic build. Still gated by
CALLKIT_ENABLED=0 — flip to 1 only after the build is installed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 16:32:13 +05:30
Sravan 3e8aaad68c feat(ios): native LiveKit connection in the call plugin (inc 1, WIP)
The plugin now carries the call media NATIVELY: on answer it connects the LiveKit Room
from the VoIP payload's url+token and publishes the mic; outgoing calls connect via
reportOutgoingCall(url,token). CallKit stays ACTIVE for the whole call (foregrounds the
app, keeps it alive) — the mic works because LiveKit's audio runs natively and
coordinates with CallKit (unlike WebKit's WebRTC). setMuted -> setMicrophone; end ->
disconnect. Removed the handoff hack.

NOT testable yet: still need (a) WebView to stop joining the room for native calls (one
connection per identity) and drive outgoing via reportOutgoingCall, and (b) server
lifecycle endpoints for native calls (answered/ended), since native media bypasses our
mesh/WS signaling. LiveKit Swift API authored without a local compile — expect a build
iteration or two. Don't build/flip CALLKIT_ENABLED yet.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 16:15:43 +05:30
Sravan aae663ccea feat(calls): mint a LiveKit join token into the native VoIP call payload (inc 1)
Increment 1 server side. Move livekitToken() into server/livekit.js (shared by routes.js
and calls.js). calls.js now mints a per-callee LiveKit join token and calls.js/push.js
put {livekitUrl, livekitToken} in the VoIP invite payload, so the native plugin can
connect the LiveKit room immediately on answer — even from a killed state, before the
WebView loads. No behaviour change while CALLKIT_ENABLED=0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 16:11:21 +05:30
Sravan c4ffe2a4e9 build(ios): add LiveKitClient pod to native-call (native call media)
Foundation for native LiveKit calling: the LiveKit iOS SDK carries the call media
natively and coordinates its audio engine with CallKit's AVAudioSession (AudioManager
.setEngineAvailability on didActivate/didDeactivate) — the thing WebKit's WebRTC can't
do. With this, the CallKit call stays active (stable ring + lock-screen answer +
background) AND the mic works. Native connection code + server LiveKit token in the VoIP
payload + WebView coordination come next. Don't build yet.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 16:03:01 +05:30
Sravan e09d17f1a7 fix(ios): stop VoIP-push crash; hand mic to WebView after answer; missed-call banner
CRASH: iOS terminates an app that receives a VoIP push without calling
reportNewIncomingCall. My re-ring 'fix' made the cancel path call completion() without
reporting -> crash. Always report then immediately end on cancel (a tiny ring blip is
unavoidable; a crash is worse).

MIC + earpiece: an ACTIVE CallKit call reserves the mic (WebView WebRTC gets a dead mic
+ earpiece routing). So on answer keep CallKit active only long enough to foreground the
app, then end it and fire 'callHandoff'; the WebView forces the loudspeaker and
re-acquires the mic (sfuSetMic off/on, retried while it finishes joining).

MISSED CALL: endDmCallByRoom now sends a plain missed-call banner to the callee when the
call ends unanswered (timeout / caller hung up before pickup); skipped on decline.

Server (missed banner) deploys now; plugin + web handoff need a Codemagic build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-29 22:48:24 +05:30
Sravan 9dc253143e fix(ios): keep CallKit call active on answer so the app foregrounds
Answering did not open the app: ending the CallKit call immediately (to free the mic)
made iOS cancel the app launch before it foregrounded. Keep the call ACTIVE on answer
— fulfilling an active-call answer is what foregrounds/unlocks the app — and fire the
answerCall event so the WebView joins. didActivate stays a no-op (don't fight WebKit's
mic). The CallKit call is ended later when the WebView call ends.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-29 20:44:09 +05:30
Sravan 6096b62368 feat(calls): CallKit ring-only + WebView media (background audio via voip mode)
Pivot away from the native-LiveKit rewrite. Discovery: the 'voip' UIBackgroundMode
already keeps the WebView's call audio alive when backgrounded (confirmed on device),
so background audio is solved WITHOUT native media. The only issue was CallKit
reserving the mic. So use CallKit purely for the incoming RING:

- Plugin CXAnswerCallAction: fulfill, then immediately end the CallKit call
  (reportCall endedAt) to RELEASE the mic, and fire answerCall to the WebView after a
  ~1s beat so iOS tears down the CallKit audio session first. didActivate no longer
  reconfigures the session (was fighting WebKit).
- home.html: outgoing calls no longer register with CallKit (WebView-only → mic works);
  incoming still rings via CallKit → hands off to the WebView on answer.

Net: native full-screen ring + working mic + background audio + all existing call
features. Needs a Codemagic build; then flip CALLKIT_ENABLED=1 to test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-29 18:25:59 +05:30
Sravan e7c3231c50 feat(calls): CallKit kill-switch + fix ~1s re-ring on cancel
MIC BROKEN with CallKit: a CallKit call reserves the microphone, so the WebView's
WebRTC can't capture it — calls are unusable until native LiveKit media lands. Add a
server kill-switch (CALLKIT_ENABLED, default OFF) so CallKit can be flipped without an
app rebuild: /api/meetings/config now returns callkit; setupNativeCall bails when off
(-> WebView calls, mic works); push.js only sends VoIP/CallKit pushes when enabled.
Deploying with the flag unset immediately restores working WebView calls.

RE-RING: a late cancel push for an already-declined call hit the plugin's 'unknown
uuid' path and re-reported a fresh incoming call (~1s re-ring). Track endedCalls and
make a late cancel for an already-ended call a no-op.

Server part deploys now (no rebuild); plugin re-ring fix ships with the native build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-29 17:54:21 +05:30
Sravan 3e21aa30d7 fix(calls): cancel the CallKit ring when the caller ends before answer
Bug: a killed/backgrounded callee is woken only for the CallKit ring and has no
WebSocket yet, so the existing dm-call active:false (WS-only) never reaches it and
it keeps ringing after the caller hangs up.

Fix: send a 'cancel' VoIP push on call teardown.
- push.js: sendCallCancel() sends a {type:'cancel',callUUID} VoIP push to the user's
  ios-voip tokens; invites now carry type:'invite'.
- calls.js: endDmCallByRoom + endGroupCallByRoom fire sendCallCancel to the rung users.
- NativeCallPlugin: on a cancel push, end the reported call (reportCall endedAt); if the
  invite was never seen, report-then-end to satisfy iOS's 'report a call per VoIP push'.

Server part deploys now; the plugin part needs the next Codemagic build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-29 11:09:07 +05:30
Sravan cd7ab74eed fix(ios): NativeCallPlugin Swift compile errors
- didReceiveIncomingPush: normalise payload.dictionaryPayload ([AnyHashable:Any])
  to [String:Any] before storing/using (the reported build error at :121).
- CXProviderConfiguration(localizedName:) instead of the no-arg init (available on
  all deployment targets, avoids an availability edge).
- Make two 'calls[uuid] ?? [:]' bindings explicitly [String:Any] to avoid empty-
  literal inference ambiguity.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-28 23:03:01 +05:30
Sravan f63aba0ed1 feat(ios): native CallKit + PushKit VoIP calling plugin + web bridge
The native call feature (iOS). Backward-compatible: without the plugin (current
builds) nativeCallOn() is false and every CallKit branch is skipped, so web/older
builds behave exactly as before.

Native (mobile/plugins/native-call, a local Capacitor plugin like audio-route):
- PushKit: registers for VoIP pushes, reports the VoIP token to JS (-> /api/v1/devices
  'ios-voip'). On an incoming VoIP push, reports a CallKit incoming call (full-screen
  ring, works when the app is force-killed).
- CallKit: answer/decline/end -> events to JS; configures the call AVAudioSession on
  didActivate so the WebView's WebRTC audio rides a call-priority session (background).
- Outgoing calls register with CallKit too (reportOutgoingCall) so they get the same
  active-call background-audio context.
- NativeCall.podspec (frameworks CallKit/PushKit/AVFoundation); added to mobile deps;
  ios-patch.sh now sets UIBackgroundModes = [audio, voip] (voip required for PushKit).

Web bridge (home.html): setupNativeCall() registers the VoIP token, joins on CallKit
answer, leaves/declines on CallKit end; on CallKit devices the in-app call-invite popup
+ WebAudio ring are suppressed (the system rings instead); outgoing calls are reported
to CallKit; call-end events dismiss the CallKit call. calls.js threads a stable call
uuid through the dm-call/group-call WS events + start responses so both sides can match
the CallKit call.

Needs a Codemagic build to compile the plugin; first on-device iteration expected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-28 22:34:27 +05:30
Sravan fd2eb42e25 feat(calls): server foundation for native CallKit/VoIP calling (phase A)
First slice of the native call feature. Backward-compatible: with no VoIP tokens
registered yet it behaves exactly like today's banner push.

- push.js: sendApnsVoip() sends a PushKit VoIP push (apns-push-type 'voip', topic
  <bundle>.voip, reusing the same .p8) to wake a killed app for CallKit; and
  sendCallNotification() which PREFERS a VoIP push when the user has an 'ios-voip'
  token, else falls back to the normal alert/banner push (Android/web/pre-CallKit iOS).
- routes.js: /api/devices now accepts platform 'ios-voip' (the PushKit token, stored
  alongside the normal alert token in device_tokens).
- calls.js: each call now carries a stable crypto.randomUUID() (CallKit needs a UUID
  to report + later cancel the call); DM and group call notifications route through
  PUSH.sendCallNotification instead of the raw banner push.

Next: the native-call Capacitor plugin (PushKit + CallKit + LiveKit iOS SDK).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-28 20:57:56 +05:30
Sravan 37e58f6087 feat(push): bundle a custom notification sound (notif.wav) for chat + calls
Notifications were silent despite the payload requesting sound:'default' and correct
device settings. Ship an explicit tone: a generated PCM .wav is bundled into the app
(ios-patch.sh copies it in; add-share-extension.rb adds it to the App target's Copy
Bundle Resources, tolerantly) and the server now sends sound:'notif.wav'. Part of the
consolidated iOS build alongside the background-audio + call-push + AppDelegate fixes.

Only affects iOS-native-app tokens (currently just the one test device); web push
ignores the field. Needs a fresh Codemagic build for the bundled file to exist.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-27 23:03:45 +05:30
Sravan 5a1ce5fdba fix(ios): declare background audio so calls survive minimising the app
Capacitor/WebView apps get suspended by iOS a few seconds after backgrounding, which
freezes the WebRTC mic + audio pipeline — so when the user minimised the app or locked
the phone during a call, no one could hear anyone. Add UIBackgroundModes=[audio] to
Info.plist (via ios-patch.sh) so iOS keeps the audio session (and the app) alive while
a call is actively playing/recording. Video rendering still pauses in the background
(unavoidable in a WebView) but voice continues. Needs a fresh Codemagic build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-27 22:24:39 +05:30
Sravan a0b3936799 fix(calls): send native push for incoming calls + replay on reconnect
Calls only notified over the chat WebSocket (CHAT.pushToUser), so a CLOSED app
(no live socket) never rang — unlike messages, which also call PUSH.sendToUser.
Add PUSH.sendToUser for both DM (startDmCall -> callee) and group (startGroupCall
-> other members) so APNs/FCM/WebPush alerts a closed device.

To make the alert actionable, add CALLS.replayActiveCalls(userId, ws), invoked
from the chat-hello handler: when a socket (re)connects, re-send any dm-call /
group-call the user is currently being rung into (the original events fire once at
call start and are missed by an app that was closed). Opening the app from the push
then re-surfaces the invite so they can answer within the ring window.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-27 22:13:52 +05:30
Sravan 1920258fd6 fix(ios): forward APNs device token from AppDelegate to Capacitor
ROOT CAUSE of iOS push not working: Capacitor 7's default AppDelegate.swift
template does NOT implement application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
or ...didFailToRegisterForRemoteNotificationsWithError:. So when @capacitor/push-
notifications calls registerForRemoteNotifications(), iOS fetches the APNs token
and calls the AppDelegate, but nothing posts .capacitorDidRegisterForRemoteNotifications,
so the plugin never delivers the token to JS. register() 'succeeds' yet neither the
registration nor registrationError event fires — proven by server push telemetry
(register-called logged; no token, no error; device_tokens stayed empty).

inject-push.js adds the two forwarding methods to the CI-generated AppDelegate
(idempotent, tolerant — never fails the build), wired into ios-patch.sh after the
audio patch. Verified against the real Capacitor 7 template: methods land inside
the class, braces balance, both listeners present.

This is the missing piece alongside the earlier aps-environment entitlement fix and
the server APNs config. Needs a fresh Codemagic build to take effect.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-27 21:27:25 +05:30
Sravan c6523a8461 debug(push): add native push-setup telemetry to trace iOS registration
device_tokens stays empty after reinstall+Allow, so the APNs token is never
obtained or never reaches the server, and there's no device console on Windows.
Add a /api/push-debug collector and breadcrumbs through setupNativePush (plugin
presence, permission state, register call, registration event/error, token POST
result) so the failing step is visible in server logs. Temporary — remove once
push is confirmed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-27 21:20:03 +05:30
Sravan 83b445e32d fix(ios): inject aps-environment entitlement so APNs push registration works
The @capacitor/push-notifications plugin does not add the Push Notifications
capability to the CI-generated Xcode project (that's a manual Xcode step), and
add-share-extension.rb only merged the App Group into App.entitlements, assuming
aps-environment was already there. It never was — so on device PushNotifications.
register() failed with 'no valid aps-environment entitlement', no APNs token was
obtained, and device_tokens stayed empty (server had nothing to push to).

ios-patch.sh now creates App/App.entitlements with aps-environment=production
before the share-extension script merges the App Group in. Still requires the App
ID to have Push Notifications enabled (so the profile carries the entitlement) and
the server APNS_* key set (Step 5) for end-to-end delivery.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-26 21:04:12 +05:30
Sravan 381c4ddfee fix(deploy): reload NPM after deploy so it re-resolves the app's IP
Root cause of a post-deploy outage: recreating the app container can assign it a NEW
docker network IP. Nginx Proxy Manager caches the app's upstream IP at config-load,
so it kept connecting to the OLD IP (which, after adding the postgres/redis services,
was reassigned to bizgaze-postgres) → 'Connection refused' → site down until nginx
re-resolved. deploy.sh now runs 'nginx -s reload' in the NPM container after verify
(normal + rollback), non-fatal if NPM isn't detected. This makes deploys self-healing
for the app-IP-change case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 23:43:28 +05:30
Sravan 63f2c588da feat(scale): swappable pub/sub layer + fix chat.js missed awaits (Phase 6)
Two things:

1. FIX a live regression the async conversion missed: chat.js calls repos via the
   lazy repos() helper (not the R. prefix), so my sweep skipped it — effectiveStatus
   / broadcastPresence read `repos().users.byId(userId)` synchronously, but that's a
   Promise now, so presence broadcasts always reported status 'active' and dropped
   last_seen. Now awaited (effectiveStatus/broadcastPresence async); touchSeen is a
   fire-and-forget UPDATE with .catch. Audited all non-R. repo calls — only chat.js
   was affected (media.js backfill was already awaited).

2. Swappable pub/sub for multi-instance real-time fan-out (the actual blocker to
   running >1 instance — not the DB). server/pubsub.js picks a backend by
   PUBSUB_BACKEND (default 'memory'). Local socket delivery is UNCHANGED; publish is
   additive — memory = no-op (zero hot-path cost, identical single-instance
   behaviour), redis = fan-out to other instances with a self-echo guard. chat.js
   pushToUser/broadcastPresence now also publish; each instance subscribes to deliver
   remote events to its local sockets. Interface is tiny so Redis is one swappable
   file (Postgres LISTEN/NOTIFY or NATS could drop in the same way — never hardwired,
   as requested). Dormant redis service added to compose behind the 'scale' profile;
   redis dep added; PUBSUB_BACKEND/REDIS_URL documented.

Validated: smoke 22/22 (memory), e2e chat delivery green. NOTE: full multi-instance
also needs distributed presence (isOnline is per-process) + meeting-signaling
sharing — chat/presence fan out via this layer; those are follow-ups.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 23:20:02 +05:30
Sravan 363c4a539f feat(db): add bizgaze-postgres service to compose (engine cutover infra)
Adds a dedicated Postgres 16 service (container bizgaze-postgres, own named volume
bizgaze_pg_data, healthcheck) on the shared NPM network. The app depends_on it
healthy. Inert until DB_BACKEND=pg is set in .env — default stays SQLite, so this
deploy changes nothing functionally; it just makes the engine available. Documented
POSTGRES_PASSWORD / DATABASE_URL / DB_BACKEND in .env.example.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 23:08:32 +05:30
Sravan 5f342b0b4e fix(db): portable thread queries for Postgres (conditional cursor + subquery alias)
The DM/group thread queries used `(? IS NULL OR created_at < ?)` — an all-NULL
param Postgres can't type ('could not determine data type of parameter') — and an
unaliased FROM-subquery (Postgres requires an alias). Both rewritten to add the
`created_at < ?` clause only when a cursor is given, and alias the subquery `t`.
Portable; sqlite db-smoke still 22/22.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 22:32:42 +05:30
Sravan e67a783bdc feat(db): Postgres backend + dialect-portable queries + data migration (Phase 5)
- db/pg.js: the pg backend (prepare/exec/tx/init) — ?→$N translation, BIGINT parsed
  as Number (matches sqlite; else expires_at<Date.now() compares string<number),
  transactions on one pooled client, init() applies schema.pg.sql. Same interface as
  db/sqlite.js, so repos are unchanged.
- repos.js: the ~7 SQLite-only queries rewritten to run on BOTH engines —
  audit.add @named→positional; email lookups COLLATE NOCASE→LOWER()=LOWER();
  INSERT OR IGNORE→ON CONFLICT DO NOTHING (addMember/poll vote/favorite);
  mergeInto's UPDATE OR IGNORE→UPDATE…WHERE NOT EXISTS/NOT IN and INSERT OR
  REPLACE→ON CONFLICT DO UPDATE. Re-validated on sqlite: db-smoke still 22/22.
- server.js: boot now `await db.init()` before listening (pg creates tables; sqlite
  no-op), so the first request can't hit a missing table.
- db/migrate-sqlite-to-pg.js: one-shot row copy in FK order (bulk insert, TRUNCATE
  first so re-runnable). audit_log id left to PG's identity.
- package.json: add pg ^8.13.1.

Next: validate DB_BACKEND=pg smoke against a real Postgres on the server, then merge.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 22:28:04 +05:30
Sravan 3250530596 feat(db): complete async call-site conversion — Phase 3 done, validated on SQLite
The full sync→async conversion is complete and green on the SQLite backend. Every
DB call across the app now awaits the async adapter, so the identical code runs on
Postgres at cutover.

Converted (this commit finishes Phase 3):
- session.js: currentUser/apiKeyFromReq async → 63 route awaits + WS + static.
- routes.js: all ~250 R.* awaited; DTO helpers (namesFor, avatarsFor, buildMsgDTO,
  buildPollDTO, reactionsForMessage, postSystemMessage, pushGroupUpdate,
  issueRefreshToken, provisionFromBizgaze) made async; every `.map(x=>buildDTO(x))`
  restructured to `await Promise.all(...map(async...))` preserving order; `.filter`
  predicates that hit the DB moved to an `asyncFilter` helper; chained
  `R.x.y(...).length/.map/.filter` wrapped as `(await R.x.y(...)).method`; stream
  upload handlers (recording/transcript/attachment) made async.
- calls.js / signaling.js: all call/meeting fns async; leaveMeeting AWAITS
  persistCallHistory + finalizeTranscript BEFORE endCallByRoom (ordering matters —
  fire-and-forget would race the map teardown); WS handle()/cleanup() async with
  .catch guards.
- static.js: authAttachment(Raw) async (the .some carrier check became a loop),
  handleGet async; server.js dispatch catches handler rejections → 500 not a hang.
- media.js backfill, push.js, reminders.js, webhooks.js await their repo calls.

Validation on DB_BACKEND=sqlite: db-smoke 22/22; legacy e2e 80 checks pass with zero
FAILs (throws only at a PRE-EXISTING WS lobby-drift assertion, unrelated). Every
server file `node --check` clean.

Still on the branch — master untouched. Next: Phase 5 (pg backend + ~7 dialect
queries + data migration + Docker Postgres + cutover), then merge.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 22:06:27 +05:30
Sravan 2460c0f9eb wip(db): async call-site conversion in progress (Phase 3) — DO NOT MERGE yet
On the db-migration branch only; master stays clean + deployable. Foundation
(adapter, pg schema, smoke harness) is already on master and safe.

Done:
- repos.js fully async (Phase 2, validated: node --check clean, no missed transforms).
- session.js currentUser/apiKeyFromReq async.
- Mechanical `await` prefix applied across routes/static/calls/signaling/reminders/
  webhooks/push.

Remaining (does NOT compile yet — deterministic to finish):
1. Async cascade: helper fns that now contain `await` must be marked async and their
   callers awaited. node --check points to each (namesFor, authAttachmentRaw/
   authAttachment in static, the WS handlers in calls/signaling, reminders/webhooks
   loops).
2. DTO builders are the real work: namesFor, avatarsFor, buildPollDTO, buildMsgDTO,
   recDTO all became async — every `.map(x => buildMsgDTO(...))` etc. must become
   `await Promise.all(arr.map(async x => ...))`.
3. Chained calls `R.x.y(...).map/.length/.includes` → `(await R.x.y(...)).method`.
4. Then: node --check all green → node test/db-smoke.js green → e2e → merge to master.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 21:26:10 +05:30
Sravan dbd209ac2b feat(db): async DB adapter with swappable sqlite backend (Phase 1)
server/dbx.js selects a backend by DB_BACKEND (default sqlite; pg added at cutover).
server/db/sqlite.js wraps the synchronous node:sqlite instance in the async
interface repos will call — prepare(sql).{get,all,run}, exec(sql), tx(fn), init().
Results come back as resolved Promises so identical repo code runs on synchronous
SQLite (dev/test) and asynchronous Postgres (prod).

tx() gives multi-statement atomicity that stays correct on both engines (sqlite is
single-connection; the pg backend will run it on one pooled client) — needed for the
account-merge transaction in repos.

Verified: get/all/run/tx all work end-to-end; confirmed no code reads
.changes/.lastInsertRowid, so the repo conversion is purely sync->Promise. Unwired —
nothing requires dbx.js yet; prod path untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 21:10:53 +05:30
Sravan e482cb5bb2 test(db): focused DB smoke harness for the migration (22 checks, green on SQLite)
Covers the DB-backed HTTP paths the async repo conversion touches — auth, users,
messages, attachments, conversations/groups, reactions, mentions, edit/delete,
polls, scheduled meetings (paginated), favorites, audit — asserting current API
shapes. Runs to completion with a pass/fail count and honours DB_BACKEND so it
doubles as the sqlite-vs-pg parity check at cutover. No WS/signaling (in-memory,
not the DB).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 21:08:29 +05:30
Sravan 1709a331d1 feat(db): Postgres target schema (Phase 1 of the migration)
server/db/schema.pg.sql — the full Postgres DDL, every column defined up front (no
ALTER-ordering fragility). SQLite→PG type mapping documented in-file (epoch-ms
INTEGER→BIGINT, 0/1 flags→SMALLINT kept numeric so app code is unchanged, sizes→
BIGINT, audit rowid→GENERATED IDENTITY). Mirrors the three existing FKs and adds a
new idx_messages_attachment (the /files auth scan we cached earlier becomes a keyed
lookup).

Validated against a throwaway Postgres 16: loads with no errors, 24 tables + 44
indexes created. Unwired — nothing uses it yet; the SQLite path is untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 19:46:04 +05:30
Sravan b2c4b10e41 fix(db): guest_emails/lobby ALTERs ran before scheduled_meetings existed + e2e drift
Migration prep. Two real fixes surfaced while building a regression harness:

1. db.js: the `guest_emails` and `lobby` ALTER TABLEs sat at lines 241/244, BEFORE
   scheduled_meetings is CREATEd (line 299). On a FRESH database the ALTER fails
   (no table yet), is swallowed by the try/catch, and the columns are never added —
   so a brand-new deploy is missing them and scheduling with guests crashes. Prod
   escaped it only by incremental deploy history. Moved both ALTERs to after the
   CREATE. (The upcoming Postgres schema defines every column up front, so this
   whole class of ordering bug goes away there.)

2. test/e2e.js: /api/meetings returns paginated `{list, pastTotal, page, pageSize}`
   now, not a bare array — updated three `.data.find` → `.data.list.find`.

No prod behaviour change (prod already has the columns; ALTERs are idempotent).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 19:43:46 +05:30
Sravan ee95f594c6 style(share-ext): clean SF-Symbol X + paper-plane instead of heavy pill/circle
The top-bar buttons looked heavy against the navy bar (thick grey X-circle, bold
"Send" pill). Swapped for light SF Symbols on the navy bar: a thin `xmark` for
cancel and a `paperplane.fill` for send (semibold, enables when ≥1 chat is picked).
Icon-only send matches the Teams reference — the radio checks already show what's
selected, so the "(N)" count text is dropped. Native-only — needs a build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 19:08:38 +05:30
Sravan 854bc86a6e feat(share-ext): fix double "Send to", Teams-style layout, clearer branding
Two things from testing (the in-sheet picker with avatars + multi-select works):

1. Double "Send to": after the extension sent, opening the app ALSO popped the web
   "Send to" modal for the same file. Cause: the extension wrote a safety-net
   manifest up front, which the app then picked up. Now the manifest represents an
   UNSENT share only — written solely when the extension can't send (no token) or a
   send fails. A successful in-sheet send clears the staged files and leaves nothing,
   so the app never re-offers it. Cancel also clears staged files (no orphans).

2. Layout aligned to the Teams reference:
   - Preview strip of thumbnails for what's being shared (image → the image, video →
     first frame via AVAssetImageGenerator, else a doc icon).
   - Radio selectors on the right — an always-visible empty circle that fills to a
     navy check when selected (clearer multi-select than an appear-on-select tick).
   - "Recent chats" section header; subtitle under each name (Direct message /
     Group · N members).
   - Clearer branding: bold white "Share to Biz Connect" on the navy bar.

Native-only — NEEDS A NEW iOS BUILD. Balance + selectors checked.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 18:25:15 +05:30
Sravan 4d446a5425 feat(share-ext): avatars, multi-select, and Biz Connect branding in the picker
Three follow-ups on the in-sheet picker:
- Profile photos: rows now show the real avatar (fetched from the conversations
  API's `avatar` field with the bearer token, or a data-URL decoded inline),
  rendered as a circle; coloured initials as the fallback — matching the app.
- Multi-select: tap toggles a checkmark instead of sending immediately; a "Send (N)"
  button in the nav bar sends to every selected chat. Each file is uploaded ONCE and
  its attachment id reused across all targets (the server allows the uploader to
  reattach the same id), so multi-send doesn't re-upload.
- Branding: navy (#1F3B73) navigation bar with a white "Biz Connect" prompt over the
  "Send to…" title and white controls.

Native-only — NEEDS A NEW iOS BUILD. Balance + selectors checked.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 18:00:01 +05:30
Sravan d664dde798 feat(share): send from inside the share sheet — the Teams-style in-extension picker
Replaces the wrong approach (stage + try to bounce into the app, which iOS blocks)
with the one Teams/WhatsApp actually use: the picker and the send happen INSIDE the
share extension, so there's no app-open at all. Tap Share → Biz Connect → pick a
chat → it uploads and sends, right there in the sheet.

How the extension can send without the app: it's a separate process that can't see
the web app's HttpOnly cookie, so:
- server: GET /api/share/token mints a bearer token for the logged-in user.
- web: on every launch the app fetches that token and hands it to the extension via
  the App Group (ShareInbox.setAuth writes token+base to the shared UserDefaults).
- extension: reads the token and calls the SAME API the native client uses —
  GET /api/messages/conversations to list chats, POST /api/messages/upload for each
  file, POST /api/messages to send. Native UITableView picker with search.

Robustness: it still stages the files + writes a manifest first, so if there's no
token yet (user never signed in) or the send fails, the file isn't lost — the app
collects it on next open, exactly as before. On success the manifest is cleared so
the app doesn't re-offer it.

Server + web are live now; the token endpoint is harmless until a build ships the
extension. NEEDS A NEW iOS BUILD for the picker itself.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 16:33:23 +05:30
Sravan 2ec0a0c0cd feat(share-ext): confirmation card instead of a confusing blank flash
A Share Extension opening its host app is unsupported on modern iOS (restricted
~iOS 14), so the programmatic bizconnect://share open is silently blocked and the
user just saw a blank flash back to Photos — looking broken even though the files
staged fine.

The extension now shows a small native card after staging: "✓ Ready to send — Open
Biz Connect to choose a chat", with an "Open Biz Connect" button (user-initiated
open has the best chance of working) and a Done button. It still attempts the
auto-open first. Either way the app collects the staged files when next opened, so
the manual path that already works is unchanged — this just removes the "did it
even work?" confusion.

Renamed the local `staged` array to `collected` to free `staged` for the state
flag. Balance + selectors checked. NEEDS A NEW iOS BUILD (native change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 16:24:15 +05:30
Sravan 0c3487fdb0 polish(share): picker avatars + target name + pre-warm video poster
Follow-ups from testing the share flow (which now works end-to-end):
- Send-to picker showed only initials — now shows the real profile photo when the
  chat has one (matching the sidebar/forward avatars), coloured initials otherwise.
- During send it only said "Uploading 60%" with no idea WHO to — now the header and
  progress name the target ("Sending to Manasa Rapolu · 60%").
- After sending, a video bubble sat blank (just a timestamp) for a second or two
  while the poster generated on first view. media.js now warms the poster thumbnail
  at UPLOAD (temp-then-rename), and the on-demand /thumbs handler also writes via a
  temp, so the two can't serve a half-written JPEG. The bubble shows its poster
  right away.

Web + server only — live on deploy. Does NOT address the share extension failing to
auto-open the app (an iOS limitation, handled next in the native build).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 16:21:02 +05:30
Sravan 4836b1e197 fix(share): read the shared file via native Filesystem, not fetch (remote-origin)
Sharing a photo into the app: the "Send to…" picker appeared and staging worked,
but picking a chat said "no file found". Cause: the app loads its UI from the
REMOTE origin (remote.bizgaze.com), and I read the staged bytes with
fetch(convertFileSrc(uri)). Capacitor's local `_capacitor_file_` serving isn't on
the remote origin, so that fetch is CORS-blocked / hits the remote server → 404.

Read through the native bridge instead: Filesystem.readFile returns base64 in
native code, never touching the webview network stack, so it reads the App Group
file the app has entitlement access to. Falls back to it.path, then to the old
webview path for local-asset builds. Web-only fix — no rebuild.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 16:08:58 +05:30
Sravan d5658eeb9e ci: surface the real xcodebuild error on archive failure
The archive keeps failing with only "Failed to archive" and exit 65 — no reason
shown. Cause: `xcode-project build-ipa` prints a prettified summary and swallows
xcodebuild's raw "error:" lines, which only survive in the /tmp/xcodebuild_logs
artifact. On failure we now grep that log for the signing/entitlement/compile
error and print it inline, so the next red build states WHY instead of just 65.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 15:40:01 +05:30
Sravan 59310419ba fix(ci): share-extension injector looked one dir too high for the xcodeproj
Codemagic log: "xcodeproj not found at /Users/builder/clone/ios/App/App.xcodeproj"
— missing the `mobile/` segment. The script lives in mobile/scripts, so __dir__ is
mobile/scripts and `File.expand_path('../..', __dir__)` resolved to the REPO ROOT,
not mobile/. The project is at mobile/ios/App/App.xcodeproj. Changed to '..' so ROOT
= mobile, which fixes PROJECT, SRC_DIR, APP_DIR and the entitlements path together.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 15:28:20 +05:30
Sravan 0a2c7376b9 feat(share): "Biz Connect" in the iOS share sheet — share a photo/file into a chat
Adds the reverse direction: share FROM Photos/Files/Safari INTO a Biz Connect
conversation. An app can only appear in the iOS share sheet as an app-extension
target, so this is real native work, not a web change.

Pieces:
- mobile/ios-share/ShareViewController.swift: a UI-less Share Extension. It stages
  the shared items into the App Group container and opens bizconnect://share. It
  deliberately does NOT reimplement the chat picker — that lives in the app, which
  already has the chat list, search and upload progress. Appends to the manifest
  (never overwrites), so sharing twice before opening the app loses nothing.
- mobile/scripts/add-share-extension.rb: injects the extension target into the
  Capacitor-generated Xcode project on every CI build (Codemagic checks out fresh),
  using the xcodeproj gem that ships with CocoaPods. Embeds it, sets the bundle id
  <app>.share, and MERGES the App Group into the app's entitlements rather than
  clobbering them (push's aps-environment must survive). Idempotent.
- mobile/plugins/share-inbox: getPending()/clear() to read that manifest — the App
  Group container isn't one of Filesystem's known directories, so it needs a bridge.
- home.html: on bizconnect://share (and every resume, and cold-launch), read the
  inbox and show a "Send to…" picker over the chat list; chosen files run the SAME
  upload + /api/messages send as an in-app attachment. Reuses convertFileSrc to read
  the staged bytes with no base64 marshalling.
- ios-patch.sh registers the bizconnect URL scheme; codemagic.yaml fetches a profile
  for the .share bundle id too.

One-time manual gate (CI cannot toggle App capabilities): the App Group
group.com.bizgaze.connect must be created and enabled on both App IDs in the Apple
portal — documented in mobile/IOS_SETUP.md. Without it the two processes can't see
each other's files and sharing silently no-ops; everything else still works.

Validated cross-file: pod-name/jsName/method wiring for all three plugins, App
Group id identical in all 4 files, URL scheme consistent across extension/plist/web,
entitlement-merge preserves push. Needs a new iOS build (new targets + plugins).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 22:58:08 +05:30
Sravan 00ea140280 feat(photos): downloaded media also lands in a "Connect" album in Photos
The Files folder is the app's own copy — it powers offline playback and Manage
storage — but Files is not where anyone looks for photos and videos. The Photos app
is, and only PhotoKit can write there; @capacitor/filesystem cannot, because an
app sandbox and the photo library are separate stores. So this adds a small native
plugin, mirroring the existing audio-route one.

- mobile/plugins/media-library: saveToAlbum({path, album, kind}) finds or creates
  the album and adds the asset. Uses addResource(with:fileURL:), which is uniform
  for photo and video and non-optional, unlike creationRequestForAssetFrom*, which
  can silently no-op.
- Requests .readWrite, NOT .addOnly: addOnly can add an asset but cannot look up or
  create an ALBUM, which is the whole point here. Both photo-library usage strings
  are already set by ios-patch.sh.
- If the album can't be resolved (e.g. "limited" access), the asset is still saved
  to the camera roll — landing somewhere beats failing outright. A racing create
  from two simultaneous downloads re-looks-up instead of erroring.
- Podspec named MediaLibrary.podspec with s.name = 'MediaLibrary' to match
  PascalCase of the package name — the same trap that broke the AudioRoute build.
  Checked by a script: pod name, jsName and declared-vs-implemented methods.

Entirely best-effort from the web side: a denied permission or an older app build
never fails a download that is already safe in the app folder. Added a Settings
toggle since this does keep a second copy of the file.

Needs a new iOS build — new native plugin.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 22:39:27 +05:30
Sravan 82fa8e04eb fix(video): one centred control — download → % → play, as specified
The download button was a small corner overlay, which landed on top of the native
control bar's speaker icon. That was not the design asked for either: it should be
a single control in the CENTRE that turns into a play button once downloaded.

The tile is now the masked poster plus one centred button:
  not downloaded → download icon  (the element has no src at all, so nothing is
                                   fetched until it is tapped)
  downloading    → live % inside that same button, in place
  downloaded     → play icon; tapping plays the LOCAL file

The native control bar is switched on only when playback starts, so there is
nothing for the control to collide with. Progress reports into the button rather
than the floating chip, so a video download no longer shows two indicators.

Also gives the tile a min-height so the thread doesn't jump while the poster loads.
Web/PWA is untouched — it has nowhere to download to, so it keeps streaming with
native controls.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 19:57:07 +05:30
Sravan cb81dd6106 feat(storage): Biz Connect folder in Files, manage storage, videos save once
Three connected pieces, so downloads stop being write-only.

1. A folder the user can actually find. ios-patch.sh now sets UIFileSharingEnabled
   and LSSupportsOpeningDocumentsInPlace, and downloads go to the app's Documents
   folder in typed subfolders. iOS shows it as:
       Files -> On My iPhone -> Biz Connect -> Images | Videos | Files
   Previously everything was written to CACHE (private, and iOS purges it whenever
   it likes) and pushed straight at the share sheet, so nothing was ever really
   "kept" by the app.

2. Manage storage (Settings -> Storage). Lists what this device has downloaded,
   grouped by type with per-group and total sizes; each row can be shared to the OS
   sheet (this is where "Save to Photos" now lives) or deleted. Plus Delete all.
   Deleting removes ONLY the local copy — the attachment stays on the server, so
   anything deleted can be downloaded again from the chat.

3. A downloaded video never downloads twice. Images and files have their own
   download link, but a video's tile IS the player, so it had no control at all and
   re-streamed on every play. It now carries a download button; once saved, the
   button becomes a tick and the tile plays from the local file — no network.

The index is treated as a cache of the filesystem, never as truth, because the user
can delete these from the Files app behind our back: every listing re-stats and
forgets what is gone, the library is reconciled at startup, and a local file that
has vanished by play time falls straight back to streaming instead of showing a
broken player.

Unit-checked the path allocator: collisions between different attachments with the
same filename resolve to "name (2)", re-downloading the SAME attachment reuses its
path, and path traversal / illegal characters are neutralised.

Note: the folder and the save location need a new iOS build to take effect. The web
side degrades cleanly — none of this UI appears outside the native app.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 15:29:29 +05:30
Sravan cc8f7d1eb8 feat(download): real % progress, and stream to disk instead of buffering
Uploads showed a bar + %; downloads showed nothing. On the native app that gap is
worse than on web, because there is no browser download UI behind it — the app
fetches the bytes itself, so a large video looked like a frozen tap.

- Adds the same chip an upload uses (name, bar, %) driven by Content-Length.
  Falls back to an indeterminate "…" when the server sends no length.
- Streams the response and appends to the file in 3-byte-aligned blocks rather
  than holding blob + base64 simultaneously. The old path peaked around 250 MB of
  memory for a 75 MB video, which is enough to get a WebView killed on a phone.
  Verified byte-exact against empty / 1 B / 2 B (base64 padding edges) / ragged
  chunk sizes / 27 MB, reassembling identical bytes every time.
- Older WebViews without streams keep the previous one-shot path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 12:18:50 +05:30
Sravan 310f37f29b fix(video): centre spinner never appeared on the one stall users actually see
Reported: "the loading buffer is not the spinner, it still loads at the left of
the timer." Correct — and it was our bug, not a cosmetic preference.

The spinner was driven by a hand-picked event list (waiting/seeking/stalled). But
a cold start from preload="none" NEVER fires `waiting`: it runs
loadstart -> loadedmetadata -> loadeddata -> canplay -> playing straight through.
Since the bandwidth fix, that cold start is the only stall left — so the spinner
sat out the exact moment it existed for, leaving just the OS control bar's own
small indicator where the play button sits, i.e. left of the timer.

Now the spinner is derived from the element's real state rather than guessed from
events: busy = seeking || (!paused && !ended && readyState < HAVE_FUTURE_DATA),
recomputed on every relevant media event. Simulated against the real event
sequences before shipping — cold start, mid-stream stall and seek all spin;
paused/ended/idle never do.

Also dim the frame to 72% brightness while buffering so the spinner reads
instantly against a bright poster, and give it a dark backing disc.

Note: the small indicator inside the native control bar belongs to the OS's own
video controls and cannot be suppressed while we use them. Ours is now the loud,
central one; removing the OS indicator entirely would mean custom controls.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 11:48:11 +05:30
Sravan 8a5409987c perf(video): stream a capped, faststart rendition instead of the raw upload
THE ANSWER to "why does an already-downloaded video still buffer?" — it was never
the download, and it was not the server. Probing the real uploads on the box:

  d0e49e58…  1920x1080  19.4 Mbps   75 MB / 31 s
  ad929d0b…  1920x1080  19.0 Mbps   27 MB / 11 s
  9f4e0865…   720x1584   3.6 Mbps   14 MB / 31 s

To play a 19 Mbps file the client has to SUSTAIN a 19 Mbps download for the whole
clip. No mobile link does, so the <video> buffer drains every few seconds: buffers,
plays, buffers, plays. Server-side disk read was instant and load was 1.7 on 20
cores throughout — the bottleneck is the media itself, not the delivery path.

Second, independent defect: phone MP4s store `moov` AFTER `mdat` (verified on two
uploads), so the player must fetch the file's tail before it can start at all.

Fix — keep the original bytes untouched (that is what the download button serves,
full quality) and build <id>.web.mp4 beside it: longest side capped at 1280,
~2.5 Mbps ceiling, +faststart. Measured on the 19 Mbps file:

  27.3 MB @ 19.0 Mbps  ->  2.55 MB @ 1.78 Mbps   (10.7x less bandwidth)
  transcode took 2.4 s for an 11.5 s clip

- server/media.js (new): probe, decide, 2-at-a-time background queue. Already
  light + correctly sized + faststart => no rendition at all. Light but wrong atom
  order => remux -c copy (seconds, no re-encode). Otherwise re-encode. A rendition
  that lands bigger than the original is discarded. MP4 box-walker for the
  faststart test is unit-checked against known fast/slow files, both directions.
- /stream/<id> serves the rendition, falling back to the original while it is still
  transcoding, so a video is never unplayable. /files/<id> is unchanged and still
  serves the pristine original for download.
- Renditions are queued at upload, and backfilled 15 s after boot for the videos
  that predate this. Range serving is now one shared helper for both routes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 10:49:04 +05:30
Sravan 2127397408 perf(video): cache attachment auth so Range playback stops stuttering; strict on-demand
Root cause of a downloaded/streaming video buffering repeatedly: every /files Range request
(a playing video fires dozens) re-ran the full attachment authorization, which scans the
messages table by attachment_id (un-indexed) — a per-chunk table scan = stutter. Now the
auth decision is cached per user+attachment for 60s (module-level, bounded), so range
requests after the first are ~free.

Also: preload='none' (nothing about a video downloads until the user taps play — only the
small poster loads), per 'no auto-download'. And the buffering spinner no longer hides on
canplay/loadeddata (they fire mid-buffer), so it reliably spins whenever it's buffering.
build batch159.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 22:27:37 +05:30
Sravan b7cd6df625 feat(video): clear center buffering spinner over in-chat videos
The native controls' buffering indicator sits by the timer and is easy to miss. Wrap the
<video> and overlay a centered spinner shown while it buffers (waiting/seeking/stalled ->
show; playing/canplay/seeked/loadeddata -> hide). Media events don't bubble, so the
listeners run in the capture phase; the overlay is pointer-events:none so it never blocks
the native controls. build batch158.
2026-07-22 22:16:35 +05:30
Sravan fd15628393 feat(video): server-generated poster thumbnails + HTTP Range streaming
- Dockerfile: add ffmpeg (Alpine).
- static.js: new /thumbs/<id> — ffmpeg extracts the first frame (0.5s), caches it next to
  the file, serves as the video poster (cosmetic; 404s gracefully if ffmpeg unavailable).
- static.js: /files now supports HTTP Range (206 Partial Content) + Accept-Ranges, which
  iOS requires to stream/seek video reliably (fixes the buffer-before-play / multi-tap);
  media (image/video/audio) now served inline, other files still download. Shared
  attachment auth refactored into one helper used by /files and /thumbs.
- home.html: video poster points at /thumbs/<id>. build batch157.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 22:09:32 +05:30
Sravan 92d41e6324 revert swipe-back to instant release; simplify in-chat video to native <video controls>
Swipe-back: the finger-following version is dropped (parked for the future) per request —
back to the reliable release-triggered swipe (rightward edge release runs bzcBack's slide).

Video: the custom download->play overlay caused layout 'dancing' on load and flaky
multi-tap playback. Replaced with a plain native <video controls playsinline preload=
metadata> (poster via #t=0.1) at a fixed box size — poster + OS play button, plays inline
on one tap, streams once and is cached (no re-downloads). build batch156.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 21:57:19 +05:30
Sravan 85a1b9d2ca fix(mobile): pull-refresh loader below the Dynamic Island; in-chat video player
Bug 1: .ptr-ind used top:8px so the pull-to-refresh spinner sat under the notch/Dynamic
Island. Now top:calc(var(--sat)+8px) clears the safe-area inset.

Bug 2: video attachments rendered as a plain download link that re-downloaded on every
tap. Server now sends isVideo/isAudio on message attachments; videos render as an in-chat
player — masked poster with a DOWNLOAD button that loads the file ONCE (preload=none ->
load on tap), then becomes a PLAY button; playing hands off to native inline controls, so
no repeat downloads. build batch155.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 21:48:09 +05:30
Sravan 3cc6ff4e54 feat(mobile): finger-following swipe-back (iOS-style), reusing the working close layout
The conversation pane now tracks your finger from the left edge and reveals the chat
list behind it, completing the back past ~35% width or springing back otherwise. Reuses
the existing body.chat-dragging layout (already defined, identical to chat-closing that
showWelcome uses): content z-index:2 at translateX(0), list .chatcol absolute behind at
z-index:0 — so the pane starts at the correct on-screen origin (the earlier attempt's
'one screen-width off' bug was a different setup). Vertical drags still scroll; popup/
search edge-release still closes via bzcBack. build batch154.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 21:22:58 +05:30
Sravan 200624bd24 chore: remove all temporary debug instrumentation
Investigations are closed, so strip the probes: bzDbg + __perfProbe definitions, the
older/render/slide/pwaFocus call sites, and the server-side /api/dbg (MDBG) sink. Kept
the functional code around each probe (renderThread's innerHTML build, the older-page
re-anchor, the slide fade). No behavior change. build batch153.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 20:46:54 +05:30
Sravan 2f368643ad fix(ios audio): stop dropping call audio on tap — never reconfigure session mid-call
Root cause of 'tapping stops the Bluetooth audio': bzUnlockAudio fires on EVERY tap
during a call and called bzApplyRoute -> setSpeaker(false) -> configureDevice, whose
setCategory+setActive(true) reconfigures the AVAudioSession mid-call and interrupts
WebKit's audio unit, dropping the call audio. Fix: bzApplyRoute on iOS no longer touches
the session at all (only wires the route-icon listener); iOS keeps auto-routing. build batch152.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 19:30:35 +05:30
Sravan 5cee67e974 feat(ios audio): final UX — auto-route + live indicator (no impossible toggle)
Telemetry confirmed the ceiling: a single speaker override holds ~1s over active BT then
WebKit reverts. So stop trying to control the route on iOS — always use the default port
(iOS auto-routes: BT/wired if connected, else loudspeaker), and make the button a live
INDICATOR of the real output; tapping shows a toast (connect/disconnect a headset to
change). Removes the temp nroute/sptap probes. Pure web change; plugin v1.1.2 already
supports it. build batch151.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 18:57:08 +05:30
Sravan 44526e1ee9 fix(ios audio): stop the speaker<->BT oscillation; single override, no re-force
v1.1.1's route observer re-forced speaker on every change, and WebKit re-added Bluetooth
each time -> the audio flapped speaker<->BT many times/sec (telemetry: dozens of route
flips from 3 taps), which read as 'sound doesn't switch'. WKWebView won't let the app
hold the built-in speaker over an active BT device. So: one override per tap, observer
only REPORTS the output (no fighting). Also stop dimming the iOS button (it's a live
output indicator, not on/off; the dim read as 'disabled' on BT). Probe now carries the
native marker so we can confirm the binary. plugin v1.1.2-stable, web batch150.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 11:54:42 +05:30
Sravan cfbf950173 fix(ios audio): force speaker over connected Bluetooth by dropping BT category options
overrideOutputAudioPort(.speaker) alone can't beat a connected BT headset (BT is higher
priority), so 'Speaker' snapped back to BT. Now setSpeaker(true) sets category options
[.defaultToSpeaker] (no allowBluetooth) so BT isn't an eligible output and the speaker
wins; setSpeaker(false) restores [.allowBluetooth,.allowBluetoothA2DP] and uses the
default port (routes to the headset). Observer re-holds speaker if a BT connect steals it.
Adds a TEMP web probe (nroute/sptap) to verify from telemetry. plugin v1.1.1, web batch149.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 11:01:06 +05:30
Sravan c3b0ef560d feat(ios audio): report real output route so the toggle icon is correct
BT audio already routes on iOS, but the web UI can't see it (iOS hides audio outputs
from enumerateDevices), so the icon was stuck on speaker. Plugin v1.1.0 now exposes the
active output: getRoute() + a 'routeChange' event ('speaker'|'bluetooth'|'wired'|
'receiver'|'airplay'). Web subscribes and drives the icon/label from the real route
(bluetooth/headphones/speaker), and the iOS toggle becomes a 2-state Speaker <-> Device
cycle (JS can't enumerate outputs there). Also strips the earpiece-investigation debug
logging from the plugin. Native needs one Codemagic build; web is live (batch148).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 23:43:07 +05:30
Sravan e9b9d3c121 feat(ios calls): drop unreachable earpiece from route toggle; Speaker <-> BT/headset
Proven via device telemetry: inside a WKWebView, WebKit owns the WebRTC audio unit and
forces the loudspeaker; overrideOutputAudioPort(.none) is a no-op (route settles on
Speaker 1.2s later), so the built-in earpiece cannot be selected. Present only what
actually works on iOS: Speaker, and Bluetooth/wired headset when connected. bzApplyRoute
now maps only 'speaker' to the loudspeaker override; bt/headset use the default port.
Coerce any stale 'earpiece' pref to speaker on iOS. Also strips the route debug telemetry.
Other platforms keep the earpiece option. build batch147.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 23:26:13 +05:30
Sravan 0282181ca6 diag(ios audio): settled-route probe (+0.4s/+1.2s) + live mode in route log
1.0.3 telemetry showed mode already == .voiceChat when earpiece still landed on
Speaker, and setSpeaker read the route synchronously (stale) right after the override.
So the mode re-pin alone may be insufficient and the sync read is unreliable.

1.0.5: keeps the .voiceChat re-pin, but stamps live mode into every route-change log
line and re-reads the SETTLED port+mode at +0.4s and +1.2s after each toggle (reported
in the next toggle's trail). This definitively answers whether WebKit flips to .videoChat
and where the route truly settles. native marker 1.0.5-settle.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 22:44:38 +05:30
Sravan b54ba10c69 fix(ios audio): pin .voiceChat before override(.none) so earpiece is reachable
Root cause (WebKit source MediaSessionManagerCocoa.mm + Apple DTS, confirmed by
telemetry): WKWebView's WebRTC re-pins the session to mode .videoChat while capture
is active, and .videoChat auto-implies .defaultToSpeaker. So override(.none) reverts
to the mode default = LOUDSPEAKER, and .none alone can never reach the earpiece once
WebKit flips the mode. Our first override won only because .voiceChat was still active.

Fix: for earpiece, setMode(.voiceChat) (its default route IS the receiver) before
override(.none) in both setSpeaker and the debounced route-change re-assert. Add an
accessory guard so a connected BT/wired headset isn't yanked to the built-in receiver.
Reconcile the launch patch: drop .defaultToSpeaker from inject-audio.js so it stops
contradicting the plugin. native marker 1.0.4-mode.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 22:31:14 +05:30
Sravan ce49e8e30d fix(ios audio): re-assert earpiece after WebKit re-forces speaker (debounced)
Telemetry proof: overrideOutputAudioPort(.none) routes to Receiver once, then every
later toggle latches to built-in Speaker despite opts=36 (no .defaultToSpeaker) —
WebKit's WebRTC engine re-forces the loudspeaker after our override. The prior build
ignored .override-reason route changes and never corrected it.

Now: react to ALL route changes, debounced 0.25s, and re-assert the chosen port only
on a genuine mismatch (self-terminating, capped at 6/toggle to avoid thrash). setSpeaker
returns a reason->port route-change trail so the log shows whether WebKit is one-shot
or persistent. native marker 1.0.3-reassert.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 22:20:29 +05:30
Sravan 36d51ba40d diag(ios audio): setSpeaker returns actual output port + category/mode + native marker
Telemetry only showed 'override didn't throw', and the web __BUILD tag can't tell
native binaries apart, so we couldn't see WHERE iOS actually routed the audio or
which plugin build ran. setSpeaker now resolves with the real currentRoute output
port (Receiver/Speaker/Bluetooth), the live AVAudioSession category/mode/options,
and a native-build marker (1.0.2-diag) so the route log is unambiguous.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 19:22:01 +05:30
Sravan 1920345ecd fix(ios audio): route earpiece reliably; stop fighting WebKit's audio session
Speaker worked but the earpiece was silent, and call audio flickered on speaker
then dropped. Causes: (1) the category set .defaultToSpeaker, so overrideOutputAudioPort(.none)
fell back to the loudspeaker instead of the receiver; (2) setSpeaker re-ran
setCategory+setActive on every toggle mid-call, tearing down the audio unit WebKit's
WebRTC engine was using and silencing the earpiece route.

Fix: drop .defaultToSpeaker (drive the port explicitly), make setSpeaker flip ONLY
overrideOutputAudioPort, and observe routeChangeNotification to re-assert the chosen
route when WebKit reconfigures the session at call start / device change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 09:10:09 +05:30
Sravan 8f33df5c3d fix(ios): rename podspec to AudioRoute.podspec so cap sync/pod install resolves it
Capacitor derives the pod name from the npm package name (audio-route -> AudioRoute)
and writes 'pod AudioRoute, :path => ../../plugins/audio-route' into the generated
Podfile. CocoaPods then requires a file literally named AudioRoute.podspec whose
s.name is 'AudioRoute'. The old AudioRoutePlugin.podspec (s.name AudioRoutePlugin)
caused the Codemagic build to fail with 'No podspec found for AudioRoute'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 21:15:56 +05:30
Sravan 804c218236 docs: preserve coturn/TURN setup notes (rescued from the removed prod-fix worktree) 2026-07-20 17:55:30 +05:30
Sravan 46b5ae16a4 speaker: force-add audio-route plugin dist stubs (global dist/ ignore would drop them from a fresh clone) 2026-07-20 17:07:01 +05:30
Sravan c6f236ecf9 speaker: make AudioRoute a real Capacitor plugin PACKAGE so it registers (device log: has:0)
Device telemetry proved the app-embedded AudioRoute class never registered (not in
Capacitor.Plugins) — appending a CAPBridgedPlugin to AppDelegate.swift gets stripped/undiscovered
in release builds. The plugins that DO register (Share, Camera, Filesystem) are all npm packages
wired by cap sync. So AudioRoute is now a local plugin package (mobile/plugins/audio-route,
file: dep in mobile/package.json) with a podspec + CAPBridgedPlugin Swift — cap sync adds its pod
and Capacitor registers it like the others. load() sets the launch speaker default; setSpeaker({on})
overrides the output port. inject-audio.js no longer injects the plugin class (would duplicate);
it keeps only the AppDelegate launch default as a fallback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 17:06:16 +05:30
Sravan a574816eaa debug: instrument bzApplyRoute to see if native AudioRoute plugin registered + setSpeaker result (batch146) 2026-07-20 16:43:39 +05:30
Sravan 5960efb612 uploads: support up to 1 GB attachments, streamed to disk (was 25 MB, buffered in memory) (batch145)
- Server streams the upload body straight to /data/uploads (a .part temp file, atomic rename on
  success), backpressure-aware, so a 1 GB file never buffers in RAM. MAX_UPLOAD_MB env (default
  1024 = 1 GB) controls the cap; error message reflects it.
- Client size guard raised 25 MB -> 1 GB.
- docker-compose documents MAX_UPLOAD_MB and the required Nginx Proxy Manager client_max_body_size.
NOTE: the actual bottleneck for the user's 9.7 MB reject is almost certainly NPM's client_max_body_size
(nginx default 1 MB) — that must be raised in the NPM admin; the app change alone can't lift it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 16:06:19 +05:30
Sravan 90d49d29d0 speaker: native AudioRoute plugin for real earpiece<->speaker toggle on iOS (batch144)
- ios-patch.sh now injects an AudioRoutePlugin (CAPBridgedPlugin, Capacitor 7 auto-registers it)
  into AppDelegate.swift with setSpeaker({on}) -> AVAudioSession.overrideOutputAudioPort. Tolerant/
  build-safe: if it doesn't register, the web call just no-ops (can't crash or fail the build).
- web: nativeAudioRoute()/bzApplyRoute() drive the plugin; toggleSpeakerphone + the on-join/on-tap
  unlock now actually switch the route on iOS (setSinkId can't). canRouteAudio() shows the toggle
  when the native plugin is present. Dormant until the next Codemagic build ships the plugin.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 00:31:25 +05:30
Sravan 9c2ba847b0 meeting: unlock iOS media playback on Join so remote call audio isn't silent until you mute/unmute (batch143) 2026-07-20 00:08:25 +05:30
Sravan 4e78448743 mobile: revert finger-following swipe-back to the working release-based version (interactive one had an undiagnosable-blind layout offset) (batch142) 2026-07-20 00:01:33 +05:30
Sravan fed0e07e3e mobile: swipe-back easier completion threshold (25%) + readback telemetry to confirm conversation actually translates (batch141) 2026-07-19 23:41:13 +05:30
Sravan 9c731f087e mobile: iOS PWA keyboard — pin app to visual viewport + undo webview scroll so header stays; swipe-back telemetry (batch140) 2026-07-19 23:17:13 +05:30
Sravan 578f3a2921 mobile: interactive-widget=resizes-content so the keyboard resizes the layout instead of panning the viewport (header no longer pushed off) (batch139) 2026-07-19 23:00:43 +05:30
Sravan f178e271c8 debug: capture PWA composer-focus viewport state (scale/scroll/font) to diagnose the zoom (batch138) 2026-07-19 22:53:28 +05:30
Sravan 8aa2532666 mobile: interactive finger-following swipe-back to go from a conversation to the list (batch137)
Drag the open conversation rightward from the left edge and it follows the finger 1:1 with the
list parallaxing in underneath; release past ~35% (or a quick flick) completes the pop, else it
snaps back. Fixes the old stuck-pane bug: once a clear horizontal drag is detected we
preventDefault (passive:false) to CLAIM the gesture so iOS/scroll can't steal it and fire
touchcancel; touchcancel always resolves to a clean state. showWelcome(skipAnim) does the state
swap without re-animating. Works in native app, PWA and mobile browser.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 22:50:10 +05:30
Sravan 40789b06cf mobile: composer font-size 16px UNCONDITIONALLY to stop iOS/PWA focus-zoom on any viewport (batch136) 2026-07-19 18:57:45 +05:30
Sravan 134cb8999d ios: default in-call audio to the loudspeaker (AVAudioSession) at build time
Calls were routing to the quiet earpiece. ios-patch.sh now runs a Node helper (Node 20 is
already in the build env) that injects an AVAudioSession .playAndRecord/.voiceChat category with
.defaultToSpeaker + Bluetooth into the generated AppDelegate. Tolerant: exits 0 and no-ops if the
template differs, so it can never fail the Codemagic build. Verified locally against the Cap 7
AppDelegate template — injects correctly and is idempotent. First pass; if WebRTC re-grabs the
session mid-call on device, a follow-up plugin will re-assert .overrideOutputAudioPort(.speaker).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 16:18:52 +05:30
Sravan f2b965bd3d desktop v0.1.20 + web: notify on download complete (was silent) (batch135)
Suppressing the save dialog made downloads completely silent — "nothing happened" even though
the file saved to Downloads. Now on download 'done': (1) tell the web UI → branded toast
"Saved X to your Downloads folder" when the window is focused; (2) native OS notification
(click → reveal in Explorer) when the app is minimized/in the tray, so it's never double-noticed;
(3) a failure notice. preload exposes onDownloadDone; home.html shows the toast.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 16:03:24 +05:30
Sravan 30eaf37773 desktop: v0.1.19 — reliable auto-update for close-to-tray users
The app closes to tray, so it kept running on the old version and only checked on a fresh launch.
Now: (1) check for updates on EVERY window show (X-to-tray then reopen, taskbar, relaunch via
second-instance) via win.on('show'), throttled 1/10min; (2) explicit autoInstallOnAppQuit=true so
a downloaded update installs on the next real quit / PC restart even if the user never clicks
"Restart now"; (3) native notification when an update finishes downloading while hidden in the
tray. The existing 6-hour background timer is unchanged and still runs regardless of window state.
Also carries the 0.1.18 downloads-to-Downloads-folder change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 15:38:01 +05:30
Sravan 3f44e2b285 desktop: v0.1.18 — downloads save to Downloads folder with no dialog 2026-07-19 11:42:38 +05:30
Sravan d098ba468e docs: revert stray whitespace in IOS_SETUP.md 2026-07-19 11:36:42 +05:30
Sravan 9f3e8b83c7 mobile: hide iOS keyboard accessory bar + composer-anchored attach menu (batch134)
- Accessory bar: call Keyboard.setAccessoryBarVisible({isVisible:false}) on iOS in the native
  IIFE, hiding the grey chevrons+Done strip above the keyboard. The plugin is already bundled
  in the current TestFlight build, so this takes effect on a web deploy — no rebuild.
- Attach: tapping the paperclip now opens a composer-anchored Photos/Camera/Document menu
  (like the emoji/mention popups) instead of firing the generic mid-screen OS chooser as the
  first thing. Each option opens a type-scoped picker (image/*, capture). Web fix, all clients.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 11:35:59 +05:30
Sravan a7f954ae44 mobile: Enter=newline on mobile, hide preview zoom buttons; desktop: downloads to Downloads folder (batch133)
- Mobile: the Return key now inserts a newline instead of sending (send via the button, like
  every native chat app). Desktop keeps Enter=send / Shift+Enter=newline.
- Image preview: hide the on-screen +/- zoom buttons on mobile (pinch-to-zoom covers it).
- Desktop (Electron): a will-download handler saves straight to the OS Downloads folder with no
  "where to save?" dialog, de-duping the name if it exists. NOTE: desktop code only — NOT
  published to the update feed (needs an explicit desktop rebuild/publish).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 10:38:36 +05:30
Sravan c32584df54 mobile: fix zoom + notch on the non-home pages (dashboard/index/connect/share/host)
The mobile viewport fixes only ever went into home.html. The other standalone pages still had
the old viewport, so in the native app they auto-zoom on input focus and (dashboard/host) run
under the notch/Dynamic Island. Bring every page's viewport to match home.html
(maximum-scale=1, user-scalable=no, viewport-fit=cover) and add safe-area top padding to the
dashboard header and the host body/indicator so nothing sits under the island now that the
viewport is cover. index/connect/share already pad for safe-area; they only needed maximum-scale.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 08:39:50 +05:30
Sravan 3a7a026533 mobile PWA: fix keyboard zoom (16px inputs) + composer lift via VisualViewport (batch132)
iOS home-screen PWAs IGNORE viewport maximum-scale (Apple disabled it for accessibility), so
the maximum-scale=1 that stops auto-zoom in the Capacitor WebView does nothing in the PWA — it
still zooms on input focus. Real cross-platform fix: make every focusable text field 16px on
mobile (the composer was .92rem). autoGrow's empty-guard keeps it one line.

Also the PWA has no Capacitor Keyboard plugin, so the composer never lifted above the keyboard
("not the same keyboard"). Added a VisualViewport-based lift for non-native clients (browser +
PWA); native still uses the plugin. >100px threshold ignores the Safari toolbar.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 08:31:32 +05:30
Sravan 150a074578 mobile: stop the open-pin schedule the instant the user scrolls (batch131)
Bug: for ~3.4s after opening a chat, the "keep newest in view as images load" pin schedule
would yank you back to the bottom if you tried to scroll up for older history — so scrolling
up snapped back to latest, and only worked once the schedule expired (~5s). Fix: the user's
first scroll gesture now sets _openScrolled, which cancels the pending pin timers and short-
circuits _pinNewest (so the late image-load pins stop too). loadOlder/anchor then works
immediately, no yank.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 08:21:34 +05:30
Sravan 2a60c01268 mobile: apply network content DURING the fade, not at landing (batch130)
Device log showed the slide motion itself is now clean 60fps (frames 0-15 all ~16ms in every
sample); the only remaining spike was at frame ~16 — AFTER the slide lands — from applying the
network thread result + pin at that instant (the "adjusts after it lands" feel). Since the open
is a compositor opacity/transform fade, main-thread work during it doesn't stall the animation
and is masked by the low opacity. So apply the reconcile/render + pins immediately when the
fetch returns (mid-fade) instead of deferring to slide-end. By the time the pane is fully opaque
the content is already settled. Removed the now-obsolete appendBubble mid-slide deferral.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 07:32:21 +05:30
Sravan 9bb74cffd2 mobile: real slide-in + fade on open, list column untouched = zero reflow (batch129)
The reflow that caused the end-of-slide hitch was never the content slide itself — it was
SHOWING the list column during the slide and hiding it (display:flex->none) at the end. So
keep .chatcol display:none the whole time (untouched) and animate ONLY .content: it pushes in
from translateX(12%)->0 with an opacity fade, on its already-promoted GPU layer. Real slide
motion, and nothing to reflow when it ends. (This also explains the batch126 breakage: that
made .chatcol position:absolute, disturbing the touch/layout target — not touched here.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 06:57:48 +05:30
Sravan 9c703d6e64 mobile: chat open = instant + quick opacity fade (no slide) (batch128)
User chose the fade over chasing the WebView slide-teardown reflow. Open now: the cache-
rendered conversation is placed instantly and fades opacity 0->1 over 140ms. No transform,
no off-screen pane, no list-column display toggle -> nothing to reflow at the end, so the
~40ms end-of-slide settle cannot occur. Same afterOpenSlide queue flushes network reconcile/
pins/appends at fade-end. Desktop unaffected (fade is mobile-only via __freshOpen).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 06:51:38 +05:30
Sravan 9eb4a99679 mobile: revert chatcol absolute-behind — it broke chat opening (batch127)
The list-column position:absolute change stopped conversations from opening. Revert to the
known-good display:none. Keep the other batch124-125 fixes (content promoted, reconcile,
reopen-at-latest, download interceptor). Slide back to the batch125 behaviour (opens fine,
minor end hitch) while I find a safe way to remove the reflow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 06:35:45 +05:30
Sravan 82d0154313 mobile: kill the real slide hitch — stop reflowing the list column at slide-end (batch126)
Device log proved the residual 30-78ms end-of-slide hitch is NOT the content-layer demote
(content stays promoted) and NOT the re-render (reconcile, longtasks:[]). It's the chat-list
column flipping display:flex->none at transitionend, which reflows that whole subtree. Keep
the list RENDERED behind the conversation (position:absolute; z-index:0; covered by the opaque
content pane) instead of toggling display. Teardown now only clears transforms = no reflow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 01:04:40 +05:30
Sravan ea04556596 mobile: definitive slide fix (zero teardown) + real native download + reconcile (batch125)
Slide: the residual ~40ms end-of-slide hitch (down from 128ms in b124) was the layer
DEMOTE + the deferred full renderThread at transitionend. Two fixes:
- Keep .content promoted for the WHOLE time a chat is open (will-change lives on
  body.chat-open, not on the animating class). The open transition now only changes the
  transform VALUE 100%->0; when it ends there is nothing to tear down -> no demote raster.
- Slide-end no longer rebuilds all 40 nodes: reconcileOpen() appends only the 0-2 genuinely
  new tail messages (full renderThread only if the page structure diverged).

Download: routing to Safari failed auth (no login cookie). Real fix: fetch the file in the
WebView (cookie present) and hand the bytes to the OS save/share sheet via Filesystem+Share
(added to mobile deps; ships next TestFlight build). Until then, images fall back to the iOS
long-press "Save to Photos" instead of breaking the app.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 00:48:34 +05:30
Sravan 91b3e5c522 mobile: kill slide end-hitch (compositor teardown), fix reopen-at-latest + native download hang (batch124)
Slide: the 40-128ms hitch was a compositor RE-RASTER at transitionend, not JS
(longtasks:[], renderMs 2-6ms in the device log). Removed contain:layout paint /
isolation:isolate from the .content slide layer and the filter:brightness parallax
on .chatcol (both force a full re-raster on teardown); defer the layer demotion two
frames past transitionend so it lands off the motion path. Also replaced the fragile
length+lastId slide-end skip (it almost never held once a live message grew the cache,
so the full innerHTML rebuild kept running at slide-end) with an exact per-message diff.

Reopen-at-latest: loadOlder wrote the GROWN thread (100+ msgs) into THREAD_CACHE, so
re-opening re-rendered all of it and stranded you mid-history as images shifted the
(pre-load) bottom past the 1200px pin guard. Open now renders the latest PAGE only;
added _forcePinOpen to glue to the newest through late image loads until the user scrolls.

Download hang: <a download> navigated the whole WKWebView away to the raw file (no back,
app frozen). Native-only capture-phase interceptor opens downloads in the system browser.
Lightbox close/download buttons: solid dark chips so they're visible over bright images.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 00:31:57 +05:30
Sravan 433703cfeb perf(mobile): skip redundant end-of-slide re-render (unchanged content) + load-older before rubber-band
Device log: slide is 60fps EXCEPT one ~60-130ms hitch at the END = the deferred renderThread rebuilding
the (identical) DOM at slide end. Skip it when the network result matches the cache render (signature).
Load-older: fired at scrollTop<120 = during the rubber-band over-scroll past the top (beforeScrollTop
was -289), so the prepend+anchor jerked momentum. Trigger earlier (<700, skip negative scrollTop) so it
loads while still scrolling and never interrupts the bounce.
Build marker -> 2026-07-19-batch123.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 00:10:27 +05:30
Sravan a4600f6b5f fix(mobile): close the debug <script> block (batch122 left it open, breaking the keyboard block)
The perf-diagnostics script tag was never closed, so it merged with the following native/keyboard
<script> and threw 'Unexpected token <', disabling the keyboard/safe-area init. Add the missing </script>.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 00:02:48 +05:30
Sravan d02d8976d3 diag(mobile): instrument slide frame-timing + render cost + load-older scroll to find the real jank
Re-add /api/dbg + a frame-gap/long-task probe over the chat-open slide, the innerHTML render time, and
before/after scroll for load-older — to measure on-device where the jank actually is (main-thread block
vs compositor) instead of guessing. Temporary; removed once fixed.
Build marker -> 2026-07-19-batch122.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 00:00:28 +05:30
Sravan 529bc26cb5 perf(mobile): compositor 'render-then-arm' chat-open slide + robust load-older anchor; remove diagnostics
Slide (workflow-verified): the jump was the main thread building the message DOM + scroll writes DURING
the 300ms animation. Now: render off-screen first, then arm a transform-only slide on a promoted GPU
layer (translate3d/contain:layout paint) with all innerHTML/scrollTop work deferred to transitionend
(afterOpenSlide queue). armOpenSlide runs after the sync render; appendBubble defers live writes mid-slide.
Load-older jump: anchor on the specific oldest-loaded message element (not scrollHeight math, which broke
when prepended images loaded and shifted content) and re-anchor as those images load.
Removed all /api/dbg diagnostics (client reporter + server route + spike/diag probes).
Build marker -> 2026-07-18-batch121.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 23:49:38 +05:30
Sravan f3c3e08be4 perf(mobile): paginate threads to 40 (was 500) — kills the heavy-DOM jank at the source
User's insight: the jank/jumps come from rendering ALL ~500 messages on open. Load only the latest 40
(server + client PAGE), and the existing loadOlder() pages in older history on scroll-up with a scroll
anchor (no jump). Whole-thread SEARCH is a separate endpoint, unaffected. Also #1: keyboard-show only
pins to newest when already near the bottom, so replying to an OLD message no longer yanks to latest.
Build marker -> 2026-07-18-batch120.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 23:31:05 +05:30
Sravan 2bd8b3c8c1 fix(mobile): image pager direction + end-arrows; reset --kb on composer blur
- Pager: force the staged (opposite-edge) frame to PAINT (void offsetWidth) before animating in, so the
  incoming image enters from the correct side (was appearing from the exit side). Hide prev-arrow at the
  first image and next-arrow at the last.
- #1: keyboard closed after reply-cancel but the --kb lift stayed (empty gap). Add keyboardDidHide reset +
  a composer-blur fallback that drops --kb when focus leaves the composer.
Build marker -> 2026-07-18-batch119.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 23:11:05 +05:30
Sravan da3d44cbb7 fix(mobile): clamp reply-quote (balloon), clip swipe-reply overflow, animated image pager
- Reply quote: was showing the FULL quoted body untruncated -> DIV.quote rendered 1571px, ballooning the
  bubble + leaving the chat not-at-bottom. Clamp to 2 lines (-webkit-line-clamp) + collapse newlines.
- Swipe-to-reply: translateX(+72px) on a right-edge bubble pushed past the viewport -> a horizontal scroll
  bar. .convo-msgs overflow-x:clip stops it.
- Image pager (#8): replace instant src swap with a real slide — current image slides out, next slides in
  from the opposite side; clamp at first/last (no wrap -> no blank slide past the end).
Build marker -> 2026-07-18-batch118.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 22:32:10 +05:30
Sravan 1f5b4bd42c fix(mobile): stop bubble/composer balloon + transition pop (shared root cause, workflow-verified)
Parallel root-cause analysis: during body.chat-opening the pane is momentarily ~0 width; word-break:
break-word / overflow-wrap:anywhere let bubbles collapse to 1-GLYPH min-content, so pre-wrap text wraps
into hundreds of lines (5684px 'balloon'); same inflates the empty/draft textarea (autoGrow->140=4 lines);
and translateX(100%) of a ~0-width pane = no travel = the 'jump'. The tall box hid in anonymous line
boxes (renderMsgBody emits bare text nodes), which is why the probe only saw the 84px timestamp span.
Fixes (all @media max-width:760px / chat-opening scoped, desktop untouched):
 1. .bubble: word-break:normal + overflow-wrap:break-word (min-content = longest word, never collapses)
 2. mobile bubble group: overflow-wrap:anywhere -> break-word
 3. .msg-link: word-break:break-word -> overflow-wrap:break-word (URL-only msgs can't reopen the hole)
 4. body.chat-opening .content: width:100vw -> definite width, no collapse frame, real slide travel
Build marker -> 2026-07-18-batch117.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 18:53:38 +05:30
Sravan 898d389dfe diag(mobile): probe composer measurements + transition animation + tall-bubble content
tallImg was no-img, so the balloon is a TEXT bubble stretching (even in a 17-msg chat). Add: composer/
textarea height+scrollHeight+rows+value+fontSize+lineHeight (why ~4 lines), whether chat-opening class +
.content animationName are applied (why transition jumps), and the tall bubble's text + tallest child.
Build marker -> 2026-07-18-batch116.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 17:59:58 +05:30
Sravan 7f7ff8ba1f fix(mobile): cap in-bubble image height (kills the stretch balloon) + sharper spike diagnostic
Spike log showed bubbles ballooning to 3576-5684px (an image loading at natural ~2778px height before
constraint). att-img is capped 240 but some image path wasn't — added .convo-msgs img/.bubble img
max-height:340px as a blanket cap so no message can stretch the thread. Enhanced spike report to name
the tall bubble's img (natural size, rendered height, computed max-height) to confirm.
Build marker -> 2026-07-18-batch115.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 17:34:31 +05:30
Sravan 676612a12b fix(mobile): disable zoom via viewport meta (not font-size) + reveal msgs during slide
- Revert font-size:16px !important (it made the composer ~4 lines tall). Disable iOS zoom with
  viewport maximum-scale=1,user-scalable=no instead -> composer keeps its size, AND double-tap-to-zoom
  (in-chat search arrows #3) is gone. touch-action:manipulation on controls as belt-and-suspenders.
  Custom lightbox pinch still works (it's transform-based, not browser zoom).
- Transition: show the newest message immediately (was hidden until images loaded -> empty pane slid in
  then popped = the 'jumping' feel). Pinning still prevents dance.
Build marker -> 2026-07-18-batch114.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 17:27:54 +05:30
Sravan 78ea36f7d0 polish(mobile): native-style parallax chat-open transition; diagnose scrollH balloon
- Transition: open now slides the whole .content pane in over the list with a subtle parallax + iOS
  easing (was an instant/panel-only slide). Close/back already parallax.
- scrollH blip: added a spike watcher that reports the tallest element (class + img src tail) when the
  thread's per-message height balloons, so we can see what stretches then settles.
Build marker -> 2026-07-18-batch113.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 17:13:39 +05:30
Sravan 2cadf90bc8 fix(mobile): lift composer by Capacitor Keyboard plugin height (resize:none, vv doesn't reflect kbd)
Device log (post-zoom-fix): keyboard open leaves clientHeight AND visualViewport at 926 -> vv gives 0 ->
composer covered. On resize:none the plugin's keyboardHeight is the only signal; now that zoom is gone
it's clean, so --kb = keyboardHeight lifts the composer flush, and keyboardWillShow at animation start +
the CSS bottom-transition makes it slide up WITH the keyboard (smooth). Config pinned to resize:none.
Build marker -> 2026-07-18-batch112.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 16:46:00 +05:30
Sravan 9f7561bf8b diag+fix(mobile): capture keyboard-open composer position; replay open slide transition
- Debug now reports curKb/compBottom/kbTop/coveredBy on keyboard events so I can see WHY the composer is
  covered (lift coming out 0) from the server log.
- Transition: force the bzConvoIn slide to replay on every chat open (CSS animation only auto-plays on a
  class change, so chat->chat looked instant). Restart via reflow + inline animation.
Build marker -> 2026-07-18-batch111.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 16:23:22 +05:30
Sravan bf8df593a1 fix(mobile): force input font-size 16px with !important (was overridden by .composer-row .92rem)
Device log confirmed zoom persisted (vvW:394,vvTop:74) because .composer-row textarea{font-size:.92rem}
out-specified the generic rule, keeping the composer <16px -> iOS still zoomed on focus. !important
forces 16px on all fields so the zoom never fires. (#7 latest + budge already verified fixed.)
Build marker -> 2026-07-18-batch110.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 15:58:41 +05:30
Sravan 0e38bd9229 fix(mobile): stop iOS input auto-zoom (font-size 16px) = real keyboard fix; robust pin-to-newest
Device log revealed the truth:
- Keyboard: focusing the <16px composer made iOS ZOOM the page (vvW 428->394, vvTop->74), scrambling
  every viewport/keyboard calc. Set all form fields to 16px on mobile -> no zoom -> keyboard math holds.
- Latest messages: on a 500-msg chat atBottom was false because late images grow the thread after the
  initial scroll. Now re-pin on a schedule + on each image load while near the bottom.
- Budge already gone (device reported ovf:false).
Build marker -> 2026-07-18-batch109.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 14:17:20 +05:30
Sravan f9d6472f77 chore(mobile): add /api/dbg diagnostics sink + client reporter (build, overflow, viewport, scroll)
Temporary: the app POSTs its real runtime state to the server log so device-only bugs (budge source,
keyboard viewport numbers, chat-open scroll state) can be diagnosed from docker logs instead of
screenshots. Removed once mobile issues settle.
Build marker -> 2026-07-18-batch108.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 13:18:58 +05:30
Sravan 720b1f0c40 fix(mobile): revert keyboard to live VisualViewport tracking (no timer), undo budge; add unit test
- Keyboard: the 60ms timer in batch106 sampled the viewport MID-animation (clientHeight/visualViewport
  temporarily inconsistent) and over-lifted -> gap. Reverted to reading clientHeight-visualViewport LIVE
  on every vv resize, which is correct and self-adapting (unit test: residual=46 flush on the device).
- Budge: reverted the file <input> back to display:none (the position:fixed;left:50% hack overflowed
  the viewport horizontally).
- Config back to resize:native to match the installed build (works, no rebuild).
- Added test/keyboard-lift.test.js (5/5 pass) verifying the lift math against real device numbers.
Build marker -> 2026-07-18-batch107.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 10:22:45 +05:30
Sravan 6e3cf95deb fix(mobile): mode-adaptive smooth keyboard + force-latest-scroll + bottom-anchored file input
- Keyboard: auto-detect resize mode. resize:none -> lift full keyboard height at willShow so the CSS
  transition slides the composer up WITH the keyboard (smooth, no iOS resize lag). resize:native ->
  residual only. Config set to resize:none for the smooth path (needs build); web stays correct on the
  current resize:native build meanwhile.
- #7: force scroll-to-bottom at 0/120/320/600ms on open so a chat always opens on the newest message.
- File picker: anchor the file <input> to a fixed bottom spot (was display:none -> iOS dropped the menu
  mid-screen); now it comes up as a bottom sheet even as the composer moves.
Build marker -> 2026-07-18-batch106.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 08:32:23 +05:30
Sravan c775ca2740 fix(mobile): lock in device-independent keyboard (VisualViewport residual), remove debug
Debug confirmed resize:native shrinks the WebView by the keyboard height, so the composer only needs the
residual lift = clientHeight - visualViewport.height (46px on the test device — the prediction-bar sliver).
Tracked live via VisualViewport so it follows the keyboard. Zero per-device constants. Removed debug bar;
reverted Keyboard config to resize:native (which the logic relies on).
Build marker -> 2026-07-18-batch105.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 08:11:39 +05:30
Sravan 8867d0abfc fix(mobile): keyboard via VisualViewport (device-independent) + temp debug readout
Replace the hardcoded factor with the real overlap = clientHeight - visualViewport.height (works on any
screen). Adds a temporary on-screen debug line to confirm which signal the device reports, so the final
logic needs no per-device tuning. Debug removed once confirmed.
Build marker -> 2026-07-18-batch104.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 01:25:10 +05:30
Sravan c5489d7ad6 fix(mobile): scale keyboard lift by measured 0.52 (plugin over-reports ~2x)
Measured from device screenshot: composer at ~678pt from bottom vs 351pt keyboard = 2x overshoot.
Scale the reported height by 0.52 so the composer sits flush on the keyboard. Single tunable const.
Build marker -> 2026-07-18-batch103.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 01:19:49 +05:30
Sravan 77a3ad455f fix(mobile): normalize keyboard height device-px -> points (was overshooting ~3x on 3x screens)
Root cause: the Keyboard plugin reports keyboardHeight in device pixels on this build; CSS needs points,
so the raw value overshot by the devicePixelRatio. Divide by DPR when the raw value exceeds the screen's
point height. Web-only.
Build marker -> 2026-07-18-batch102.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 01:13:57 +05:30
Sravan 233db2c140 fix(mobile): keyboard lift via VisualViewport (measured gap, exact) not plugin height
The Keyboard plugin's reported height overshot. With resize:none the WebView stays full-size, so
window.innerHeight - visualViewport.height is the EXACT keyboard overlap -> composer lands on the
keyboard. Web-only, works on the resize:none build already installed.
Build marker -> 2026-07-18-batch101.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 01:05:12 +05:30
Sravan 357f0168ba fix(mobile): keyboard resize:none + web-tunable JS lift (deterministic, no plugin fight)
resize:native gave contradictory results (covered vs header) because the safe-area plugin fights it.
Set resize:none so the native layer does nothing, and lift the composer purely in JS by keyboardHeight
* KB_LIFT. Once resize:none is built, the lift is web-tunable with zero further builds.
Build marker -> 2026-07-18-batch100.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 00:55:17 +05:30
Sravan 9bee2c635c fix(mobile): remove redundant --kb lift; keyboard uses resize:native alone (was double-lifting to header)
Isolated test showed 'too high' = resize:native already lifts the composer, so the JS --kb added a
second lift up to the header. Removed it. resize:native is the single mover now.
Build marker -> 2026-07-18-batch99.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 00:50:18 +05:30
Sravan f55af18e90 fix(mobile): deterministic keyboard lift via --kb (single mover, no rebuild needed)
batch92 proved resize:native is a no-op with the safe-area plugin, and batch97 turned off the
safe-area keyboard offset, so re-adding the JS --kb lift makes it the ONLY thing moving the composer
= it sits exactly on the keyboard. Works on the current installed build (web-only).
Build marker -> 2026-07-18-batch98.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 00:45:06 +05:30
Sravan cc2a76450f fix(mobile): native keyboard (remove JS hack), open at latest + no double-render dance, splash cfg
- #3 keyboard: the overshoot proved resize:native DOES lift the composer; my --kb JS was a second lift.
  Removed the JS hack entirely; keyboard is now purely @capacitor/keyboard resize:native. Config: turn
  OFF safe-area offsetForKeyboardInsetBug so only one mechanism moves the view (needs the build).
- #7: gate the open-time hide/reveal with _convoRevealed so the cache->network double render doesn't
  flash/dance; on mobile open at the LATEST message (skip auto-scroll to first-unread).
- #6: add SplashScreen config (bg #16294F, no spinner) — asset gen already produces the logo.
Build marker -> 2026-07-18-batch97.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 00:17:58 +05:30
Sravan 763b2996d1 fix(mobile): revert app-breaking interactive edge-back (iOS touchcancel left UI stuck)
The finger-follow edge gesture starting at the very left edge collided with iOS's own edge-swipe,
which fires touchcancel instead of touchend, so cleanup never ran and .content stayed transformed +
chat-dragging stuck on top -> bottom nav hidden and all clicks blocked. Back to the safe release-based
swipe (still gets showWelcome's parallax slide). Keyboard --kb inset, #7 no-dance, #8 image swipe kept.
Build marker -> 2026-07-17-batch96.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 23:58:42 +05:30
Sravan 3393e44691 fix(mobile): JS-driven keyboard inset, interactive edge-back, finger-follow image swipe, no-dance
- #3 keyboard (was B: chat didn't move, keyboard covered composer): native resize wasn't moving our
  fixed layout, so drive it from JS — the Keyboard plugin reports its height, we expose --kb and lift the
  composer to sit exactly on the keyboard; keyboard config -> resize:none so native won't double-adjust.
- #4: the left-edge back is now INTERACTIVE — the conversation follows the finger with the list revealed
  underneath (parallax), commit past 1/3 width else spring back (like Teams). Falls back to release-based
  bzcBack for popups/search.
- #8: the image now follows the finger sideways (and down) during the swipe, not just on release.
- #7: hold the thread hidden until its images load (max 700ms) then reveal at the bottom — no dance.
Build marker -> 2026-07-17-batch95.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 23:11:54 +05:30
Sravan f2e2e8b08a fix(mobile): parallax slide-back, swipe images left/right, glue thread while images load
- #4: on back, reveal the chat list UNDERNEATH with a parallax slide-in while the conversation slides
  off to the right (slide the whole .content, list forced visible beneath) — matches the Teams push/pop.
- #8: swipe left/right in the image viewer flips to the prev/next image (not just swipe-down to close).
- #7: re-pin to the bottom as each image finishes loading (when near bottom), so late images don't
  reflow/'dance' the thread.
Build marker -> 2026-07-17-batch94.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 22:07:42 +05:30
Sravan e29810ea2a fix(mobile): un-clip popups, swipe-to-reply, swipe-down-close image, no msg dance, slide-back
Addresses reported iOS observations (web-side, no rebuild):
- #1: the overflow-x:hidden I added to stop sideways-scroll was clipping the profile/bell popup menus;
  now only the chat-list scroller is clipped and long content wraps instead of widening the page.
- #9: swipe a message bubble right to reply (WhatsApp/Teams style).
- #8: swipe an opened image down to dismiss the lightbox.
- #7: hide the thread for one frame on open so messages don't visibly scroll/'dance' into place.
- #4: slide the outgoing conversation off-screen on back (inline transform, reliable across WebKit).
Build marker -> 2026-07-17-batch93.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 21:34:15 +05:30
Sravan 13b0f910ab ci(ios): set CFBundleVersion to Codemagic BUILD_NUMBER so each upload is unique
App Store Connect rejected the upload: 'The bundle version must be higher than the
previously uploaded version: 1'. Capacitor defaults CFBundleVersion to 1, so every
build collided with the first upload. Patch it to the monotonic BUILD_NUMBER.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 20:09:51 +05:30
Sravan 2ce7ec72fb fix(ios): PERMANENT native safe-area + keyboard via Capacitor 7 + safe-area plugin
Device screenshots proved the WebView reports env(safe-area-inset-*)=0, so no web/CSS/JS trick can
move content off the Dynamic Island — it must be fixed natively. Upgrade the Capacitor shell to v7 and
add @capacitor-community/safe-area (populates env() with real per-device insets, edge-to-edge) and
@capacitor/keyboard (resize:native so the composer sits directly on the keyboard, like Teams).

- mobile: Capacitor 6 -> 7 for all plugins; add safe-area + keyboard; SafeArea/Keyboard config.
- codemagic: npm ci -> npm install (dependency set changed); drop stale Cap6 lockfile.
- web: remove the temporary StatusBar/34px hacks (env() now works); keep var(--sat)/var(--sab) padding.
- share/connect: back link now respects env(safe-area-inset-top/left).
- add native-style slide in/out (push/pop) animation when opening/closing a chat on mobile.
Build marker -> 2026-07-17-batch92.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 17:36:14 +05:30
Sravan a609bfd2e0 fix(ios): status-bar inset via StatusBar plugin, hide nav in open chat, bulletproof h-scroll
Root cause from device screenshots: the iOS Capacitor WebView reports env(safe-area-inset-*)=0,
so CSS padding did nothing and content slid under the Dynamic Island (every page: home/share/
connect/login) and the bottom nav was clipped.
- Use the already-installed StatusBar plugin: setOverlaysWebView(false) pushes content below the
  status bar natively (no rebuild). Applied on all entry pages via a small native-chrome snippet.
- Hard-code the bottom home-indicator inset (--sab:34px on html.native-ios) since env() can't give it.
- #2 keyboard: hide the bottom tab bar inside an open conversation so the composer sits directly on
  the keyboard (was sandwiched between composer and keyboard).
- #3 h-scroll: clip every scroll surface + overflow-wrap:anywhere so long content can't widen the page.
Build marker -> 2026-07-17-batch91.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 17:19:37 +05:30
Sravan 95e13a707e fix(ios/mobile): safe-area insets, no keyboard auto-open, no h-scroll, swipe-back, hide desktop-download
Reported on the iOS TestFlight build:
- #1/#5 notch/home-indicator: apply top safe-area inset per surface (chat list column +
  content panels) instead of on the whole shell, so headers sit below the Dynamic Island
  and nothing is cut off top/bottom.
- #2: opening a chat no longer auto-focuses the composer (was popping the phone keyboard
  and shoving the layout up); tapping the box still focuses normally.
- #3: overflow-x:hidden + max-width:100vw guards so pages can't pan left/right.
- #4: left-edge swipe-right now triggers the existing bzcBack() (close popup/search/open
  chat) — a native-feeling back gesture with no native code.
- #6: hide the 'Download app' (Windows) button when running inside the Capacitor app.
Build marker -> 2026-07-17-batch90.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 16:44:12 +05:30
Sravan 2e4e0210b0 ci(ios): internal-testing-only publishing + declare encryption exemption
The IPA now builds, signs, uploads and processes on App Store Connect. Set
submit_to_testflight=false so the build stays green via internal testing; external
beta review (which needs Test Information + a demo login) is opt-in later. Also set
ITSAppUsesNonExemptEncryption=false in Info.plist so ASC stops prompting for export
compliance on every upload.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 16:02:28 +05:30
Sravan 1ffc69469b ci(ios): pass a fixed CERTIFICATE_PRIVATE_KEY so the distribution cert is reusable
fetch-signing-files --create alone mints a throwaway distribution certificate whose
private key dies with the build VM; the next build then finds a cert it has no key
for and fails 'Cannot save Signing Certificates without certificate private key'.
Supplying our own fixed private key (secure var in the ios_signing group) makes the
cert reproducible and reusable across builds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 15:47:28 +05:30
Sravan 84315ccfb4 ci(ios): run xcode-project use-profiles after pod install, not before
The archive failed with 'App requires a provisioning profile' because use-profiles
ran inside the signing step before pod install created the workspace, so the
profile never bound to the App target. Move it to just before build-ipa, matching
Codemagic's Capacitor recipe.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 13:39:01 +05:30
Sravan 054b0bb70f ci(ios): remove ios_signing auto-fetch block so first build creates its own signing profile
The environment.ios_signing block makes Codemagic fetch an EXISTING profile at
build init and fails with 'No matching profiles found' on a brand-new app. The
'Set up code signing' script already creates the cert+profile via
fetch-signing-files --create, so the block was both redundant and blocking.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 13:30:11 +05:30
Sravan c18e55b5ec ci: remove hard-coded personal email from codemagic.yaml (watch builds on the dashboard) 2026-07-16 18:09:26 +05:30
Sravan 42e0122504 docs(ci): how to connect Codemagic to self-hosted Gitea over SSH (expose port + read-only deploy key) 2026-07-16 15:46:22 +05:30
Sravan 6b5ca687e4 docs(ios): track ReplayKit screen-broadcast + native audio-routing as phase-2 follow-ups
iOS WebViews don't support getDisplayMedia, so sharing the device screen into a meeting needs a
native ReplayKit Broadcast Upload Extension (+ App Groups) — viewing a shared screen works today.
Also note native audio routing (AVAudioSession) as a phase-2 plugin. Adjusted the App Review note
so we don't advertise iOS screen-sharing before that extension ships.
2026-07-16 14:47:28 +05:30
Sravan 3b09702593 docs(ios): add App ID registration step (fields + Push Notifications capability) 2026-07-16 14:34:46 +05:30
Sravan bc909cb0c0 build(ios): Codemagic pipeline + runbook for App Store (no Mac needed)
The iOS app is a Capacitor shell over the live web UI — the web/server side is already fully
Capacitor-ready (nativePlatform() detects Capacitor; setupNativePush registers APNs tokens via
/api/v1/devices; the APNs sender is built into server/push.js, config-gated). So this adds only
the build/sign/upload path:

- codemagic.yaml: macOS-cloud workflow that generates the iOS project, patches Info.plist,
  generates icons/splash, signs via an App Store Connect API key (automatic signing), archives,
  and uploads to TestFlight. No Mac required.
- mobile/scripts/ios-patch.sh: adds the App-Review privacy usage strings (camera/mic/photos) +
  display name to the generated Info.plist.
- mobile/IOS_SETUP.md: click-by-click runbook — ASC app record, API key, Codemagic integration,
  first build, APNs key → server .env, and the public-submission checklist.

Bundle id com.bizgaze.connect. No secrets committed — Apple keys live in Codemagic + server .env.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 16:45:10 +05:30
Sravan c8f383cbcb fix(gif): send a GIF as the active reply; show GIF (not URL) in reply bar/quote (batch89)
sendGif ignored replyTarget, so picking a GIF while replying sent a plain message instead of a
reply. It now carries replyTo and clears the reply, like sendMessage. Reply bar + quote show
'GIF' instead of the raw media URL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 15:54:31 +05:30
Sravan a172214c44 fix(gif): fixed-height grid rows so GIFs stop stacking over each other (batch88)
aspect-ratio:1 on the grid cells collapsed to ~0 height in the emoji-pop flex column, so the
images overflowed and overlapped. Use grid-auto-rows + a fixed cell height instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 15:46:05 +05:30
Sravan 02075fbd47 feat(chat): GIF picker via server-proxied GIPHY (#5) (batch87)
- Server: GET /api/gifs proxies GIPHY search/trending. The API key is read from the server
  env only (config.GIPHY_API_KEY, from the gitignored .env) and NEVER reaches the browser;
  the picker is hidden when it isn't configured.
- Emoji picker gains a GIF tab (separated from the emoji categories) with a search box + a 2-col
  grid, "Powered by GIPHY" attribution. Clicking a GIF sends it immediately.
- GIFs are HOTLINKED to GIPHY's CDN (their terms require this — no re-hosting): the message body
  is the GIF url, and a body that is a lone GIF url renders inline as the animated GIF (reusing
  the image/lightbox path). Sidebar previews + notifications show "🎞️ GIF", not the raw url.

Key is NOT in git — set as GIPHY_API_KEY in the server .env.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 15:30:44 +05:30
Sravan c3dc47a94c fix(meetings): Past shows only scheduled + instant meetings; ad-hoc calls hidden w/o recording (batch86)
Revised rule per user: a call is not a meeting. Past meetings now = real SCHEDULED meetings +
INSTANT meetings (Start-a-meeting, logged in call_history as adhoc). Ad-hoc CALLS — 1:1 direct,
group calls, and a 1:1 that a 3rd person joined — are shown ONLY if they produced a
recording/transcript. Dropped the earlier ">2 participants shows it" exception.
Also stop rendering a bare "Host: —" on logged call cards.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 14:58:48 +05:30
Sravan f708cc2f12 fix(meetings): hide empty 1:1 direct calls; date from/to validation + field alignment (batch85)
#3 The 136 "Direct Call" cards: calls.js writes a scheduled_meetings row for EVERY call
   ("Direct Call" / "Group call"), which is separate from the call_history table. Those rows
   came through the scheduled-meetings path and my earlier filter never touched them. Now an
   auto call-history row is shown in Past ONLY if it produced a recording/transcript OR the
   call ever held >2 people (peak from the call log); plain 1:1s with neither are dropped.
   Removed the now-redundant callRows synthesis. Recordings stay attached (rows WITH a
   recording are always kept).
#4 Date range: from ≤ to enforced by disabling out-of-range days in each picker (can't pick a
   from after to, or a to before from). Filter controls share one height/baseline so the
   calendar icon, preset dropdown and date fields align cleanly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 13:19:12 +05:30
Sravan fad8a52da4 fix: last-seen backfill, report-style date filter, hover overflow (batch84)
#1 Last seen still read "Offline": last_seen is a NEW column, so every existing user was NULL
   until they happened to reconnect. Backfill it from the newest message each user sent (best
   evidence we already have), and also stamp it on message send — not just on connect/disconnect
   — so it stays fresh if a socket never closes cleanly.
#3 Past-meetings filter is a report filter now: presets (Today, Yesterday, Last 7/30 days, This
   month, Year to date, All time) plus a Custom range that uses the SAME branded calendar popup
   as the scheduler. The raw <input type=date> looked foreign and behaved differently per browser.
#4 Hover action row overflowed off-panel on SHORT received messages: it's wider than the bubble
   and was anchored to the bubble's right edge, so it ran off the left. Received bubbles now
   anchor it from the left (growing into the empty space); own messages keep the right anchor.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 01:02:59 +05:30
Sravan 6fa261b68f feat(meetings): call log, past pagination + date filter; last-seen exact time (batch83)
#7 The past list was hard-capped at 12 (a .slice(0,12) in the client) and there was NO record
   of how many people were ever in a finished call — so the "only calls with >2 people" rule
   was impossible to apply. Added a call_history table: signaling tracks the HIGH-WATER
   participant count per room and logs the call when the room tears down (scheduled meetings
   are skipped — they already have their own row).
   Past meetings now follow the rules asked for:
     • a plain 1:1 direct call is NOT listed — unless it produced a recording/transcript
       (those already surface as recording entries);
     • a call that ever held MORE than 2 people IS listed (e.g. a 1:1 a third person joined),
       showing its participant count and duration;
     • entries are visible only to people who were actually in the call (or the group).
   Server-side pagination (10/page) + a from/to date filter; nothing is double-listed.

#2 Last seen now shows the exact time/date, WhatsApp-style — "last seen today at 1:36 PM",
   "last seen yesterday at 10:15 AM", "last seen 14/07/2026 at 9:00 AM" — instead of "10
   minutes ago".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 00:42:53 +05:30
Sravan 860a7bd6cf feat(chat): emoji speed, action rework, copy, phone links, image zoom, upload %, profile card, last seen (batch82)
#6 Emoji were slow because Twemoji swapped EVERY emoji for an <img> fetched individually
   from a CDN — opening the picker fired hundreds of image requests. Now uses the OS's own
   colour emoji font: instant, zero network. twemojify() kept as a no-op.
#4 Message hover row reworked: three one-tap reactions (Like/Laugh/Surprised) + the emoji
   picker + (own) Edit. Reply / Forward / Copy / Delete moved behind a ⋮ menu. Added Copy.
   The row now sits FULLY above the bubble (was top:-14px, overlapping the first text line).
#9 Phone numbers linkify to tel: — mobile gets the OS "call this number?" prompt; desktop has
   no dialer so it offers to copy. Regex kept conservative (10–15 digits, needs +/grouping) so
   it won't grab amounts, dates or 6-digit meeting codes.
#3 Image preview zooms: wheel + pinch + double-click + ± buttons, drag to pan, keys (+/-/0),
   cursor-anchored. Arrows hide while zoomed so panning isn't hijacked.
#8 Upload progress: fetch() can't report upload progress at all, so a large file just said
   "uploading…". Switched to XHR (upload.onprogress) → real bar + %, and cancel aborts in flight.
#1 Clicking a sender in a group opens a mini profile card (photo, presence, last seen) with a
   Message button that opens the 1:1 (and a view-photo button).
#2 Last seen: new users.last_seen column, stamped on connect and when the last socket drops;
   carried on the presence broadcast, so an offline contact reads "Last seen 10 minutes ago"
   instead of a bare "Offline".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 23:46:52 +05:30
Sravan 667b4c69d5 perf(update-check): throttle + single-flight the build check (batch81)
The check itself is cheap (one ~35-byte response, served from a variable the server reads
once at startup), but it was hooked to BOTH `focus` and `visibilitychange` with no throttle —
and a single alt-tab back into the app fires both, so every refocus cost two redundant
requests. Now: one check per minute at most, never overlapping itself, and it stops checking
entirely once a new build is known (the retry loop takes over).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 16:14:50 +05:30
Sravan c1f01e796a fix: DP missing in 1:1 for un-messaged contacts; make web updates fully silent (batch80)
DP bug — real cause found (client-side, not the DB):
loadSidebar builds a DM row for every contact you haven't messaged yet, but it copied only
{name, online} from the contact and DROPPED `avatar` (and status/email). So an un-messaged
contact always rendered initials in the 1:1, while the SAME person showed their photo in a
group (which reads /api/groups/members). Carry the whole contact through.
Kept a server-side safety net: avatarsFor() now indexes known photos under person-id, email
AND name, so a duplicate row missing a photo can match on any of them (the previous single
composite key missed twins with different emails).

Web updates are now completely silent: no banner, no toast. A web build is an implementation
detail — surfacing it makes users reason about "web build vs app version", which is exactly
the confusion to avoid. New code simply applies itself as soon as it's safe.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 16:06:28 +05:30
Sravan 2aeeb0a096 fix: auto-apply new web builds; DP missing in DM but shown in group (batch79)
Auto-update (no manual step, no version confusion):
- New code now applies ITSELF. The client polls /api/build and, as soon as it's SAFE,
  silently hard-reloads onto the new build. Safe = not in a call, no live screen session,
  no dialog open, nothing half-typed; if the user is busy we wait and apply the moment
  they're free. A brief "Updated to the latest version" toast confirms it.
- Removed the "web build" row from Settings: users must never have to reason about an app
  version vs a web build. The only version surfaced is the desktop app's (auto-updater).

DP bug: a contact showed their photo in a GROUP but fell back to initials in the 1:1.
Two causes, both handled:
- Duplicate rows for one person (signed in by email once and by mobile another time before
  the bizgaze_user_id merge landed) — only one row carries the DP, and the group happened to
  reference the row WITH the photo. avatarsFor() now keys rows by stable person identity
  (bizgaze person id → email → name) so a photo-less row borrows its twin's photo. Applied to
  contacts, conversations, group members and group info.
- A DM whose counterparty was merged away is now keyed by the SURVIVING account, so the row
  carries that account's name/photo/presence (and split threads collapse into one).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 15:34:35 +05:30
Sravan a0017f2036 feat: detect new web builds + hard-refresh escape hatch (0.1.17/batch78)
Root cause of "the fix works on mobile but not on desktop/web": nothing was wrong with
the code — the desktop app now CLOSES TO TRAY, so it can run for weeks on the page it
loaded on day one and never re-fetch after a deploy. There was also no way to force it
off a stale page (no menu bar → no reload accelerator).

- Server: GET /api/build returns home.html's __BUILD marker.
- Client: polls it (boot, on focus/visibility, every 10 min); when the server's build
  differs from the running one, shows a branded "A new version is available — Refresh"
  banner. Settings gains an always-available "Refresh app" with the current build shown.
- hardReloadApp(): in the browser it unregisters service workers + clears CacheStorage
  then reloads cache-busted; in the shell it calls the native hard reload.
- Desktop: hard-reload IPC (clears the session HTTP cache + reloadIgnoringCache), wired to
  Ctrl+R (reload), Ctrl+Shift+R / F5 (hard reload), and a "Refresh app (get latest)" tray
  item. Previously there was literally no way to clear the cache from the app.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 13:38:55 +05:30
Sravan 5a138f5bc4 fix(meetings/mobile): PTR, ringing tile, responsive bar, ⋮ toggle, add-people search (batch77)
#6 Pull-to-refresh genuinely broken: the indicator lived INSIDE the scroller (so it
   scrolled away unseen) and only became visible after ~96px while the trigger fired at
   70 — and preventDefault was deferred until the pull passed 10px, by which point
   iOS/Chrome had already claimed the gesture. Indicator now mounts on the list's
   non-scrolling parent with the branded loader, the gesture is claimed immediately, and
   the trigger is reachable. Works on Android + iOS.
#4 ⋮ More now TOGGLES (it used to remove then instantly rebuild, so it never closed).
#3 "Ringing…" is centred over the tile with the avatar/name dimmed behind it.
#2 Meeting bar fits the screen on mobile: one row of controls sized to the viewport,
   room code on its own line, safe-area padding.
#5 Search box in the in-call Add-people tab.
#1 Speaker control: setSinkId (the only web API for audio output) is NOT implemented in
   Android Chrome or iOS Safari — the OS owns the route there, and iOS forces loudspeaker
   whenever a mic track is live. Rather than ship a button that silently does nothing, it
   now only renders where output switching actually works. Real speaker/earpiece/Bluetooth
   switching on phones needs the native (Capacitor) audio plugin.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 12:35:01 +05:30
Sravan e8c0b1889f fix: off-state colors, mobile audio route, iOS rail/PTR, in-place join, draggable bars (0.1.16/batch76)
Regressions I introduced, now fixed:
#8d Mic/Camera OFF went DIM — my new `.meet-ic.off` rule overrode the original RED.
    Scoped the lite style to the speaker button only; mic/cam OFF are red again.
#7  Guest "left the meeting" was unstyled (dark text on blue, no card): the card CSS was
    scoped to .guest-prejoin only. Shared with .guest-left. Rejoin no longer dead-ends —
    if the room is gone we say "This meeting has ended" and hide the button.

Reported:
#8d Speaker button no longer shows on desktop (devices already live under the mic ▾).
#8c/#8e Mobile speaker button now CYCLES Speaker → Earpiece → Bluetooth (icon follows the
    route); dropped the redundant "Audio devices" entry from the ⋮ menu.
#8a iOS gap under the bottom rail: the page rubber-band-bounced, exposing background beneath
    the fixed bar. overscroll-behavior:none + fixed body pins it.
#8b Pull-to-refresh now fires on iOS too (overscroll-behavior:contain on the lists so Safari's
    rubber band stops swallowing the gesture; scrollTop>2 tolerance for momentum).
#5  A meeting link no longer opens a whole new window: same-origin urls navigate the main
    window in the shell, and a link clicked in chat joins the meeting IN PLACE.

New observations:
1. The viewer's mic now starts MUTED on a screen session (and can actually be un/muted).
2. iOS lightbox close/download buttons moved below the Dynamic Island (safe-area insets).
3. Meeting chat: recipient picker moved to the BOTTOM next to the input; a private message
   auto-targets your reply back to that person; private vs everyone are visibly different
   (brand amber vs blue/neutral) and the compose area tints in private mode.
4. Meeting bar + screen-session bars are DRAGGABLE (position remembered) so they stop
   covering the shared screen.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-13 22:24:36 +05:30
Sravan 48b6a4050a fix: SFU participants, duplicate peers, RC without login, devices, mobile bar (batch75)
#4 Participants list only ever showed "you": in SFU mode meetMakePeer drew a tile but
   NEVER added to meetPeers, so the roster (and the meeting-chat "To" list) was empty.
#5 Same person as several tiles: each tab/reload/reconnect gets a new peerId, leaving
   ghost peers. One uid = one tile now (dropDupPeers keeps the newest).
#1 Remote control needed a login: /share opened top-level (the no-login "Share my
   screen") has the preload bridge RIGHT THERE, but we only postMessage'd to a parent
   frame that doesn't exist — so control never armed. Use the native bridge directly.
#2 Sharer's session bar moved to the shared Lucide icon set (was old inline SVGs).
#3/#6 Device menu: collapse Windows' "Default -"/"Communications -" triplicates into one
   clean list (single "System default" + each real device once), and actually re-apply the
   saved mic/speaker to the room on connect so a picked headset/Bluetooth is used.
#7 Guest "left the meeting" screen rebranded to match the new pre-join.
#9 Tapping a member in group info opens the private conversation with them.
#8a iOS bottom rail: border-box + height incl. the home-indicator inset, px env() fallbacks
   (unitless 0 breaks calc() in Safari), promoted layer so it stops drifting.
#8c/#8e Mobile meeting bar: Mic / Camera / Speaker / End only; screen, record, transcript,
   chat, participants move behind a ⋮ More menu. No mic device dropdown on mobile.
#8d Speaker button reflects the real route: speaker-on / speaker-off (dimmed) / bluetooth
   when a headset is in use; re-detected on devicechange.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-13 15:39:05 +05:30
Sravan 94b8fac32f fix: guest pre-join, post-admit lobby, audio device menu, RC keyboard (0.1.15/batch74)
1. Guest pre-join redesigned: brand backdrop, live camera preview, mic/cam toggles
   applied on entry, initials avatar, name required, "host may admit you" note.
2. Post-admit bug: the guest stayed on "Waiting for the host…" forever — the lobby
   screen had replaced the call UI and meeting-joined never re-rendered it. Now it
   rebuilds the call on admission (_inLobby).
3. Audio devices: dropped the standalone headphones button. The MIC now has a ▾ caret
   opening one Teams-style menu with Speaker + Microphone sections (radio-selected);
   speaker uses setSinkId/LiveKit switchActiveDevice, mic switches the live input.
   Mobile gets a speakerphone toggle that prefers a connected BT/headset when off.
4. Remote-control keyboard:
   - Injector now maps the PHYSICAL key (KeyboardEvent.code) instead of the character,
     so Shift+1 types "!" etc. Character mapping was why typing "performed differently".
   - Keys reach the sharer ONLY while control is ENGAGED (window focused AND you clicked
     their screen). Minimised/unfocused/chat typing stays local. Esc or clicking away
     releases; modifiers are released on disengage so nothing sticks.
   - Explicit control icons: viewer gets a Control ON/OFF button (green when engaged) +
     an on-screen hint; the SHARER gets a control icon beside mic/chat to allow/stop
     access at a glance, synced with the consent dialog and banner.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-13 13:18:01 +05:30
Sravan 82fa4a24d3 feat(meetings): in-meeting chat — Everyone or direct-to-participant, brand-styled (batch73)
Adds an ephemeral chat inside meetings (relayed over the meeting signaling socket,
not persisted). A chat button in the meeting bar (with an unread badge) opens a
brand-styled panel: pick "Everyone" or a specific participant (private), send with
Enter/Send. Direct messages are marked private on both sides. Works for guests too.
Chat state resets when you leave the call.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 15:08:24 +05:30
Sravan d0f9355553 feat: close-to-tray, meeting lobby, speaker select, link expiry, mobile RC touch (0.1.14/batch72)
General #1/#2 (closed-app notifications): the desktop app now CLOSES TO TRAY instead
of quitting, keeping its chat WebSocket alive so calls/messages still notify. Tray
icon + menu (Open / Quit), single-instance lock, first-close hint.

Guest #4 (lobby/admit): meetings can require the host to admit guests joining by link.
Setting on the schedule form ("Guests must be admitted by the host", default on) +
ad-hoc default. Guests wait on a "waiting to be let in" screen; the host gets an
Admit/Deny prompt; auto-cleanup on leave. Logged-in members always join directly.

Guest #5 (speaker): headphones/speaker output picker in the meeting (setSinkId),
remembered and applied to every tile.

Guest #3 (link expiry): guest link/token dies ~2h after a scheduled meeting's end
(HTTP 410) with a clear message; live-room links expire when the room empties.

RC #4 (mobile): touch→mouse mapping so a phone/tablet viewer can control (tap=click,
drag=move). Uses the same letterbox-correct coordinate mapping.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 14:44:58 +05:30
Sravan bd488b3286 fix(rc+guest): coordinate/keyboard/UI for remote control; guest media + panel fixes (batch71)
Remote control (connect.html viewer):
- Coordinate offset fixed: map clicks to the actual video CONTENT rect (object-fit
  letterbox-aware), not the element rect — cursor now lands where you click.
- Keyboard: capture at document level while a session is live (the <video> lost
  focus on bar clicks → keys did nothing). Skips the chat input.
- Control bar moved to bottom-right with tiny modern icons; video fills the viewport.
- Smoother cursor (mousemove ~60/s).

Guest meetings:
- Guest mic inaudible + guest invisible in the participant list + outsider screen
  share not showing (#1/#8/#11): root cause was the SFU media→tile map keyed on
  identity==uid, but guests had a random LiveKit identity and a null signaling uid.
  Guests now carry ONE stable id across signaling (meeting-join guestId) and the
  LiveKit token identity, so their media attaches and they appear to everyone.
- Guests can't add participants (#9) and don't see the transcript button (#12).
- Search box in the schedule participant list (#10).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 14:28:37 +05:30
Sravan e562099344 feat(remote-control): viewer can control a desktop sharer's screen, with consent (0.1.13/batch70)
Fixes the core "viewer can't control the sharer even on desktop" gap. Three root
causes addressed:
- share.html DISCARDED every input-channel message (onmessage=()=>{}). It now
  parses the viewer's mouse/keyboard events and forwards them to the desktop shell.
- The main desktop app had NO OS injector (it lived only in the separate agent).
  Ported the nut-js injector (agent/input/inject.js) into desktop/input, wired an
  inject IPC + injectInput bridge, HARD-gated behind a consent flag (rcArmed).
- /share runs in an iframe (no direct bridge access) → it postMessages input to
  the top frame (home.html), which relays to the native bridge.

Consent + safety: the sharer sees an Allow/Deny prompt the first time the agent
interacts; while active a persistent "your screen is being controlled — Stop"
banner; instant revoke; auto-release on session end/teardown. Browser sharers stay
view-only (no OS injection possible). nut-js is an optionalDependency (N-API, ABI-
stable across Electron) — degrades to no-op if the native module is unavailable.
Windows-first; maps to the primary display.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:30:39 +05:30
Sravan 7bc40d8397 feat(meetings): email invites + add external participants by email + share link (batch69)
#4: scheduled meetings can now invite people who aren't on Connect.
- SMTP config (config.js, env-gated: SMTP_HOST/PORT/USER/PASS/FROM/SECURE,
  PUBLIC_BASE_URL) + a small nodemailer wrapper (mailer.js) with a branded
  meeting-invite template carrying the guest join link. No-op until SMTP is set.
- /api/meetings/schedule + /update accept participantEmails; external emails are
  persisted (scheduled_meetings.guest_emails migration) and emailed the guest
  link (plus any invited Connect users with an email on file). Fire-and-forget —
  a mail outage never fails scheduling.
- Meetings list DTO returns `link`; schedule form gains an "Invite by email"
  chip input; each scheduled-meeting card gets a "Copy link" action.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:02:45 +05:30
Sravan 466c0d5d70 feat(meetings): guest join by link — external people can join without a Connect account (batch68)
- Server: POST /api/meetings/guest-token issues an unauthenticated LiveKit token
  for a room that is currently live or a valid scheduled meeting (throwaway guest
  identity). Mesh signaling already tolerates anonymous peers.
- Client: opening /home?meet=CODE while signed out runs a lightweight GUEST mode —
  name prompt, then straight into the meeting with the full meeting client and the
  chat/sidebar chrome hidden. Signed-in users who open the link auto-join.
- sfuConnect uses the guest token for guests. Guests get a friendly "left the
  meeting / rejoin" screen (no chat to fall back to).
- Meeting "Add people" panel gains a "Copy invite link" (copyMeetingLink) that
  copies the guest link — foundation for the emailed invites in #4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 15:44:28 +05:30
Sravan 9b86def921 feat(search): only surface Connect users; clear "not on Connect"/"not found" (batch67)
Contact search no longer lists BizGaze directory people who aren't on Connect as
addable rows (they can't be messaged). It shows only people actually on Connect;
if a search matches nobody on Connect it shows either "Not on Connect" (they exist
on BizGaze but haven't signed in) or "Contact not found".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 15:36:18 +05:30
Sravan aa4bb2902d fix: group toast icon, left-click spell suggestions, scroll no-yank (0.1.12/batch66)
1. Group message toast had no icon: the generated group icon is a data: URL, but
   the 0.1.11 handler only used ALREADY-cached icons and skipped it. data: URLs
   are synchronous — use them immediately, so every group toast shows an icon.
2. Spell suggestions on a LEFT click: clicking a red-squiggled word in the message
   box now pops the native suggestions menu (renderer asks the shell to synthesize
   a right-click at that point → real dictionary suggestions). No right-click.
3. Scroll felt "stuck" because an incoming message yanked you to the bottom even
   when you'd scrolled up to read history (worse now that bg messages arrive live).
   appendBubble now keeps your position unless you were at the bottom / it's your
   own message, and surfaces the "jump to latest" control instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 14:57:02 +05:30
Sravan 1dfb6b16cb fix: unstick scrolling, group toast icon, seen separator, autocorrect (batch65)
1. Scroll felt "stuck": the seen-by card had TWO nested scroll containers
   (.modal overflow-y:auto + inner .seen-scroll) fighting each other — card is
   now overflow:hidden so only the inner list scrolls. Global scrollbar widened
   6→11px, dropped the inset border, added a min thumb length so it's easy to
   grab and drags smoothly everywhere.
2. Group message toast now carries a generated group icon (initials on a brand
   disc) when the group has no photo — was iconless.
3. Seen / Not-seen split by a visual divider in the message-info popup.
4. Auto-correct: curated common-typo dictionary applied as you type (on a word
   boundary) — corrections happen automatically, no right-click. Web/desktop/mobile.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 13:56:18 +05:30
Sravan adafc8c960 fix: seen-by layout, group-name notif, teams-style badge, excel paste, spellcheck (0.1.11/batch64)
1. Message-info popup: ONE scroll region for the whole list with sticky
   Seen / Not-seen headers (was a separate scrollbar per section), realigned.
2. Group message notifications now title = GROUP name, body = "Sender: text".
3. Unread taskbar badge: solid red rounded-square (Teams-style) + white outline
   instead of the gradient disc.
4. Pasting Excel/Sheets cells no longer uploads a screenshot — when the clipboard
   carries real text, the text is pasted; image-only clipboards still upload.
5. Spell check in the message box (red squiggles) with a right-click menu of
   corrections + add-to-dictionary; spellcheck enabled on the textarea.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 13:25:37 +05:30
Sravan 70a776fa6c fix: real-time bg messages, join clears invite, richer seen-by, nicer badge (0.1.10/batch63)
1. Notifications/messages lagged when the desktop window was backgrounded —
   Electron throttles hidden renderers by default, stalling the chat WS's
   onmessage + timers. Set backgroundThrottling:false → real-time in the tray.
   (Transport is WebSocket; no Firebase needed.)
2. Joining a call via the header Join button left the Join/Decline invite popup
   on screen — enterMeeting now dismisses the invite (and stops the ring).
3. Seen-by is now "Message info": real contact DPs, a "Not seen yet" list for
   groups, and dark lettering (white-on-pastel initials were invisible).
4. App-icon unread badge: red→pink gradient pill with a white ring + shadow,
   drawn at 2x, instead of a flat red disc.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 12:51:14 +05:30
Sravan 62a5f750af fix(desktop): notification click no longer reloads to a dead page (0.1.9/batch62)
Root cause of the persistent "notification opens a dead page / no Join" bug:
openFromNotif gated the in-place open on `window.ME`, but ME is declared with
`let` — which never creates a global property — so window.ME was ALWAYS
undefined and every click hit the full-page-reload fallback. Use bare `ME`.

Also:
- Notifications fire instantly: never block on the DP download. Use the photo
  only if already cached; warm the cache in the background + pre-warm all
  contact DPs on chat load (precache-avatars IPC). Removes the ~2.5s lag.
- Wire call Join/Decline handlers BEFORE firing the OS notification so Join is
  live the instant the invite popup appears (was dead until the toast settled).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 18:00:56 +05:30
Sravan 6ed0fa0ea0 fix(desktop): custom screen picker, single restart prompt, reliable call Join (0.1.8/batch61)
- Custom branded screen/window picker (picker.html) — useSystemPicker was
  silently no-op on Win11 and auto-shared the primary display with no choice.
- Use checkForUpdates (not ...AndNotify): drops electron-updater's own native
  "Update ready" toast that duplicated our in-app banner (two restart prompts).
- Call notification DP: wait up to 2.5s for the caller photo on persistent
  (call) toasts instead of 600ms so the DP actually shows.
- Re-surface Join/Decline invite when opening a chat with an active incoming
  call, so a call-notification click always lands on a joinable call.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 17:38:50 +05:30
Sravan 4e2ccb5d60 fix: seen-by popup (#2), info-view DP preview (#5), notification DP cache + no Close btn, branded update flow (0.1.7)
- #2: 'Seen by' opens an on-screen popup listing readers (was a flash toast).
- #5: the DM contact-info view now shows the DP; clicking it previews full-size.
- Desktop notifications: cache DPs per-sender (fast AND with photo after the first);
  removed timeoutType:'never' which added an unwanted 'Close' button.
- Update flow: dropped the unbranded native restart dialog — the branded web banner
  handles Restart. Banner text clearer ('Downloading update…'), plus an update
  indicator that cascades profile 'i' badge → Settings → version line, with the
  Settings button becoming 'Restart now' when the update is downloaded. desktop 0.1.7.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 16:56:39 +05:30
Sravan 49718e5d37 feat: hyperlinks, group seen-by for all, profile-pic preview, in-call invite fix + desktop update progress (0.1.6)
- #1: URLs in chat are now clickable links (open externally on desktop).
- #2: group 'Seen by X, Y +N more' now shows under the LATEST message to EVERYONE
  (server computes reads for all messages; click shows the names).
- #5: tapping the conversation-header avatar previews the DP/group photo full-size.
- #4: in-call invite lists only people you've messaged, excludes those already in the
  call/invited, and the Invite button is sticky.
- #3 (0.1.6 shell): auto-updater emits checking/available/downloading/ready/error to
  the web UI, which shows a progress banner (+ Restart button) so updates aren't silent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 15:58:09 +05:30
Sravan 7682e17a53 fix(desktop 0.1.6): fast + persistent native notifications + screen picker
- Desktop notifications were slow (~15s), vanished in ~1s, and clicks did nothing:
  * don't block the toast on the avatar download (race a 600ms cap) → shows instantly
  * keep a strong reference to each Notification (Electron GC'd them → premature close
    + dead click)
  * call invites use timeoutType:'never' + a 45s window so they stay until clicked/ended;
    web marks call notifications persistent.
- #9: enable the OS screen/window PICKER (useSystemPicker) so users choose what to share
  (a single window avoids the whole-screen mirror); falls back to primary display.
- desktop 0.1.5 -> 0.1.6.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 15:43:07 +05:30
Sravan 0976b6f91a feat(dashboard): profile pic (More#3), sticky top nav (More#5), App-installs search+pagination (More#4)
- #3: profile avatar now shows the photo (avatarUrl) not just initials.
- #5: header is position:sticky so the brand + profile stay visible while scrolling.
- #4: App installs table gets a search box (user/platform/version/OS) and 10-per-page
  pagination with prev/next + count.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 14:28:12 +05:30
Sravan 3e811af3d6 fix(calls): screen shows with camera OFF (#9), screen-share button highlight, unanswered caller vs callee text
- #9 REAL cause: the tile was forced to avatar whenever the peer's CAMERA was off
  (addTile + meeting-peer-state), so a screen-share only appeared if the camera was
  also on. Now camera-off only shows the avatar when the peer is NOT sharing a screen.
- #9: screen-share button is highlighted (blue) while active, like mic/cam/record.
- Unanswered call text is viewer-relative: the caller sees 'Call not answered', the
  callee sees 'Missed call'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 14:24:17 +05:30
Sravan 096683385a fix: chat-open scroll regression, SFU screen reliability, unanswered calls, selected-chat border
- REGRESSION (More#1): removed overflow-anchor:none (it stopped the view from staying
  at the bottom as images settle) + renderThread re-asserts scroll-to-bottom after late
  content, unless a 'New messages' divider is shown → chats open at the latest message.
- #9: dynacast off — a screen-share layer was being paused unless a camera track was
  also flowing (blank / only-with-camera / slow). Now every published track flows.
- More#7/#9: 1:1 calls track 'answered'; unanswered calls auto-end after ~40s (caller
  no longer stuck ringing) and post 'Missed call' instead of a duration; answered calls
  show duration from the answer time. meeting-ended reason 'unanswered' → 'No answer'.
- More#6: selected chat now has a thin yellow (brand) boundary.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 13:20:19 +05:30
Sravan f6962a0b4a fix: screen-share mirror (#9), sidebar tick sync (#1), desktop notification reload (#3)
- #9: sharing your whole screen no longer creates a 'hall of mirrors' — your own
  screen is NOT shown back to you (you see your camera/avatar + a 'You're sharing'
  badge); other participants still see your screen. Your own tile is never the local
  stage.
- #1: opening a DM now syncs the sidebar tick to the thread's true delivered/read
  state, so it can't show a single tick while the conversation shows double.
- #3: nativePlatform() now also detects older desktop builds that expose
  bizConnectNative but not __NATIVE__. Those were wrongly subscribing to Web Push, so
  the service worker's openWindow RELOADED the page on notification click (losing the
  header DP). Desktop now uses only the native toast → opens in-place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 11:55:30 +05:30
Sravan 1114cd4fda fix(calls): callee tile while ringing (#7), multi-device decline no longer kills active call (#8), SFU screen-attach retry (#9)
- #7: outgoing 1:1 call shows the person you're calling (DP + name + 'Ringing…')
  instead of only your own tile; removed when they answer or the call ends.
- #8: declineDmCall now ignores the decline if that user has ALREADY accepted on
  another device (they're in the room) — declining the ringing invite on a 2nd
  device no longer tears down the active call.
- #9: sfuAttach retries (bounded) when the uid→peerId map lags the LiveKit track,
  so a shared screen isn't silently dropped due to a race.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 23:18:14 +05:30
Sravan f52d54a093 fix(chat): forward polish + scrollbar + image preview + media tabs
- #4: forward modal buttons now branded (bzc-* un-scoped from .bz-confirm); target
  rows get real checkboxes + border highlight; selected MESSAGES highlight in green
  with a filled tick (distinct from blue bubbles), checkbox on every message.
- #5: forwarded messages show an italic 'Forwarded from <origin>' label; new fwd_from
  column preserves the true origin across re-forwards.
- #6: image-preview arrows are smaller (32px) chevron icons, clear of the image
  (image max 82vw); icons.js?v=5.
- #10: image preview now opens ABOVE the media modal (z 9900) and Esc/close returns
  to the media view instead of closing everything.
- #11: Media/Links/Docs active tab underline is brand-blue, not green.
- #2: chat-list + conversation scrollbars 6px, stepper arrows hidden; pagination adds
  a cooldown + overflow-anchor:none so scrolling up no longer sticks/jumps.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 23:11:02 +05:30
Sravan 346361da8a feat(chat): dismiss a chat's notifications on other devices once seen (#13)
When you open/read a conversation, the server now also pushes a notif-clear to your
OWN other sockets. Each device tags notifications by conversation (kind:id), so on
notif-clear it closes the matching page Notification + any Service-Worker (Web Push)
notifications, and drops matching activity-center entries so the bell badge stays in
sync. (Desktop Electron native toasts are transient/auto-expire; the web+PWA surface
is covered.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 16:20:18 +05:30
Sravan ff436704ec feat(desktop 0.1.5): show version + Check for updates in Settings (#12)
- Settings now shows 'Biz Connect for Desktop · Version x.y.z' with a Check for
  updates button (desktop only, feature-detected).
- preload exposes checkForUpdates(); main.js adds the check-updates IPC (returns
  available/current/dev/error) and, when a build finishes downloading, shows a
  Restart now / Later dialog instead of only the silent on-next-launch install.
- desktop version bumped 0.1.4 -> 0.1.5.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 16:12:21 +05:30
Sravan a9b3533f7a feat(chat): forward messages with multi-select (#1)
- Message action pill gains a Forward button; tapping it enters selection mode
  (tap bubbles to multi-select, footer bar shows count + Forward/Cancel, Esc exits).
- Forward picker lists EXISTING conversations only (DMs + groups from the sidebar),
  searchable, multi-target. POST /api/messages/forward copies body+attachment into
  each target (authorized as participant/member), live-pushed like a normal send.
- /files auth now accepts ANY message carrying an attachment (allByAttachment), so
  forwarded images stay viewable for the new recipients.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 16:09:02 +05:30
Sravan 3a976d58ab feat(chat): reply-jump (#8), image prev/next nav (#3), multi-file send (#5)
- #8: reply quotes are now clickable — jump to the original message (paging older
  history in if needed), then flash it. reply DTO carries the target's timestamp.
- #3: image lightbox now has ← / → arrows + keyboard nav to flip through all images
  in the conversation.
- #5: the composer queues MULTIPLE files (file input is multiple; paste still works);
  each is shown as a removable chip and sent as its own message (first carries the
  typed text as caption), in order.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 16:02:15 +05:30
Sravan c672f7b65f fix: notification-open in-place (#2/#7/#19) + polish (#9 scrollbar, #16 call scrollbar, #17 ringback)
- #2/#7/#19: openFromNotif opened chats via a full-page reload (location.assign),
  which was slow AND dropped live state — the sidebar hadn't reloaded so the header
  showed 'Conversation' with no DP, and an incoming call's Join/invite popup was lost.
  Now it opens the chat IN-PLACE (selectChat) since the app is already running;
  full-page nav only as a fallback when the app isn't initialised.
- #9: slimmer 6px scrollbar; explicitly hide all webkit stepper-arrow variants.
- #16: 1:1/small call no longer shows a stray scrollbar — meet-grid centers tiles
  and clips overflow (call UI fits the viewport).
- #17: caller now hears a gentle ringback while waiting; stops on answer, on any
  call exit, and auto-stops after 45s so it never rings forever.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 15:54:28 +05:30
Sravan 16065315a7 fix(chat): pull-to-refresh at top loads older history, no longer resets to bottom
Pull-down-at-top called reloadThread (reload newest 500 + scroll to bottom), so
reaching the oldest message yanked the view to the newest — jarring, especially on a
single page. Now the pull gesture calls loadOlder: it pages in older history keeping
scroll position, or no-ops when there's nothing older. Never jumps to the bottom.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 15:44:32 +05:30
Sravan eb79823fd2 feat(chat): older-history pagination + full-thread server-side search
Older messages (beyond the newest 500) now load as you scroll to the top — the
thread endpoint takes a ?before=<created_at> cursor, the client prepends the older
page and preserves scroll position (renderThread keepScroll). _hasMoreOlder stops
paging when a short page returns.

Search now covers the ENTIRE thread, not just the loaded window: new
/api/messages/search (DM + group, LIKE with escaped wildcards) returns all matching
message ids; the client debounces the query, and jumping to a hit older than the
loaded window pages history back (ensureLoadedBack) until the match is in view, then
highlights + flashes it. Cap raised to 500.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 15:21:14 +05:30
Sravan 4fd323fff4 fix(chat): thread query returned OLDEST 300, hiding new messages past the cap
THE disappearing-messages root cause (found via THREAD.length=300 vs 351 on server).
messages.thread and threadByConversation did 'ORDER BY created_at ASC LIMIT 300' —
the oldest 300. Once a DM/group passed 300 messages, every newer message was silently
dropped from the fetch, so anything sent after that point 'disappeared' (persisted
server-side, never returned to the client). Now: inner 'ORDER BY created_at DESC LIMIT'
takes the NEWEST N, outer ASC presents them oldest-first. Cap raised 300 -> 500.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 15:08:38 +05:30
Sravan 507489ec55 fix(chat): stop blanking a conversation (and wiping its cache) on a failed thread fetch
THE disappearing-messages root cause. openConvo did: let msgs=[]; try{ msgs=fetch()
}catch{}; THREAD = Array.isArray(msgs)?msgs:[]. On a flaky desktop network a failed
fetch left msgs=[] (still an array) → THREAD=[] AND THREAD_CACHE.set(ckey,[]) — so
reopening a chat blanked it AND overwrote the cache, making messages vanish and stay
gone even though they persist server-side (confirmed: 982 DMs, zero dangling ids).

Now msgs stays null on a failed/non-OK fetch; we only replace THREAD/cache on a real
array response, and otherwise keep the cached render instead of blanking.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 13:47:58 +05:30
Sravan 12be747609 fix(chat): resolve merged-away user ids so DMs to merged contacts don't vanish
Root cause of 'messages to some contacts disappear (gone after reopen)': the #2
account merge deletes the merged-away user row. Any lingering reference to that old
id — a cached contact, an in-flight DM — then saved against a dead recipient / 404'd
on thread fetch, so messages silently vanished.

- New user_aliases table records old_id -> survivor on every merge (mergeInto).
- users.resolve(id) follows the redirect.
- DM send (recipient), thread fetch (with), and read now resolve() the peer id, so a
  stale id transparently routes to the surviving account.

Fixes future merges fully. Contacts merged BEFORE this (no alias recorded) may need a
one-off data check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 13:23:49 +05:30
Sravan 1128f9811a fix: persist chat uploads on /data volume (broken images) + prevent duplicate chat sockets
- Broken images: UPLOADS_DIR/REC_DIR/TRANS_DIR were server/<dir> INSIDE the image,
  so every deploy.sh rebuild wiped uploaded files — old images 404'd ('broken
  image') though their DB rows survived. Make them env-overridable and point prod
  at /data/uploads|recordings|transcripts (persistent volume), matching DB/downloads.
  NOTE: files already lost to prior rebuilds can't be recovered; new uploads persist.
- Duplicate notifications: harden connectChatWs — close/detach any prior socket
  before opening a new one and keep a single pending reconnect timer, so a flaky
  reconnect can't leave two live sockets delivering every event/notification twice.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 13:09:24 +05:30
Sravan 7d284213d1 fix(chat): non-destructive reconnect resync — stop messages disappearing after send
batch42's resync-on-reconnect reopened the conversation via openConvo, which
replaces THREAD wholesale. On the desktop app (flaky WS), a reload racing with a
just-sent message could momentarily blank the chat ('messages disappear after
sending', seen on the Manasa chat). resync now MERGES: adds messages missed while
disconnected + refreshes read/delivered/seen/edited/deleted flags, but never
removes messages already on screen.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 12:41:12 +05:30
Sravan 37c8929c5e fix(sfu): upgrade LiveKit server v1.7 -> v1.9 to match client SDK 2.20
The bundled livekit-client@2.20 uses signaling protocol 17 and the /rtc/v1 path,
which the v1.7 server didn't implement (404). The client fell back to the legacy
path, leaving the track publisher in a bad state so mic/cam publishing failed with
'InvalidAccessError: The sender was not created by this peer connection' — surfaced
to users as a misleading 'permission required' toast. v1.9 supports protocol 17.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 12:33:11 +05:30
Sravan 496eba3c17 fix(chat): batch 1 desktop fixes — resync-on-reconnect, branded confirm, esc, typing-in-panel, media errors
- #10/#18/#7: on WebSocket RE-connect, re-pull sidebar + re-open the current
  thread so the desktop/mobile apps recover missed messages/ticks without a
  refresh (the old onopen only re-sent chat-hello).
- #11: branded bzConfirm() dialog replaces window.confirm for delete (the OS/
  Electron default dialog looked off-brand on desktop).
- #4: global Esc no longer closes the conversation while an image preview is
  open — the preview closes first, the conversation on a second Esc.
- #6: live 'typing…' now also shows inside the conversation panel (animated),
  not only the header/sidebar.
- #15 (diagnostic): mic/cam failures now report the REAL cause (permission vs
  no-device vs in-use) with desktop-specific guidance, and log the raw error,
  instead of always saying 'permission required'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 11:46:22 +05:30
Sravan 472170784b fix(livekit): single UDP media port + pin node_ip for the NAT'd server
The prod box is behind NAT (private 192.168.88.61 behind public 118.95.33.89), so
LiveKit auto-IP-detection would pick the wrong (outbound) address. Pin
rtc.node_ip=118.95.33.89 and collapse media to one UDP port (50000) + TCP 7881 to
minimize the upstream gateway port-forward the network team must add. Docs updated
with the exact forward table.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 13:50:24 +05:30
Sravan 10e393a31f chore(compose): gate livekit behind 'sfu' profile so it stays dormant until enabled
A normal deploy no longer starts the livekit container (it would crashloop with
empty keys before provisioning). Enable with 'docker compose --profile sfu up -d'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 13:23:09 +05:30
Sravan 47b6f475e6 docs(deploy): LiveKit SFU provisioning — phase 3 (ops runbook)
Step-by-step to enable meetings SFU: generate key/secret, .env vars, DNS record,
NPM proxy host for wss signaling, VPS firewall for UDP media + TCP fallback, deploy,
verify. Includes the one-line rollback to mesh (remove the LIVEKIT_* vars).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 13:21:44 +05:30
Sravan 6118d59c5c feat(meetings): LiveKit SFU — phase 2 (client media plane, behind the flag)
Meeting media flows through LiveKit when the server reports sfu:true; otherwise the
P2P mesh is unchanged. Reuses the ENTIRE existing meeting UI + WS control plane
(join/host/mute/screen/recording/transcript) and only swaps the transport:
- vendored livekit-client 2.20 UMD (lazy-loaded; no build step).
- sfuInit() reads /api/meetings/config at boot; sfuConnect() joins the LiveKit room
  with the minted token after the WS meeting-join.
- remote tracks map back to the WS peerId via uid (LiveKit identity = app user id);
  per-peer stream prefers screen over camera, driving the existing sharing/stage UI.
- toggleMic/Cam/Screen publish via LiveKit; local tracks reflected into meetLocalStream
  so tiles, active-speaker meter, canvas recording and transcript keep working.
- meetMakePeer/peer-joined/peer-left/leaveMeeting branch on SFU.on; mesh path intact.

Needs a running LiveKit server + live test (phase 3 ops) to exercise end-to-end.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 13:20:59 +05:30
Sravan f1dbcd0f86 feat(meetings): LiveKit SFU — phase 1 (server plumbing, config-gated)
Adds the server side of scaling meetings past the ~5-peer mesh:
- config.js: LIVEKIT_URL/API_KEY/API_SECRET + LIVEKIT_ENABLED flag. All optional;
  when unset the app keeps the built-in P2P mesh (fully additive, like push).
- routes.js: GET /api/meetings/config (tells the client sfu on/off + wss url) and
  POST /api/meetings/token (mints a per-user, per-room LiveKit join token — hand-rolled
  HS256 JWT like the FCM/APNs tokens, no new dependency; secret stays server-side).
- docker-compose.yml: optional livekit service (single-node, no Redis), keys injected
  via LIVEKIT_KEYS from the same .env; media over published UDP 50000-50100 + TCP 7881,
  signaling proxied by NPM.
- livekit.yaml + .env.example documented.

Client (mesh->LiveKit media swap, behind the flag) lands in phase 2.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 13:11:37 +05:30
Sravan 30e354d58f feat(chat): per-message group read receipts (seen-by + read-by-all ticks)
Thread: every group message I send now carries a receipt tick — sent (1 grey)
-> seen-by-some (2 grey) -> seen-by-all (2 yellow) — computed from the per-message
seenBy the server already returns and kept live by onGroupRead. Tap the tick to see
exactly who ('Seen by X, Y') with an 'N of M' tooltip. Replaces the old last-message-
only 'Seen by' line with a universal, tappable per-message receipt.

Sidebar: the group row tick now reflects real read state (read/delivered/sent) via
memberReads vs member count, instead of a hardcoded 'sent' — and refreshes live when
the open group is read by all.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 10:57:08 +05:30
Sravan 3f791cb120 feat(chat): live typing indicators for DMs and groups
Ephemeral over the chat WebSocket (no DB). Composer emits chat-typing on/off
(throttled 2.5s, auto-stop after 4s idle / on send / on leaving the chat).
Server relays to the DM peer or fans out to group members (membership-checked).
Receiver shows 'typing…' in the conversation header subtitle and the sidebar
row preview (brand-blue italic), with per-sender auto-expiry so a dropped 'off'
can't stick. Group shows names ('Alice is typing…', 'N people are typing…').

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 17:17:03 +05:30
Sravan 820e7a08fc add publish-desktop.sh — one-command desktop installer publish from laptop
Mirrors redeploy.sh conventions (pinned host key, DEPLOY_PASS/deploy.secret/
prompt password resolution, plink discovery). Uploads the three electron-builder
artifacts via pscp to a temp dir, then docker cp's them into the app container's
/data/downloads (volume-path-independent), and verifies the public feed serves
the new version. Keeps older versions; only latest.yml is overwritten.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 16:04:22 +05:30
Sravan 609427747a docs(deploy): document scp-to-named-volume as the desktop release publish step
/data is a named Docker volume, not a host bind-mount, so the prior
scp root@host:/data/downloads/ path was wrong. Document the real host
path (/var/lib/docker/volumes/bizgaze_support_data/_data/downloads) plus
the docker cp alternative, and note latest.yml is the only overwritten file.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 15:43:44 +05:30
Sravan a1887064eb feat(chat/notif): single hover action-pill; sender DP in desktop+mobile notifications
- Message actions (reply/react/edit/delete) consolidated into ONE hover pill anchored to the
  bubble's top-right, overlapping it so on short messages the icons no longer float off into
  empty space and vanish before you can click.
- Desktop toast + mobile(FCM)/web-background push now show the sender's real DP:
  * renderer passes the DP URL through; desktop shell downloads it for the toast icon
    (canvas-drawing an external DP tainted it → initials). Desktop bumped to 0.1.4.
  * DM push payload carries icon=sender avatar; sw.js already uses it (web background),
    sendFcm sets notification.image (Android).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 18:01:32 +05:30
avinash ab48642cf6 Merge branch 'master' of https://code.bizgaze.com/Sravan/BizGaze_Remote 2026-07-02 17:58:23 +05:30
avinash b0473dee7d Merge branch 'master' of https://code.bizgaze.com/Sravan/BizGaze_Remote 2026-07-02 17:58:14 +05:30
avinash 5eb8f436c4 fix(redeploy): add host key verification to SSH command 2026-07-02 17:57:55 +05:30
Sravan 51e206279b feat(chat): edit message (#4)
Sender can edit their own text messages: a pencil action on the bubble loads the text into the
composer in an 'Editing' mode; saving updates the body, marks it 'edited', and pushes the change
live to the other side/tabs (chat-edited, mirroring delete). Adds messages.edited_at + editBody().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 17:45:20 +05:30
Sravan 9bc109528e fix(brand/ux): real brand C on header, yellow read-tick, sign-in spinner, notif DP
- #5: use the ACTUAL brand C (extracted transparent white C + gold dot from the master
  app-icon) on the blue headers instead of a hand-drawn mark; login card keeps the app icon.
- #3: read-receipt double tick on my own (blue) bubble is now brand yellow (was blue-on-blue,
  invisible).
- #2: Sign-in button shows a spinner + 'Signing in…' on submit.
- #1: web notification uses the sender/group DP URL directly as the icon (drawing an external
  DP to canvas tainted it → silently fell back to initials).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 17:39:38 +05:30
Sravan 7674c456f2 fix(brand): header shows a plain white C + gold dot on the blue bar
The header is already blue, so the app-icon-in-a-white-pill looked like blue→white→blue→white
nesting. Use a transparent mark (mark-light.svg: white C + gold dot) placed directly on the blue
header (home/index/connect/dashboard), dropping the white background + padding. share.html keeps
the full app icon (it's a light card, not the blue bar).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 17:26:22 +05:30
Sravan 952242f62b fix(brand/ux): real Biz Connect logo, branded loading screen, phone login, no blank gap
- Replace the leftover 'Your Virtual CXO' logo.png with the app icon (C mark) in every
  header (home/index/connect/dashboard) + the app icon on share.html; delete logo.png.
- Loading screen now shows the orbit mark + 'Biz Connect' wordmark + 'Loading…' (was bare).
- Keep the branded splash up until the chat list finishes loading — no blank/stuck gap
  after login (previously hidden before loadSidebar()).
- Login accepts email OR phone (field was type=email, which rejected phone numbers and so
  blocked the mobile-login that triggers the account merge). Label → 'Email or phone'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 17:16:08 +05:30
Sravan d515a562a0 fix(chat): stop echo downgrading delivered/read tick (#6); set self-chat apart (#3)
- #6: the server echoes your own sent message back over the socket; onChatMessage reset
  last_status='sent', overwriting a delivered/read that arrived first → the chat-list tick
  flipped back to single. Track last_msg_id and never downgrade the same message's tick.
- #3: pin the 'You' note-to-self chat in its own slot — tinted row + 'Note to self' tag +
  a divider separating it from the conversation list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 16:17:30 +05:30
Sravan 515411fc83 ops: persist desktop download feed on /data volume + IT release guide
- docker-compose: DOWNLOADS_DIR=/data/downloads so uploaded installers/latest.yml
  survive image rebuilds (deploy.sh) instead of being wiped.
- DEPLOY.md: step-by-step for publishing a desktop release (build → upload the
  3 feed files → verify) so the Download button + auto-update go live.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 15:46:33 +05:30
Sravan dc1915bb43 feat: live presence, delivery-tick sync, brand rollout, call fixes, desktop 0.1.3
Live presence (fixes stale in-call/status until refresh — impossible in apps):
- server broadcasts a user's status over the chat socket on connect/disconnect, call
  join/leave, and status change (chat.js broadcastPresence; signaling + routes hooks).
- client onPresence() updates the contact dot + open-chat header live.

Chat delivery ticks (#6): chat-list row now mirrors the thread (delivered→double grey,
read→blue) via a new 'with' field on the delivered relay + onChatRead/onChatDelivered.

Call fixes: no bogus 'host handed over' when a 1:1 call ends (leaveMeeting forced);
branded call-connecting + chat-thread loaders; header subtitle tracks live call state.

Notifications: web notify + sw.js use sender/group DP + brand icon (not old wordmark);
desktop shell drops Web Push so only the single native toast fires (#5).

Brand: master icon/splash/loaders wired everywhere (PWA/favicon/apple-touch/.ico),
branded login (blue + gold CTA), branded toasts (BZToast) on all pages, Electron splash.

Desktop: dev auto-targets localhost (packaged→prod); version 0.1.3 with new multi-size
icon; dropped unused node-notifier; removed home-mockup.html.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 15:43:02 +05:30
Sravan a152005b71 feat(brand): roll out master app icon, splash & branded loaders everywhere
From brand-assets/ masters (C + orbiting-dot on brand blue):
- Regenerated PWA icons (192/512/maskable), apple-touch (180), favicons
  (32/16 + root favicon.ico) from the 1024 master; bumped manifest to v3.
- Rebuilt desktop/build/icon.ico as a proper multi-size ICO (16..256,
  PNG-compressed) to fix the tiny/blurry taskbar icon.
- Updated mobile masters (resources/icon.png 1024, splash.png/splash-dark.png
  2732) for capacitor-assets to regenerate native icons/splash.
- Wired the animated branded orbit loader into the app boot 'Loading…' screen;
  added favicon/theme-color links to index + home heads.
- logo.png (horizontal wordmark) left untouched — masters have no wordmark.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 12:41:48 +05:30
Sravan 04db586dc3 feat(auth): merge mobile+email logins into one account via BizGaze person-id (#2)
Provisioning now keys the Biz Connect account on bz.bizgazeUserId (the same
value whether the person signs in with email or mobile) instead of the typed
identifier, so both logins resolve to a single contact. Legacy rows get the
person-id stamped on next login; an existing duplicate created under the same
identifier is folded in via a transactional users.mergeInto() that reassigns
all messages/memberships/reactions/votes/favorites/ownership to the survivor.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 12:35:29 +05:30
Sravan 88e897cc9c feat(chat): modern emojis via Twemoji (#5)
Loads @twemoji/api (jsDelivr) and renders emojis as Twemoji images in messages, the emoji
picker, and reactions (twemojify at each render point). Picker inserts via data-emoji so it
survives the <img> swap. Falls back to plain Unicode if the CDN is unavailable. build batch25.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 12:23:26 +05:30
Sravan 462a167438 feat(chat): self-chat 'You' — note-to-self (#4)
Pinned 'You' chat at the top of the list (always available); messaging yourself works
(to===me), with no self push/echo notification and a 'Message yourself' header. Self is
filtered from the normal contacts and shows no status dot. build batch24.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 12:05:32 +05:30
Sravan 15350c691b feat(chat): delivery ticks on the last message in the chat list (#3)
Conversations DTO now returns last_status (sent/delivered/read for DMs; sent for groups) for
my last message. The list row shows the matching tick (single/double, blue when read) and a
red 'Draft:' indicator when there's unsent text. Live 'sent' on send/receive; upgrades to
delivered/read on refresh. e2e 119.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 11:59:53 +05:30
Sravan a33ed27ffe feat(chat): per-chat drafts + fix emoji picker closing on tab switch
- Unsent text is saved per conversation (survives switching chats and reloads) and restored
  when you reopen the chat; cleared on send. (#1)
- Emoji picker: stopPropagation on tab/grid clicks so switching category no longer closes it
  (the re-render was detaching the clicked node -> outside-click handler fired). (#6)
build batch23.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 11:55:14 +05:30
Sravan 2b27889e07 fix(desktop): use Electron's native Notification (reliable click-to-open)
node-notifier/SnoreToast click callback never fired without the crashing wait mode. Switch the
chat toast to Electron's built-in Notification: shows avatar + message and its 'click' event
reliably raises the app + opens the chat. No SnoreToast, no external tools.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 11:16:35 +05:30
Sravan f8978ff796 fix(desktop): drop crashing SnoreToast reply path — clean click-to-open toast
The bundled SnoreToast crashes (0xC0000409) handling a text reply, and that crash triggered
a second (fallback) toast. Removed the direct-SnoreToast reply path entirely; the chat toast
now reliably shows avatar + message via node-notifier and opens the chat on click. Inline
text reply needs a different toast engine (deferred).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 08:58:26 +05:30
Sravan 0b58d33117 fix(desktop): drop -w — SnoreToast waits by default; -w made it fail (exit -1)
Testing showed SnoreToast blocks/waits for the toast interaction when given -pipeName; the
-w flag actually fails on this build (exit -1) which forced the reply-less fallback. Without
-w it waits, captures the typed reply, and writes it to our pipe.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 08:43:40 +05:30
Sravan 0f5e5bf00a fix(desktop): spawn SnoreToast from app.asar.unpacked (was ENOENT inside asar)
snoreExe returned the app.asar path (fs.existsSync lies about asar paths), so spawn failed
with ENOENT and always fell back to the reply-less WindowsToaster. Map to app.asar.unpacked
unconditionally so the real SnoreToast binary (with -w) runs and captures the reply.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 00:28:43 +05:30
Sravan c0f7926210 fix(desktop): direct SnoreToast -w to capture reply + WindowsToaster fallback
Root cause: node-notifier's toaster whitelist has no -w, so SnoreToast never waits and the
reply is lost. Now drive SnoreToast directly with -w + our own pipe (correct args, no
-application which had broken the toast). If the binary is missing or fails to show, fall
back to node-notifier's WindowsToaster so a toast always appears. Logs code+raw for diagnosis.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 00:06:01 +05:30
Sravan 1abf6855d8 fix(desktop): drive SnoreToast directly with own named pipe + raw reply logging
node-notifier returned an empty result for text replies. Now spawn the bundled SnoreToast
with -tb -w -pipeName against our own pipe, read the raw UTF-16LE result, and parse the
reply (keeps spaces). Logs the raw pipe string to userData/toast-debug.log to pin the
exact reply field on real hardware.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 23:44:08 +05:30
Sravan 3f209bf619 feat(desktop): real Windows inline reply via SnoreToast -tb + sender/group avatar
- node-notifier's WindowsToaster forwards raw opts to SnoreToast, so inject -tb (reply box)
  + -p (image). Reuses its named-pipe + result parsing (exit 5 = TextEntered). No pwsh needed.
  Logs the raw toast result to userData/toast-debug.log to confirm the reply field on real HW.
- home.html: notifAvatarDataUrl draws the DM sender's pic / group's DP (else colored initials)
  to a round PNG and passes it as the toast image. Reply -> sendReplyTo; click -> open chat.
- dropped powertoast (ESM + needs pwsh 7, absent here). build batch22.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 23:26:24 +05:30
Sravan ffe04e6bff fix(desktop): asarUnpack node-notifier so SnoreToast can launch from the packaged app
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 23:03:48 +05:30
Sravan 21ae3e1aa5 feat(desktop): Phase D — inline-reply notifications (Windows toast reply box)
Reply to a chat straight from the OS notification, no app switch:
- node-notifier (bundles SnoreToast) renders a native Windows toast with a reply box —
  Electron's own Notification can't do Windows inline reply.
- main.js reply-notification handler resolves {text}|{open}|null; preload exposes replyNotify.
- home.html notify() routes chat toasts through it on desktop: a typed reply -> sendReplyTo()
  POSTs to /api/messages without opening the app; a click opens the chat. Web/PWA path unchanged.
- Works only in the installed app (needs the installer's AppUserModelID). desktop 0.1.2, build batch21.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 22:36:02 +05:30
Sravan 160a66f934 fix(landing): Windows logo on the Download button (signals it's the Windows app)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 22:27:31 +05:30
Sravan 9ff2ef5d48 feat(dashboard): "App installs" view + compact top-right Download button
- dashboard.html: admin "App installs" card — table of user · platform · version · OS ·
  first/last seen, from GET /api/v1/admin/installs (loadInstalls).
- index.html: replaced the long inline link with a compact white "Download app" button in
  the blue top header (top-right); hidden when already inside the desktop app.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 22:16:38 +05:30
Sravan 899770ed02 feat: Windows download link + self-served update feed + install tracking
Downloads/updates:
- config: DOWNLOADS_DIR (override to a mounted volume in prod).
- static.js: serves /downloads/* (installer, latest.yml, .blockmap) with range support for
  resumable + differential auto-updates; /download/windows redirects to the current .exe
  (stable link). Landing page gets a "Download the Windows desktop app" button (hidden in-app).

Install tracking (who installed the app):
- db app_installs + repos.appInstalls (upsert by install_id, fills in the user on sign-in).
- POST /api/v1/telemetry/install (records install + user once authenticated);
  GET /api/v1/admin/installs (admin: list installs with user/version/os/last-seen).
- desktop main.js: stable per-install id in userData, exposed via preload
  (bizConnectNative.installId/version/os); home.html reportInstall() posts it after login.
- e2e: +2 checks (telemetry recorded, admin sees it). 119/119. build batch20.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 21:28:53 +05:30
Sravan e5c94ebf6d fix: login submits on Enter (real <form>) + desktop notifications show "Biz Connect"
- home.html: login is now a real <form> with a submit button, so Enter (or click) both
  submit natively — replaces the ad-hoc keydown handler. (build batch19; header stays removed)
- desktop/main.js: app.setAppUserModelId('com.bizgaze.connect.desktop') so Windows resolves
  the installed shortcut and toasts read "Biz Connect" instead of "electron.app.BizConnect".
- desktop version → 0.1.1; installer rebuilt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 18:19:01 +05:30
Sravan e84e5eb241 feat(desktop): open the landing page (pre-login), not /home directly
The desktop app was hardcoded to /home, so it jumped straight to the login form and
skipped the 'before login' landing (no-login 'Share my screen' + sign-in). Now loads / —
same entry as the website; it redirects logged-in users to /home.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 17:55:49 +05:30
Sravan 07286899c5 chore(desktop): one-click installer (no scope/folder prompts)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 17:37:58 +05:30
Sravan c605304c67 chore(desktop): add author field (cleaner electron-builder output)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 17:21:54 +05:30
Sravan 1500d42cd2 feat(desktop): packaging + self-hosted auto-update (electron-builder/updater)
- package.json build config: NSIS installer, app icon, generic publish provider →
  https://remote.bizgaze.com/downloads/ (self-hosted update feed).
- main.js: electron-updater checks the feed on launch + every 6h, downloads in the
  background, installs on restart. Active only in packaged builds.
- build/icon.ico app icon; PACKAGING.md documents build/release/signing.
- Key design: web/UI changes reach installed apps instantly (they load the live server);
  only native shell changes need an auto-updated build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 17:03:18 +05:30
Sravan 2404538270 fix(ui): modern thin scrollbars app-wide (remove classic up/down arrows)
Only the chat LIST had styled scrollbars; the chat message area and every other scroll
region fell back to the OS scrollbar, which in the Electron/Windows shell shows classic
up/down stepper arrows. Added a global ::-webkit-scrollbar style (thin, rounded thumb,
scrollbar-button hidden) + scrollbar-width:thin to home.html, share.html, connect.html,
dashboard.html. (home build batch18)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 16:46:40 +05:30
Sravan 1ca0b836e1 feat(desktop): unread-chat count badge on the taskbar icon
Mirrors the rail's unread-chat count onto the Windows taskbar icon (overlay) and the
macOS/Linux dock badge. updateRailUnread() draws a small red count badge on a canvas
and hands it to the shell via bizConnectNative.setUnread(count, dataUrl); main sets it
with win.setOverlayIcon + app.setBadgeCount. Clears at 0, shows 99+ past 99. No-op in a
browser/mobile. (home.html build batch17)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 16:28:15 +05:30
Sravan 5a98ae4d34 feat(desktop): media/notification permissions + notification raises the app
- desktop/main.js: grant media (camera/mic), display-capture, notifications, clipboard,
  fullscreen, pointerLock for the app origin (Electron denies these by default, which
  silently broke meetings' camera/mic). Adds setPermissionRequestHandler +
  setPermissionCheckHandler on the app session.
- Clicking a notification now raises + focuses the window: preload exposes
  bizConnectNative.focusApp(), main handles 'focus-window' IPC, and the web notify()
  onclick calls it when running in the desktop shell. (home.html build batch16)
- CLIENTS.md: Phase D — inline-reply notifications (Windows Toast RemoteInput /
  Android RemoteInput / iOS UNTextInputNotificationAction) queued right after packaging.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 16:16:40 +05:30
Sravan 7a2ab3fc8d fix(agent): remote-control input now works (data channel + nut-js API)
Two latent bugs that broke input control on any setup:
- Data channel was created by the viewer (the answerer), so the agent's offer had
  no SCTP m-line and the channel never opened -> no input reached the agent. The
  agent (offerer) now creates the 'input' channel; the viewer receives it.
- inject.js used nut.screen.getResolution() which doesn't exist in this nut-js;
  switched to screen.width()/height() with per-session caching.

Verified end-to-end locally: screen streams + mouse injection moves the remote cursor.
Also commits desktop/ + mobile/ package-lock.json from client installs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 15:47:09 +05:30
Sravan 73b40a5d9f feat(mobile): Android prep — icons/splash assets, permissions, FCM setup
- resources/: 1024 icon.png + 2732 splash.png/splash-dark.png generated from the
  PWA icon + brand blue; wired @capacitor/assets (npm run assets) + splash-screen plugin.
- ANDROID_SETUP.md: end-to-end guide (SDK setup, cap add android, manifest permissions,
  Firebase/google-services.json + Gradle, run, Play AAB build) for package com.bizgaze.connect.
- android-permissions.xml: paste-ready POST_NOTIFICATIONS + camera/mic/WebRTC perms.
- mobile/README links the guide; setup adds `npm run assets`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 20:18:11 +05:30
Sravan 7ae0cacf74 feat(push): wire Capacitor native push into the web UI
home.html: in a Capacitor app shell, setupPush() now uses the native FCM/APNs path
instead of Web Push — requests permission, registers, POSTs the OS device token to
/api/v1/devices, deep-links on notification tap (selectChat), and unregisters the
token on logout. Web Notification prompts are suppressed on native. Fully inert in a
normal browser (Web Push unchanged). build batch15.

CLIENTS.md Phase B push items checked off.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 19:56:59 +05:30
Sravan 4c75db2029 feat(push): native device-token registration + FCM/APNs senders
- /api/v1/devices (register) + /api/v1/devices/remove — auth-required, validates
  platform (ios|android), upserts by token; e2e covers register/validation/auth/remove.
- db device_tokens table + deviceTokens repo.
- push.js: FCM HTTP v1 (Android) and APNs token-based over HTTP/2 (iOS) folded into
  the single push.sendToUser path alongside Web Push; each transport independently
  config-gated and a silent no-op without creds. Dead tokens pruned on 404/410.
- docs: CLIENTS.md Phase B updated; DEPLOY.md env table adds FCM/APNs vars.

e2e 117/117.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 18:23:10 +05:30
Sravan 593a4677b6 feat(clients): scaffold mobile (Capacitor) + desktop (Electron) shells
Plan + decisions in CLIENTS.md (parallel mobile+desktop; desktop = technician
client + existing remote-control agent host; mobile = Capacitor wrap).

- desktop/: Electron technician client — loads the live Connect UI, native
  screen capture via setDisplayMediaRequestHandler, persisted session, external
  links to browser; electron-builder config for Win/Mac/Linux installers.
- mobile/: Capacitor project — server.url loads Connect UI, push/camera/status-bar
  plugins declared, www splash fallback; iOS/Android added via `cap add`.
- Reuses the existing /api/v1 + Bearer auth backend; no web-code changes.
- .gitignore: ignore generated mobile/android, mobile/ios platform dirs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 17:49:41 +05:30
Sravan f517c153c1 docs(deploy): add operational guardrails + env/verification checklist for IT
Single-instance requirement, ALLOW_LOCAL_LOGIN-off, server-side directory token,
no-store HTML, Node>=22.5/web-push, required env vars (SSO/VAPID/TURN), and the
window.__BUILD per-release verification step.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 17:06:08 +05:30
Sravan 06f0b08a18 feat(chat): rich shared-media view, status selector, drag-drop upload + fixes
Chat / shared media:
- Media/Docs/Links: clean underline tabs (green active), audio & video now
  classified as Media and rendered as tiles (download + headphone/play +
  duration) instead of broken-image glyphs; image thumbnails -> lightbox
- Drag-and-drop a file/video/image onto a conversation to send it
- Fix: removed #chatPanel{position:relative} override that collapsed the
  conversation pane (messages spilled into a clipped right-edge strip)
- "Media, links & docs" row cleaned up (no folder/placeholder icon); media
  popup keeps the back arrow, drops the redundant close button

Presence / status:
- Single current-status row with an arrow that expands Available/Away/On leave
- On leave = circle with minus, In a call = solid red indicators
- Fix: selected-status tick now follows the chosen option

Icons: added headphones + play; bumped icons.js cache-bust to v4

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 17:01:15 +05:30
Sravan e9e5c7f406 fix(pwa): white icon tile for contrast + cache-bust icon URLs (v2)
Logo was dark-on-blue (low contrast); now centered on a white tile like the
header treatment. Icon URLs versioned (?v=2) so browsers/installs fetch the new
ones. Build marker -> pwa2.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 15:02:11 +05:30
Sravan a427be9b6f fix(cache): send Cache-Control: no-store on all JSON/404 responses
Prevents a 404 (e.g. /manifest.json fetched before deploy) from being cached on
a device and persisting after the file exists — the cause of the manifest 404
on mobile but not desktop.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 17:58:23 +05:30
Sravan b576ed372a feat(pwa): installable app (Add to Home Screen) for Android + iOS
- manifest.json (standalone display, theme color, maskable icons 192/512).
- generated square icons + apple-touch-icon (180) from the logo.
- apple-mobile-web-app + theme-color meta in home.html.
- sw.js gets a no-op fetch handler so it meets installability criteria (still
  no caching). static.js serves .json/.webmanifest with correct MIME.
- Installing as a PWA also unlocks Web Push on iOS (Apple requires Add to Home Screen).
Build marker -> pwa1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 17:13:01 +05:30
Sravan f4a23ae805 fix(cache): serve HTML with no-store so deploys reach browsers without a hard refresh
Browsers were serving a cached old home.html on normal reloads (only incognito/
hard-refresh got the new one). HTML now sends Cache-Control: no-store; versioned
assets keep ETag revalidation. Bumps build marker to push4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 16:30:17 +05:30
Sravan f7ddb2e7ae fix(push): wait for active SW before subscribe + log every step (subscribe was failing silently)
subscribePush() swallowed all errors, so if pushManager.subscribe() failed
(e.g. called before the service worker was active) nobody ever subscribed and
there was no trace. Now: await serviceWorker.ready before subscribing, and
console.log/warn each step so the real failure is visible. Server send path
verified independently (web-push builds valid VAPID requests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 13:57:03 +05:30
Sravan 5edb3fa241 fix(chat): dedup sent message in sendMessage too (WS echo can beat the POST response)
The server echoes the sender's own message over WS before returning the HTTP
response, so onChatMessage could append it before sendMessage's await resolved,
then sendMessage appended again -> double. Both append paths now dedup by id.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 13:39:42 +05:30
Sravan 88d7657364 chore: add build marker (window.__BUILD) to home.html for deploy verification
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 12:38:35 +05:30
Sravan 1272b81cee feat(push): Web Push notifications for backgrounded/closed/mobile tabs
Page-level Notifications can't fire when a tab is frozen/closed (and never on
mobile), which is why recipients on another tab/app got nothing. Adds a
notification-only service worker (sw.js, no caching) + Web Push:

- push.js: optional web-push wrapper (no-op unless web-push installed AND
  VAPID_PUBLIC_KEY/VAPID_PRIVATE_KEY set -> app unaffected if unconfigured).
- push_subscriptions table + R.pushSubs repo (upsert by endpoint, prune dead).
- /api/push/vapid|subscribe|unsubscribe; DM + group message routes also send a
  Web Push to recipients.
- Client registers /sw.js, subscribes when permission granted; hidden-tab popups
  are left to push to avoid double-notifying (pushActive flag); SW suppresses the
  OS popup when a tab is visible. Removes the old code that unregistered SWs.

Requires (prod, once): npm install + VAPID_PUBLIC_KEY/VAPID_PRIVATE_KEY/VAPID_SUBJECT env.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 21:58:49 +05:30
Sravan d50d4bde47 fix(icons): proper end-call (hang-up) glyph + cache-bust icons.js (v3)
- callEnd is now a rotated-handset hang-up icon (was a phone-off placeholder).
- All pages reference /icons.js?v=3 so browsers/proxies fetch the corrected
  file instead of a stale cached copy (fixes 'old end icon' + icons not
  appearing until a re-render when an old/404 icons.js was cached).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 18:47:24 +05:30
Sravan 1f4516d69b fix(chat): dedup own echoed message so sent messages don't show twice
Server echoes your own message back over WS (multi-tab/device sync) and
sendMessage already appended it optimistically; onChatMessage now skips the
append if the id is already in the thread.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 18:06:00 +05:30
Sravan fcd6a60baa fix(prod): add missing public/icons.js (was untracked -> 404 in prod)
icons.js was never committed (untracked, lost from disk), so every page
404'd /icons.js and stalled at Loading. Restored from commit e05a788 and
added 16 icons referenced by current code but absent in that snapshot
(bell, bold, italic, strikethrough, code, list, listOrdered, type, crown,
checkCheck, calendarX, calendarClock, fileText, record, callEnd, settings).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 17:41:44 +05:30
150 changed files with 20637 additions and 1631 deletions
+21
View File
@@ -21,3 +21,24 @@ TURN_CREDENTIAL=
# Optional: BizGaze webhook endpoint for session events.
# BIZGAZE_WEBHOOK_URL=
# Optional: LiveKit SFU for meetings (scales past the ~5-peer P2P mesh). Set ALL THREE to enable;
# leave unset to keep the built-in mesh. The app mints join tokens with the secret (server-side
# only); the same key/secret feed the livekit container via LIVEKIT_KEYS in docker-compose.
# Generate a key/secret pair: two random strings, e.g. `openssl rand -hex 16` for each.
# LIVEKIT_URL=wss://livekit.bizgaze.com
# LIVEKIT_API_KEY=
# LIVEKIT_API_SECRET=
# Optional: PostgreSQL data store. Leave unset to use the built-in SQLite file (DB_PATH). To move to
# Postgres: set POSTGRES_PASSWORD (used by the bizgaze-postgres container AND the URL below), then set
# DATABASE_URL + DB_BACKEND=pg after running db/migrate-sqlite-to-pg.js. See db/schema.pg.sql.
# POSTGRES_PASSWORD=
# DATABASE_URL=postgres://bizgaze:PASSWORD@bizgaze-postgres:5432/bizgaze
# DB_BACKEND=pg
# Optional: cross-instance real-time (chat/presence) fan-out via Redis, for running MULTIPLE app instances.
# Leave unset for single-instance (in-memory pub/sub, the default). To scale out: start the redis service
# (`docker compose --profile scale up -d`), then set both below + a sticky load balancer for /ws.
# PUBSUB_BACKEND=redis
# REDIS_URL=redis://bizgaze-redis:6379
+13
View File
@@ -29,10 +29,19 @@ dist/
build/
out/
# Native client generated/build artifacts (Capacitor adds platform dirs; Electron builds to dist)
mobile/android/
mobile/ios/
# Keep the desktop app icon (a build RESOURCE), even though the global build/ rule ignores it
!desktop/build/
!desktop/build/**
# Runtime media (created at startup by config.js)
server/recordings/
server/transcripts/
server/uploads/
server/downloads/
# OS files
.DS_Store
@@ -41,3 +50,7 @@ Thumbs.db
# Editor
.vscode/
.idea/
# Firebase service-account keys (SECRET private key — NEVER commit)
**/*firebase-adminsdk*.json
**/*service-account*.json
+15 -6
View File
@@ -12,8 +12,11 @@ Roadmap: grow into a communication platform (meetings + persistent chat) for
registered BizGaze users.
## Tech stack (intentionally minimal — keep it this way)
- **Node.js >= 22.5**, single npm dependency: `ws` (WebSocket).
- **Built-in `node:sqlite`** (no native modules). DB file: `server/data.db`.
- **Node.js >= 22.5**. npm deps: `ws`, `pg`, `redis`, `web-push` (+ optional `nodemailer`).
- **PostgreSQL** via the async adapter (`server/dbx.js``server/db/pg.js`). SQLite was RETIRED 2026-08-12:
there is now ONE schema source of truth, **`server/db/schema.pg.sql`** — every schema change goes there
(and post-cutover COLUMNS need an explicit `ALTER TABLE … ADD COLUMN IF NOT EXISTS`, since the file is
applied idempotently on every boot and `CREATE TABLE IF NOT EXISTS` won't alter an existing table).
- **WebRTC** peer-to-peer for media (screen video + voice + data channels).
- **No build step, no framework.** Each page is a single self-contained HTML file
with inline `<style>` and `<script>`. Do not introduce React/bundlers.
@@ -30,9 +33,10 @@ server/
routes.js # HTTP JSON API (/api/*, /sso) -> { "METHOD /path": handler } map
static.js # static file serving + authenticated recording/transcript downloads
signaling.js # WebSocket signaling (consent + SDP/ICE relay)
repos.js # data-access layer — ALL SQL lives here (tenant-scoped)
repos.js # data-access layer — ALL SQL lives here (tenant-scoped, async)
bizgaze.js # BizGaze identity provider (validate login, env-gated)
db.js # node:sqlite schema + idempotent migrations
dbx.js # async DB adapter facade -> db/pg.js (Postgres; only backend)
db/pg.js # Postgres backend; db/schema.pg.sql = the single schema source of truth
auth.js # scrypt hashing, token/id generation, TOTP helpers
package.json # { "dependencies": { "ws": "^8.18" }, engines node>=22.5 }
test/e2e.js # 21-check backend e2e (register->login->session->signaling->audit)
@@ -48,11 +52,16 @@ server/
transcripts/ # saved transcripts (.txt) [created at runtime]
```
Architecture/roadmap detail lives in `ARCHITECTURE.md`. Backend SQL must go through
`repos.js` (never inline in routes/signaling). Run `node test/e2e.js` after backend edits.
`repos.js` (never inline in routes/signaling). ANY schema change goes in `db/schema.pg.sql` (see stack note).
After backend edits, run the tests against a DISPOSABLE Postgres (they no longer bundle SQLite):
`DATABASE_URL=postgres://…/bizgaze_test node test/db-smoke.js`.
## Run locally
```
cd server && npm install && node server.js
# Start a local Postgres (or use the compose one), then:
docker compose up -d bizgazepg
cd server && npm install
DB_BACKEND=pg DATABASE_URL=postgres://bizgaze:bizgaze_local@localhost:5432/bizgaze node server.js
# HTTP on :8090 (HTTPS on :8443 only if cert.pem + key.pem exist in server/)
# Env: ALLOW_REGISTRATION=1 opens the first-team registration
```
+128
View File
@@ -0,0 +1,128 @@
# Biz Connect — Mobile & Desktop clients
Native clients for Biz Connect. **The web app is the single source of truth for the UI**;
each native client is a thin shell that loads that UI and adds the capabilities a browser
can't provide (background push, native screen capture, OS input injection, store presence).
Decisions (set by the user 2026-06-30):
- **Build mobile and desktop in parallel.**
- **Desktop = both pieces:** the remote-control **host** (existing `agent/`) *and* a
**technician desktop client** (`desktop/` — Connect in a window).
- **Mobile = Capacitor wrap** of the existing web UI (one codebase), not a native rewrite.
Backend is already client-ready (see [ARCHITECTURE.md](ARCHITECTURE.md) Phase 2): `/api/v1`,
`Authorization: Bearer` + refresh tokens, API keys, per-tenant webhooks. The one remaining
backend gap is **APNs/FCM push** for native mobile (needs Apple/Google credentials).
---
## Components
| Dir | Client | Tech | What it adds over the browser |
|-----|--------|------|-------------------------------|
| `mobile/` | iOS + Android app | **Capacitor** loading the Connect UI | Native push (FCM/APNs), camera/mic perms, store distribution, screen capture (ReplayKit / MediaProjection) |
| `desktop/` | Technician client | **Electron** loading the Connect UI | Native full-screen capture for screen-share; windowed app; later: tray, auto-update |
| `agent/` | Remote-control **host** (customer) | **Electron + nut-js** *(exists, v0.2.0)* | Screen capture + **OS input injection** so a technician can control the machine |
All three authenticate through the same `/api/v1` access layer (Bearer token for mobile/desktop,
the existing consent/enroll flow for the agent).
---
## Why "wrap the web UI" (not rewrite)
The Connect UI is already an installable PWA built from server-rendered single-file HTML.
Pointing a native webview at the server origin means **every relative `/api` and `/ws` URL
keeps working unchanged** — zero web-code changes — while native plugins augment it through
the JS bridge. One codebase, three shells.
Trade-off: a server-URL shell needs network at launch (fine for a remote-support tool) and
some stores scrutinise "just a website". We mitigate by shipping real native capabilities
(push, screen capture, deep links), and can later switch to **bundled** web assets + an
absolute API base if offline-launch or store policy requires it.
---
## Phased plan
### Phase A — Shells that load the live app ← start here
- [ ] `desktop/` Electron client: `loadURL(server)`, `setDisplayMediaRequestHandler` so
screen-share works natively, external links → browser, persisted session.
- [ ] `mobile/` Capacitor project: `server.url` → Connect, app icons/splash, status bar.
- [ ] Inject `window.__NATIVE__ = 'desktop' | 'ios' | 'android'` so the web UI can adapt
(e.g. hide the PWA "install" prompt, enable native push instead of Web Push).
### Phase B — Native capabilities
- [x] **Push backend:** device-token registration (`POST /api/v1/devices`,
`/api/v1/devices/remove`) + native senders folded into the single `push.sendToUser`
path — **FCM v1** (Android) and **APNs** token-based over HTTP/2 (iOS), each
config-gated and a no-op until creds are set. Web Push (VAPID) unchanged. Dead
tokens are pruned on 404/410/UNREGISTERED. (db `device_tokens`, repo `deviceTokens`,
`push.js`.) *Mobile app still needs the Capacitor push plugin wired + FCM/APNs creds
to deliver end-to-end.*
- [x] **Capacitor push plugin wired** in the web UI (`setupNativePush` in home.html):
inside the app it requests permission, registers, and `POST`s the FCM/APNs token to
`/api/v1/devices`; notification taps deep-link via `selectChat`; logout unregisters the
token. Web Push is skipped when running natively. Inert in a normal browser. *Activates
once the Capacitor Android/iOS app is built and FCM/APNs creds are set.*
- [ ] **Mobile screen capture** for "Share Screen" from a phone (ReplayKit / MediaProjection plugin).
- [ ] **Deep links / universal links** so a session/meeting link opens the app.
### Phase C — Packaging & distribution *(needs external accounts)*
- [ ] Desktop installers via **electron-builder** (Win NSIS + Mac dmg); **code-signing**
(Win EV cert, Apple Developer ID + notarization).
- [ ] Mobile store builds: **Apple Developer** ($99/yr) + **Google Play** ($25 once);
signing keys; store listings & privacy disclosures.
- [ ] Agent host installer (signed) for customers.
- [ ] Auto-update channels.
### Phase D — Inline-reply notifications (Teams-style) *(right AFTER packaging)*
Reply to a chat directly from the OS notification, without opening the app. Cross-platform:
- [x] **Desktop (Windows):** native Windows toast with a **reply box** via **node-notifier**
(bundles SnoreToast). main.js `reply-notification` handler → preload `replyNotify`
home.html `notify()` routes chat toasts through it: a typed reply calls `sendReplyTo`
(POST /api/messages) without opening the app; clicking opens the chat. Uses the installer's
AppUserModelID, so it only works in the **installed** app. *Needs a live test in the
installed app (can't drive a real Windows toast from CI).*
- **Android:** notification action with **`RemoteInput`** (direct reply) on the FCM message.
- **iOS:** **`UNTextInputNotificationAction`** on the APNs notification category.
All three hand the typed text to the same send path. Depends on Phase B push + Phase C packaging.
---
## Build & run
### Desktop (technician client)
```bash
cd desktop
npm install
SERVER_URL=https://remote.bizgaze.com npm start # or http://localhost:8090 in dev
npm run dist # build installers (needs electron-builder + certs)
```
### Mobile (Capacitor)
```bash
cd mobile
npm install
npx cap add android # needs Android Studio + SDK
npx cap add ios # needs macOS + Xcode
npx cap sync
npx cap open android # build/run from Android Studio
npx cap open ios # build/run from Xcode
```
Set the server origin in `capacitor.config.json` (`server.url`).
### Agent host (existing)
```bash
cd agent
npm install
SERVER_URL=https://remote.bizgaze.com AGENT_ENROLL_TOKEN=<token> npm start
```
---
## What's gated on you (external, can't be done from code alone)
- **Apple Developer** + **Google Play** accounts (mobile store builds & push).
- **Code-signing certificates** (Windows EV, Apple Developer ID) for trusted installers.
- **FCM/APNs credentials** for native push.
Everything else — the shells, the device/push backend, native plugin wiring — is built here.
+164
View File
@@ -21,6 +21,52 @@ Server facts:
---
## Operational guardrails (read before every deploy)
These are correctness/security invariants, not preferences. Breaking one degrades
or breaks the app even if the container starts fine.
- **Single instance only.** Chat, presence, and meeting (WebRTC) signaling use an
**in-process** registry. Do **not** scale to multiple replicas or place several
instances behind a round-robin load balancer — users on different processes
can't see each other's messages/calls. One container, one process.
- **`ALLOW_LOCAL_LOGIN` must NOT be set in production.** It's a dev-only escape
hatch that bypasses BizGaze SSO and the local-password lockout. Production logs
in via BizGaze only.
- **`BIZGAZE_DIRECTORY_TOKEN` is server-side only** — it's used by the server to
proxy directory lookups and must never be exposed to the browser/client.
- **HTML is served `Cache-Control: no-store` by design** so new builds land
immediately. Do not add an HTTP/CDN cache layer that caches `.html`. Static JS
(`icons.js`) is cache-busted with a `?v=` query, currently `?v=4`.
- **Node ≥ 22.5** (the image uses `node:24-alpine`) — required for the built-in
`node:sqlite` that `db.js` relies on. `deploy.sh` rebuilds the image, so
`npm install` (incl. `web-push`) happens automatically; no manual install.
- **No DB migration is required** for routine UI/chat releases. The `data.db`
volume persists across rebuilds; schema changes (when present) auto-apply on boot.
### Env vars to confirm in `.env`
`.env` lives only on the server (never in git) and must contain, beyond the TURN
secrets already documented:
| Group | Vars | Needed for |
|-------|------|-----------|
| Login / SSO | `BIZGAZE_LOGIN_URL`, `BIZGAZE_DIRECTORY_URL`, `BIZGAZE_DIRECTORY_TOKEN`, `SSO_SECRET` | BizGaze sign-in + directory search |
| Web Push | `VAPID_PUBLIC_KEY`, `VAPID_PRIVATE_KEY`, `VAPID_SUBJECT` | Background push for browsers / installed PWA |
| Native push — Android | `FCM_SERVICE_ACCOUNT` (path to / inline Firebase service-account JSON) | FCM push to the Android app |
| Native push — iOS | `APNS_KEY` (path/inline `.p8`), `APNS_KEY_ID`, `APNS_TEAM_ID`, `APNS_BUNDLE_ID`, `APNS_PRODUCTION=1` | APNs push to the iOS app |
| Calls | `TURN_URLS` / `TURN_SECRET` (or `TURN_USERNAME`+`TURN_CREDENTIAL`) | Audio/video across NATs & mobile networks |
If the VAPID keys are missing, push silently no-ops (the app still runs). Push on
iOS additionally requires the user to **Add to Home Screen** (iOS 16.4+) — an
end-user step, not ops.
### Per-release verification
After deploy, open the app and check the browser console logs the expected build,
e.g. `Biz Connect build 2026-06-30-batch14`. That confirms the new HTML is being
served (not a stale cache).
---
## One-time bootstrap (server → git clone)
Run **once** to convert the existing folder into a git checkout without losing the
@@ -84,6 +130,124 @@ ssh -p 61 root@118.95.33.89 'cd /opt/bizgaze-support && ./deploy.sh'
---
## Desktop app releases (make the installer live + auto-update)
Web/UI changes reach the desktop app instantly (it loads the live site). Only a change to the
**native shell** (`desktop/`) needs a new installer. Publishing one both powers the site's
"Download for Windows" button and pushes an auto-update to already-installed apps.
The installer feed is served from `DOWNLOADS_DIR`, which docker-compose now points at
`/data/downloads` (the persistent volume) so uploads survive `deploy.sh` rebuilds. **First time
only**, redeploy once after pulling so the container picks up `DOWNLOADS_DIR`, then create the dir:
```bash
ssh -p 61 root@118.95.33.89 'docker exec bizgaze-support mkdir -p /data/downloads'
```
**Each desktop release:**
1. Build on a Windows machine (needs `desktop/build/icon.ico`; bump `desktop/package.json`
`version` first):
```bash
cd desktop && npm install && npm run dist
```
Output in `desktop/dist/`: `Biz Connect Setup <ver>.exe`, `…​.exe.blockmap`, `latest.yml`.
2. Upload those **three** files into the container's `/data/downloads` (all three are required —
`latest.yml` is the update manifest, `.blockmap` enables differential updates). `/data` is a
**named Docker volume** (`bizgaze_support_data`), not a host bind-mount, so its real host path
is `/var/lib/docker/volumes/bizgaze_support_data/_data`. scp straight into it — one step, no
restart needed (the server serves the folder live):
```powershell
# from the repo's desktop\dist folder on the Windows build machine
scp -P 61 "Biz Connect Setup <ver>.exe" "Biz Connect Setup <ver>.exe.blockmap" latest.yml `
root@118.95.33.89:/var/lib/docker/volumes/bizgaze_support_data/_data/downloads/
```
Alternatively, scp to `/tmp` on the server and `docker cp` in (avoids touching the volume path):
```bash
docker cp "/tmp/Biz Connect Setup <ver>.exe" bizgaze-support:/data/downloads/
docker cp "/tmp/Biz Connect Setup <ver>.exe.blockmap" bizgaze-support:/data/downloads/
docker cp "/tmp/latest.yml" bizgaze-support:/data/downloads/
```
Keep both versions' `.exe`/`.blockmap` on the server (older blockmaps let installed apps pull
deltas); only `latest.yml` is overwritten — there must be exactly one, pointing at the newest.
3. Verify:
```bash
curl -I https://remote.bizgaze.com/download/windows # 302 → the new .exe
curl https://remote.bizgaze.com/downloads/latest.yml # shows version <ver>
```
Installed apps check the feed on launch and every 6h, download in the background, and update on
next restart. Keep the `.exe` + `.blockmap` that `latest.yml` references on the server; older
versions can be pruned. Note: the installer is **not code-signed**, so Windows SmartScreen shows
an "unknown publisher" warning — supply an EV/OV code-signing cert to remove it (see
`desktop/PACKAGING.md`).
---
## Meetings SFU (LiveKit) — optional, scales meetings past ~5 people
By default meetings use a **P2P mesh** (each person sends video to every other person), which
degrades past ~5 participants. Enabling **LiveKit** routes media through an SFU so each person
uploads once — rooms scale to 20-50+. It's **fully optional and config-gated**: until you set the
three `LIVEKIT_*` vars, the app keeps using the mesh, unchanged. The `livekit` service is already
in `docker-compose.yml`; these steps turn it on.
**1. Generate an API key + secret** (any two random strings; keep them secret):
```bash
echo "LIVEKIT_API_KEY=$(openssl rand -hex 8)"
echo "LIVEKIT_API_SECRET=$(openssl rand -hex 24)"
```
Add those two lines to the server's `.env`, plus the public signaling URL:
```
LIVEKIT_URL=wss://livekit.bizgaze.com
LIVEKIT_API_KEY=<from above>
LIVEKIT_API_SECRET=<from above>
```
The app mints join tokens with the secret (server-side only); the same key/secret reach the
`livekit` container via `LIVEKIT_KEYS` (docker-compose reads them from this same `.env`).
**2. DNS**: point `livekit.bizgaze.com` (A record) at the server — `118.95.33.89`.
**3. NPM proxy host** for the signaling WebSocket (LiveKit media does NOT go through NPM):
- Domain `livekit.bizgaze.com` → **Forward to** `livekit:7880` (scheme `http`).
- **Websockets Support: ON**. Request an SSL cert (Let's Encrypt) + Force SSL.
- NPM reaches `livekit:7880` by container name — both are on `nginx_proxy_manager_default`.
**4. Media ports — NAT port-forward (REQUIRED here).** This box sits **behind NAT**: its only
interface is a private `192.168.88.61`; the public `118.95.33.89` (DNS) is mapped by an upstream
gateway. WebRTC media can't traverse NPM (L7), so the gateway/router must forward the media ports
to the box. To keep the ask minimal, LiveKit is configured for **one** UDP port + one TCP fallback:
Ask whoever controls the network/gateway to forward, from `118.95.33.89` → `192.168.88.61`:
| Port | Proto | Purpose |
|------|-------|---------|
| 50000 | UDP | WebRTC media (all participants mux over this one port) |
| 7881 | TCP | WebRTC-over-TCP fallback (restrictive client networks) |
`livekit.yaml` already pins `rtc.node_ip: 118.95.33.89` (auto-detect would pick the wrong outbound
IP behind this NAT). The host's local `ufw` is inactive, so no host-firewall change is needed — the
only requirement is the upstream port-forward above. Until it exists, signaling connects but media
won't flow (participants see each other's tiles but no video/audio).
**5. Deploy** (the livekit service is behind a `sfu` compose profile, so it stays dormant on a
normal deploy — start it explicitly):
```bash
cd /opt/bizgaze-support && ./deploy.sh # rebuilds/starts the app as usual
docker compose --profile sfu up -d # additionally starts the livekit container
docker compose ps # expect both bizgaze-support AND bizgaze-livekit "Up"
```
**6. Verify**:
```bash
curl https://remote.bizgaze.com/api/meetings/config # expect {"sfu":true,"url":"wss://livekit.bizgaze.com"}
curl -I https://livekit.bizgaze.com # 200/426 (WS endpoint reachable via NPM+TLS)
docker logs bizgaze-livekit --tail 30 # "starting LiveKit server", no key errors
```
Then start a meeting in the app and confirm 3+ participants see each other. To roll back to mesh,
just remove the `LIVEKIT_*` vars from `.env` and redeploy — no code change.
---
## Verify
```bash
+7 -3
View File
@@ -1,7 +1,11 @@
# BizGaze Support — server image
# Node 24 ships node:sqlite as a stable built-in (no flag), which db.js relies on.
# Data store is PostgreSQL (DB_BACKEND=pg; the `pg` client is a prod dependency installed below). SQLite was
# retired 2026-08-12 — one schema source of truth (db/schema.pg.sql), no dual-maintenance drift.
FROM node:24-alpine
# ffmpeg: server-side video poster thumbnails (see static.js /thumbs/<id>). Small on Alpine.
RUN apk add --no-cache ffmpeg
ENV NODE_ENV=production
WORKDIR /app/server
@@ -12,9 +16,9 @@ RUN npm install --omit=dev --no-audit --no-fund
# App source
COPY server/ ./
# Served HTTP port (NPM terminates TLS and proxies here). DB lives on a volume.
# Served HTTP port (NPM terminates TLS and proxies here). The DB is Postgres (DATABASE_URL, set via .env);
# the /data volume holds uploads / recordings / transcripts / downloads (see docker-compose.yml).
ENV PORT=8090
ENV DB_PATH=/data/data.db
EXPOSE 8090
CMD ["node", "server.js"]
+10 -2
View File
@@ -41,10 +41,17 @@ function mapKey(key, code) {
return null;
}
// Cache the screen size (this nut-js exposes screen.width()/height(), not getResolution()).
// Recomputed once per session (cleared in releaseAll) so a resolution change is picked up.
let _screen = null;
async function screenSize() {
if (!_screen) _screen = { w: await nut.screen.width(), h: await nut.screen.height() };
return _screen;
}
async function moveTo(xNorm, yNorm) {
if (!nut) return;
const { width, height } = await nut.screen.getResolution();
await nut.mouse.setPosition(new nut.Point(Math.round(xNorm * width), Math.round(yNorm * height)));
const { w, h } = await screenSize();
await nut.mouse.setPosition(new nut.Point(Math.round(xNorm * w), Math.round(yNorm * h)));
}
function buttonEnum(b) {
@@ -98,6 +105,7 @@ async function releaseAll() {
if (!nut) { pressed.clear(); return; }
for (const k of pressed) { try { await nut.keyboard.releaseKey(k); } catch {} }
pressed.clear();
_screen = null;
}
module.exports = { inject, releaseAll, available, mapKey };
+5 -5
View File
@@ -104,14 +104,14 @@ async function startStreaming() {
pc = new RTCPeerConnection({ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] });
localStream.getTracks().forEach((t) => pc.addTrack(t, localStream));
// Viewer creates the input data channel; we receive it here.
pc.ondatachannel = (ev) => {
const ch = ev.channel;
ch.onmessage = (msg) => {
// The agent is the OFFERER, so it must create the input data channel — otherwise the
// SCTP m-line is absent from the offer and the channel never negotiates (viewer's stays
// closed, so no input arrives). The viewer receives this channel via ondatachannel.
const inputCh = pc.createDataChannel('input', { ordered: true });
inputCh.onmessage = (msg) => {
let evt; try { evt = JSON.parse(msg.data); } catch { return; }
window.agent.injectInput(evt); // -> main process -> OS injection
};
};
pc.onicecandidate = (ev) => {
if (ev.candidate) ws.send(JSON.stringify({ type: 'ice-candidate', sessionId: currentSessionId, candidate: ev.candidate }));
+122
View File
@@ -0,0 +1,122 @@
# TASK FOR CLAUDE (VS Code): Apply the Biz Connect brand — icons, splash, loaders, toasts
Read this whole file, then execute it. Work CONSERVATIVELY — only ADD / restyle, do NOT
refactor unrelated code. The app is live in production. Find the right spots in the CURRENT
code yourself (don't assume old names). Summarise all changes and STOP for my review before
committing anything.
Repo root: C:\BizGaze_Support\remote-access-app
Master brand assets are already placed in: brand-assets\
- app-icon-1024.png (1024 full-bleed app icon master)
- splash-2732-dark.png (2732 splash, brand blue — primary)
- splash-2732-light.png (2732 splash, white — optional light theme)
- loader-ring.svg (default spinner, light backgrounds)
- loader-orbit.svg (branded spinner, light backgrounds)
- loader-orbit-dark.svg (branded spinner, dark/overlay backgrounds)
Brand colours: blue #1F3B73, blue-dark #16294F, yellow #FFC708, gold #E0AC00.
Note: brand-assets/ is only the SOURCE. Put the GENERATED / used copies where each target
needs them — web assets under server/public/ (served over HTTP); native icons/splash into the
platform build folders (Electron / Android / iOS) as applicable.
## 1. App icons (from brand-assets/app-icon-1024.png)
Generate and place:
- Windows .ico (multi-size 16/32/48/256) — fixes the tiny/blurry taskbar icon.
- Favicon: server/public/favicon.ico + a 32px PNG; add to each page <head>:
<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="apple-touch-icon" href="/apple-touch-icon-180.png">
- PWA icons 192, 512, and a maskable 512; reference them in the web manifest, and set the
manifest "background_color" and "theme_color" to "#1F3B73".
- Native mobile icons (Android mipmap set + adaptive, iOS AppIcon set) into their folders.
## 2. Splash (from brand-assets/splash-2732-dark.png)
- Web/PWA loading + Electron splash: brand-blue background #1F3B73 with the logo centred
(use the 2732 image, or reuse the app's splash.html if present).
- Native launch screens: use the 2732 image (Android 12 SplashScreen background #1F3B73 + the
app icon; iOS LaunchScreen background #1F3B73 + centred logo). Keep native launch STATIC.
- Use splash-2732-light.png only if a light theme is supported.
## 3. Loaders (from brand-assets/loader-*.svg)
Copy the three SVGs into server/public/ (e.g. server/public/loaders/). Wire them:
- Everyday "Loading…" and in-app spinners -> loader-ring.svg
- The hero "Connecting…" moment (session connect) -> loader-orbit.svg (light) / loader-orbit-dark.svg (on dark)
Show one centered in the middle of the screen/panel while loading; hide when done. Always pair
show with hide on BOTH the success and error paths so it can never get stuck.
## 4. Branded notification toasts
Create server/public/bizconnect-toast.css with EXACTLY:
```css
/* Biz Connect — branded notification toast. BZToast.success('…') / .error / .message / .info */
.bzt-wrap{position:fixed;top:16px;right:16px;z-index:2147483600;display:flex;flex-direction:column;gap:10px;max-width:min(380px,92vw)}
@supports(top:env(safe-area-inset-top)){.bzt-wrap{top:calc(16px + env(safe-area-inset-top));right:calc(16px + env(safe-area-inset-right))}}
.bzt{display:flex;align-items:flex-start;gap:12px;background:#fff;color:#1f2430;border-radius:14px;padding:12px 14px;
box-shadow:0 12px 30px rgba(16,26,53,.20);border-left:5px solid #1F3B73;
transform:translateX(120%);opacity:0;transition:transform .3s cubic-bezier(.2,.7,.2,1),opacity .3s}
.bzt.bzt-in{transform:translateX(0);opacity:1}
.bzt.success{border-left-color:#16a34a}.bzt.error{border-left-color:#b91c1c}
.bzt-badge{flex:none;width:34px;height:34px;border-radius:50%;display:grid;place-items:center;background:#1F3B73}
.bzt.success .bzt-badge{background:#16a34a}.bzt.error .bzt-badge{background:#b91c1c}
.bzt-badge svg{width:20px;height:20px}
.bzt-body{flex:1;min-width:0;padding-top:1px}
.bzt-title{font:700 13.5px/1.3 'Segoe UI',system-ui,sans-serif;color:#1F3B73;margin:0 0 1px}
.bzt.success .bzt-title{color:#15803d}.bzt.error .bzt-title{color:#b91c1c}
.bzt-msg{font:500 13px/1.4 'Segoe UI',system-ui,sans-serif;color:#3a4152;overflow-wrap:anywhere}
.bzt-x{flex:none;background:none;border:none;color:#9aa3b2;cursor:pointer;font-size:18px;line-height:1;padding:2px 4px}
.bzt-x:hover{color:#1f2430}
@media(prefers-reduced-motion:reduce){.bzt{transition:opacity .2s}}
```
Create server/public/bizconnect-toast.js with EXACTLY:
```js
/* Biz Connect toast API. Requires bizconnect-toast.css.
BZToast.success('Saved'); BZToast.error('Connection lost'); BZToast.message('Hi', {title:'Ravi'}); */
window.BZToast=(function(){
var wrap=null;
var ICON={
message:'<svg viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
info:'<svg viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="9" stroke="#fff" stroke-width="2.2"/><path d="M12 11v5M12 8h.01" stroke="#fff" stroke-width="2.4" stroke-linecap="round"/></svg>',
success:'<svg viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>',
error:'<svg viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg>'
};
function esc(s){return String(s==null?'':s).replace(/[&<>"]/g,function(c){return{'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c];});}
function ensure(){ if(wrap) return wrap; wrap=document.createElement('div'); wrap.className='bzt-wrap'; document.body.appendChild(wrap); return wrap; }
function show(message,opts){
opts=opts||{}; var type=opts.type||'message'; var w=ensure();
var t=document.createElement('div'); t.className='bzt '+type;
t.innerHTML='<div class="bzt-badge">'+(ICON[type]||ICON.message)+'</div><div class="bzt-body">'
+(opts.title?'<div class="bzt-title">'+esc(opts.title)+'</div>':'')
+'<div class="bzt-msg">'+esc(message)+'</div></div><button class="bzt-x" aria-label="Dismiss">&times;</button>';
w.appendChild(t); requestAnimationFrame(function(){ t.classList.add('bzt-in'); });
var dur=(opts.duration==null?4000:opts.duration), timer;
function close(){ t.classList.remove('bzt-in'); setTimeout(function(){ if(t.parentNode) t.parentNode.removeChild(t); },320); clearTimeout(timer); }
t.querySelector('.bzt-x').onclick=close; if(dur>0) timer=setTimeout(close,dur); return close;
}
return { show:show,
message:function(m,o){o=o||{};o.type='message';return show(m,o);},
success:function(m,o){o=o||{};o.type='success';return show(m,o);},
error:function(m,o){o=o||{};o.type='error';return show(m,o);},
info:function(m,o){o=o||{};o.type='info';return show(m,o);} };
})();
```
Then, on every page that shows notifications (connect, share, home, dashboard, console),
include both files near the top BEFORE the page's own inline <script>:
<link rel="stylesheet" href="/bizconnect-toast.css">
<script src="/bizconnect-toast.js"></script>
(Load the JS via src only — never inline.)
Now REPLACE the existing toast / notification pop-ups with the branded API (keep the same
triggers and text, just route them through BZToast so they look on-brand):
- Incoming chat message -> BZToast.message(text, {title: senderName})
- A success (e.g. recording/transcript saved, agent added) -> BZToast.success('…')
- An error (connection lost, upload failed, invalid code) -> BZToast.error('…')
- Neutral info -> BZToast.info('…')
Remove the old inline toast markup/styles it replaces. Toasts appear top-right and auto-dismiss.
## 5. Verify (do not commit until I review)
- node --check any JS you extract/touch; confirm every page still loads.
- Confirm: taskbar/favicon icon is crisp, splash shows on launch, a loader appears centered
during connect/report, and notifications now use the branded toast.
- List exactly which files changed, then STOP for my review.
+24
View File
@@ -0,0 +1,24 @@
# Biz Connect — master assets for VS Claude
Three masters, exactly as requested. Regenerate/wire everything from these.
## 1. App icon → app-icon-1024.png
- 1024×1024, full-bleed solid brand-blue square (no baked-in rounded corners), C mark
centred with safe padding. Use as the single source to regenerate:
Windows `.ico` (multi-size — fixes the tiny/blurry taskbar icon), PWA icons
(192, 512, maskable), apple-touch-icon, favicon, and the Android/iOS mobile icons.
## 2. Splash → splash-2732-dark.png (primary) · splash-2732-light.png (optional)
- 2732×2732. Dark = brand blue (use this everywhere by default). Light = white background
variant if you support a light theme. Use for the desktop/web launch and the mobile
native splash. (Native launch screens should stay static — no animation.)
## 3. Loader → animated SVG (pick per context)
- loader-ring.svg default everyday spinner, for LIGHT backgrounds (blue track + yellow arc)
- loader-orbit.svg branded spinner (the C with a circling dot), LIGHT backgrounds
- loader-orbit-dark.svg same branded spinner for DARK/overlay backgrounds (white C)
Recommended: use loader-ring.svg as the standard "Loading…" and in-app spinner; use
loader-orbit(-dark).svg for the hero "Connecting…" moment. SVG is animated, tiny, scalable.
## Brand
Blue #1F3B73 · Blue-dark #16294F · Yellow #FFC708 · (deeper gold #E0AC00 for "Connect" on white)
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

+5
View File
@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="64" height="64" role="img" aria-label="Loading">
<circle cx="50" cy="50" r="34" fill="none" stroke="#ffffff" stroke-width="9" stroke-linecap="round" stroke-dasharray="165 300" transform="rotate(38 50 50)"/>
<g><circle cx="84" cy="50" r="7" fill="#FFC708"/>
<animateTransform attributeName="transform" type="rotate" from="0 50 50" to="360 50 50" dur="1.1s" repeatCount="indefinite"/></g>
</svg>

After

Width:  |  Height:  |  Size: 471 B

+5
View File
@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="64" height="64" role="img" aria-label="Loading">
<circle cx="50" cy="50" r="34" fill="none" stroke="#1F3B73" stroke-width="9" stroke-linecap="round" stroke-dasharray="165 300" transform="rotate(38 50 50)"/>
<g><circle cx="84" cy="50" r="7" fill="#FFC708"/>
<animateTransform attributeName="transform" type="rotate" from="0 50 50" to="360 50 50" dur="1.1s" repeatCount="indefinite"/></g>
</svg>

After

Width:  |  Height:  |  Size: 471 B

+6
View File
@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="50" height="50" role="img" aria-label="Loading">
<circle cx="25" cy="25" r="20" fill="none" stroke="#1F3B73" stroke-opacity="0.16" stroke-width="5"/>
<path fill="none" stroke="#FFC708" stroke-width="5" stroke-linecap="round" d="M25 5 A20 20 0 0 1 45 25">
<animateTransform attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.8s" repeatCount="indefinite"/>
</path>
</svg>

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

+266
View File
@@ -0,0 +1,266 @@
# Codemagic CI/CD — builds the Biz Connect iOS app (Capacitor shell over the live web UI) and uploads it
# to TestFlight / App Store Connect. No Mac needed: this runs on Codemagic's macOS cloud instances.
#
# The app is a thin Capacitor wrapper that loads https://remote.bizgaze.com, so there's no bundled web
# code to build here — we generate the iOS project, patch its privacy strings, sign, archive and upload.
#
# ── One-time setup (see mobile/IOS_SETUP.md for the click-by-click) ────────────────────────────────
# 1. App Store Connect: create the app with bundle id com.bizgaze.connect
# 2. Codemagic → Teams/Integrations → App Store Connect: add your ASC API key (issuer id, key id, .p8).
# Name the integration exactly: BizGaze App Store Connect
# 3. That's it — automatic code signing fetches/creates the distribution cert + profile from that key.
workflows:
ios-testflight:
name: Biz Connect iOS → TestFlight
max_build_duration: 60
instance_type: mac_mini_m2
integrations:
app_store_connect: BizGaze App Store Connect # ← must match the integration name you create
environment:
# NOTE: we deliberately do NOT use an `ios_signing:` block here. That block makes Codemagic
# try to *fetch an existing* provisioning profile at build startup — it never creates one — so on
# a brand-new app it fails init with "No matching profiles found …". Instead the "Set up code
# signing" script below runs `fetch-signing-files … --create`, which creates the distribution
# certificate + profile on first run, then `xcode-project use-profiles` wires them into the project.
groups:
- ios_signing # ← Codemagic variable group holding CERTIFICATE_PRIVATE_KEY (secure). See below.
vars:
BUNDLE_ID: "com.bizgaze.connect"
XCODE_PROJECT: "mobile/ios/App/App.xcodeproj"
XCODE_SCHEME: "App"
node: 22
xcode: latest
cocoapods: default
scripts:
- name: Install JS dependencies
script: |
cd mobile
# npm install (not ci): the dependency set changed to Capacitor 7 + the safe-area/keyboard
# plugins, so we let npm resolve a fresh tree rather than require a pre-synced lockfile.
npm install
- name: Generate the iOS project (Capacitor)
script: |
cd mobile
# `cap add ios` scaffolds ios/App; safe to re-run — it no-ops if it already exists.
# Capacitor 8 Swift Package Manager: generate an SPM project (no Podfile). LiveKit is pulled via the
# native-call plugin's Package.swift; `cap sync` wires all local plugins into the CapApp-SPM package.
if [ ! -d "ios" ]; then npx cap add ios --packagemanager SPM; fi
npx cap sync ios
# Sanity: the Xcode project must exist. Print the iOS dir so the log shows the SPM layout (CapApp-SPM
# present, NO Podfile) — if a Podfile appears, the SPM flag didn't take and we'd need to fix it.
test -d ios/App/App.xcodeproj || { echo "ERROR: iOS Xcode project not generated"; ls -la ios/App || true; exit 1; }
echo "iOS project layout:"; ls -la ios/App
# ── Diagnose local-plugin SPM wiring (the regression: our file: plugins didn't function at runtime) ──
echo "=== local plugins in node_modules — symlink vs copy, and is Package.swift present? ==="
for p in native-call media-library audio-route share-inbox file-opener; do
echo "-- $p --"; ls -ld "node_modules/$p" 2>/dev/null || echo " (dir missing)"
( ls "node_modules/$p/Package.swift" >/dev/null 2>&1 && echo " Package.swift PRESENT" ) || echo " Package.swift MISSING"
done
echo "=== CapApp-SPM Package.swift — are our local plugins + LiveKit wired in? ==="
CAPSPM=$(find ios -path "*CapApp-SPM*Package.swift" 2>/dev/null | head -1)
if [ -n "$CAPSPM" ]; then echo "found: $CAPSPM"; cat "$CAPSPM"; else echo " CapApp-SPM/Package.swift NOT FOUND"; find ios -name Package.swift 2>/dev/null; fi
# App icon + splash from resources/icon.png & resources/splash*.png (1024x1024 icon, 2732² splash).
npx capacitor-assets generate --ios || echo "capacitor-assets returned non-zero (see above)"
# HARD-VERIFY the splash + icon actually landed in the iOS project. Previously this step swallowed
# failures with `|| echo skipped`, so a broken generation shipped Capacitor's BLANK default splash
# (looked unbranded on launch). Fail the build loudly instead of shipping an empty splash.
SPLASH_PNG=$(find ios -path "*Assets.xcassets/Splash.imageset*" -name "*.png" 2>/dev/null | head -1)
ICON_PNG=$(find ios -path "*Assets.xcassets/AppIcon.appiconset*" -name "*.png" 2>/dev/null | head -1)
if [ -z "$SPLASH_PNG" ]; then echo "ERROR: iOS Splash.imageset not generated — the app would launch with a blank splash"; exit 1; fi
echo "iOS splash asset OK -> $SPLASH_PNG"
echo "iOS app icon asset -> ${ICON_PNG:-MISSING}"
- name: Patch Info.plist (App-Review privacy strings) + bundle id
script: |
bash mobile/scripts/ios-patch.sh
- name: Add the Share Extension target
script: |
# Inject the second target (Biz Connect in the iOS share sheet) into the freshly-generated
# Xcode project. Uses the `xcodeproj` gem that ships with CocoaPods, so no extra install.
# Runs BEFORE pod install: the extension uses no pods, and this way the workspace that pods
# generates already contains the new target.
ruby mobile/scripts/add-share-extension.rb
- name: Add the Broadcast (screen-share) Extension target
script: |
# Inject the ReplayKit broadcast upload extension (lets the user share their iPhone screen).
# It links the LiveKit Swift package (LKSampleHandler). Runs after cap sync so the SPM project
# + App.entitlements already exist. A build failure here is most likely the SPM product-link or
# the missing App Group capability on the com.bizgaze.connect.broadcast App ID (a one-time manual
# step in the Apple Developer portal — see mobile/IOS_SETUP.md).
ruby mobile/scripts/add-broadcast-extension.rb
- name: Set up code signing
script: |
# Create the distribution certificate + provisioning profile from the ASC API key and add the
# cert to the keychain. NOTE: `xcode-project use-profiles` is intentionally NOT here — it must
# run AFTER `pod install` generates the workspace, otherwise it fails to wire the profile into
# the App target and the archive dies with "App requires a provisioning profile".
#
# --certificate-key is REQUIRED for reusable signing: without it, --create makes a throwaway
# distribution cert whose private key dies with the build machine, so the next build finds a
# cert it has no key for ("Cannot save Signing Certificates without certificate private key").
# By passing our own fixed private key (CERTIFICATE_PRIVATE_KEY, a secure var in the
# `ios_signing` group), the cert is created once from that key and reused by every build.
#
# TWO bundle ids now need signing: the app AND the share extension (<app>.share). Each gets its
# own App Store profile. The App Group capability (group.com.bizgaze.connect) must be enabled on
# BOTH App IDs in the Apple Developer portal — see mobile/IOS_SETUP.md. fetch-signing-files
# registers a missing bundle id and creates its profile, but does NOT toggle the App Group
# capability, so that stays a one-time manual step.
keychain initialize
app-store-connect fetch-signing-files "$BUNDLE_ID" \
--type IOS_APP_STORE \
--certificate-key="@env:CERTIFICATE_PRIVATE_KEY" \
--create
app-store-connect fetch-signing-files "${BUNDLE_ID}.share" \
--type IOS_APP_STORE \
--certificate-key="@env:CERTIFICATE_PRIVATE_KEY" \
--create
# THIRD bundle id: the broadcast (screen-share) extension. Same story as .share — its App Group
# capability (group.com.bizgaze.connect) must be enabled MANUALLY on the App ID in the Apple
# Developer portal (fetch-signing-files registers the id + profile but does NOT toggle App Group).
app-store-connect fetch-signing-files "${BUNDLE_ID}.broadcast" \
--type IOS_APP_STORE \
--certificate-key="@env:CERTIFICATE_PRIVATE_KEY" \
--create
keychain add-certificates
# (No "Install CocoaPods" step under SPM — there is no Podfile. Xcode resolves the Swift packages
# (Capacitor, plugins, LiveKit + its WebRTC/UniFFI/SwiftProtobuf) during the archive below.)
- name: Build the signed IPA
script: |
# Apply the fetched provisioning profile(s) to the Xcode project NOW that the workspace exists,
# then archive. use-profiles scans for **/*.xcodeproj under the repo root and sets manual
# signing (team + profile specifier) on the matching App target.
xcode-project use-profiles
# `xcode-project build-ipa` prints a PRETTIFIED summary and swallows the raw xcodebuild "error:"
# lines — a failed archive shows only "Failed to archive" with no reason. On failure, surface the
# actual errors from the raw log so we don't have to dig through the artifact.
if ! xcode-project build-ipa --project "$XCODE_PROJECT" --scheme "$XCODE_SCHEME"; then
echo "======================= xcodebuild errors ======================="
grep -h -E "error:|errSec|Provisioning profile|entitlement|Code ?Sign|does not (support|contain)|requires a provisioning|No profile|No signing|doesn't (include|match)|Command .* failed" /tmp/xcodebuild_logs/*.log 2>/dev/null | grep -vi "warning:" | tail -60 || echo "(no matching lines — open the xcodebuild_logs artifact)"
echo "================================================================="
exit 1
fi
artifacts:
- build/ios/ipa/*.ipa
- /tmp/xcodebuild_logs/*.log
publishing:
app_store_connect:
auth: integration
# Upload the build to App Store Connect. It is immediately usable for INTERNAL TestFlight testing
# (no Apple review). We keep external-beta submission OFF for now: submit_to_testflight=true would
# push the build to EXTERNAL beta review, which requires the Test Information (feedback email +
# beta review contact + a demo login, since our app needs sign-in) to be filled in first, and
# fails the build until then. Flip to true (and add `beta_groups:` + fill Test Information at
# App Store Connect → TestFlight → Test Information) when you want outside testers.
submit_to_testflight: false
# Flip this to true (and add a `submit_to_app_store` group with reviewer notes) once you're ready
# to push a build to public App Store review instead of only TestFlight.
# submit_to_app_store: false
# No email recipients here on purpose — build status is watched on the Codemagic dashboard. Add
# per-user notifications in the Codemagic UI (or a `publishing.email` block) later if you want them.
# ── Android test build ──────────────────────────────────────────────────────────────────────────
# Builds an INSTALLABLE debug APK of the same Capacitor shell (loads https://remote.bizgaze.com). This is
# the Android equivalent of the iOS TestFlight loop, but simpler — no Google Play account or signing is
# needed to test: download the APK artifact from the Codemagic build page (or wire an email/Slack in the
# UI), sideload it on a phone (enable "Install unknown apps"), and run.
#
# Runs on the SAME macOS instance as the iOS workflow (mac_mini_m2) — Codemagic's macOS images ship the
# Android SDK + JDK too. (A Linux instance would be cheaper/faster but linux_x2 isn't on every billing
# plan; mac_mini_m2 is the one this account already uses for iOS.)
#
# Firebase push (FCM) is OPTIONAL for this test build: app/build.gradle only applies the google-services
# plugin when google-services.json is present, so the APK builds fine WITHOUT it (push/call-wake just
# won't fire). To enable push, base64 the google-services.json and store it as a secure Codemagic env var
# GOOGLE_SERVICES_JSON (group `android_config`); the step below decodes it into place.
android-apk:
name: Biz Connect Android → test APK
max_build_duration: 45
instance_type: mac_mini_m2
environment:
# To enable FCM push later, create a Codemagic variable group holding GOOGLE_SERVICES_JSON (base64 of
# google-services.json, marked secure) and uncomment the two lines below. Left out for now so the first
# test build needs ZERO Codemagic setup.
# groups:
# - android_config
vars:
PACKAGE_NAME: "com.bizgaze.connect"
node: 22
java: 21 # Capacitor 8's Android build (AGP 8.7 / Gradle 8.11) requires JDK 21 — JDK 17 fails the build.
scripts:
- name: Install JS dependencies
script: |
cd mobile
npm install
- name: Generate the Android project (Capacitor)
script: |
cd mobile
# `cap add android` scaffolds android/; safe to re-run — it no-ops if it already exists (our committed
# project has custom manifest permissions, which cap sync preserves).
if [ ! -d "android" ]; then npx cap add android; fi
npx cap sync android
# App icon + splash from resources/icon.png & resources/splash*.png.
npx capacitor-assets generate --android || echo "capacitor-assets returned non-zero (see above)"
# The generated project points sdk.dir at wherever it was made; overwrite it with the CI SDK path so
# Gradle finds the SDK. Codemagic exports ANDROID_SDK_ROOT (fall back to ANDROID_HOME on macOS images).
SDK="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}"
echo "sdk.dir=$SDK" > android/local.properties
echo "Android SDK -> $SDK"
# android/ is gitignored and regenerated fresh in CI, so its manifest only has INTERNET. Inject the
# camera/mic/notification permissions the web UI needs (mirrors ios-patch.sh for iOS). Tolerant + idempotent.
node scripts/android-patch.js android/app/src/main/AndroidManifest.xml
- name: Firebase google-services.json for FCM push
script: |
# Place the client Firebase config into android/app/ so the google-services Gradle plugin applies and
# FirebaseApp initializes at runtime — WITHOUT it, PushNotifications.register() throws
# "Default FirebaseApp is not initialized" and crashes the app on Android. Prefer the committed file;
# fall back to a base64 GOOGLE_SERVICES_JSON env var. (Runs from the repo root; the Android project was
# generated in the previous step.)
DEST=mobile/android/app/google-services.json
if [ -f mobile/FirebaseAccount_Google/google-services.json ]; then
cp mobile/FirebaseAccount_Google/google-services.json "$DEST"
echo "google-services.json copied from repo → FCM enabled"
elif [ -n "$GOOGLE_SERVICES_JSON" ]; then
echo "$GOOGLE_SERVICES_JSON" | { base64 --decode 2>/dev/null || base64 -D; } > "$DEST"
echo "google-services.json written from env → FCM enabled"
else
echo "No google-services.json found — building WITHOUT FCM push"
fi
ls -l "$DEST" 2>/dev/null || echo "(no google-services.json placed)"
- name: Build the debug APK
script: |
set -e
cd mobile/android
chmod +x ./gradlew
# Debug build type is auto-signed with the Android debug keystore → directly installable, no Play
# account or upload key needed. (A signed release AAB for the Play Store is a later, separate step.)
# Capture the output so that, on failure, we surface Gradle's actual "What went wrong" block instead
# of a wall of internal stack frames — and FAIL the step (a trailing `find` used to exit 0 and mask it).
set +e
./gradlew assembleDebug --stacktrace 2>&1 | tee /tmp/gradle.log
STATUS=${PIPESTATUS[0]}
set -e
if [ "$STATUS" != "0" ]; then
echo "======================= GRADLE FAILURE ======================="
grep -n -A 25 "What went wrong" /tmp/gradle.log || true
grep -n -A 3 "FAILURE:" /tmp/gradle.log || true
echo "=============================================================="
exit 1
fi
echo "APK(s):"; find app/build/outputs -name "*.apk"
test -n "$(find app/build/outputs -name '*.apk' -print -quit)" || { echo "ERROR: no APK produced"; exit 1; }
artifacts:
- mobile/android/app/build/outputs/**/*.apk
# Download the APK from the build page. To get it emailed like TestFlight, add a `publishing.email` block
# here (or notifications in the Codemagic UI). A signed release AAB → Google Play internal testing is a
# separate workflow we can add once the shell is verified on a device.
+20 -1
View File
@@ -84,6 +84,24 @@ verify() {
fi
}
# Recreating the app container can give it a NEW docker network IP. Nginx Proxy Manager caches the app's
# upstream IP at config-load, so it would keep hitting the OLD IP ("Connection refused" → site down) until
# it re-resolves. Reload NPM's nginx so it picks up the current IP. Non-fatal: warn (don't fail) if NPM
# isn't found — some environments run a different reverse proxy.
reload_proxy() {
local npm
npm="$(docker ps --format '{{.Names}}' | grep -iE 'nginx.?proxy.?manager.*app' | head -n1 || true)"
if [ -n "$npm" ] && docker exec "$npm" nginx -t >/dev/null 2>&1; then
if docker exec "$npm" nginx -s reload >/dev/null 2>&1; then
ok "Reloaded $npm (re-resolved app upstream IP)."
else
warn "Could not reload $npm — if the site 502s, run: docker exec $npm nginx -s reload"
fi
else
warn "Reverse proxy (NPM) not auto-detected; if the site fails after deploy, reload it so it re-resolves the app IP."
fi
}
# --- rollback mode ---
if [ "$ROLLBACK" -eq 1 ]; then
latest="$(ls -1t "$BK_DIR"/*.tgz 2>/dev/null | head -n1 || true)"
@@ -91,7 +109,7 @@ if [ "$ROLLBACK" -eq 1 ]; then
log "Rolling back from: $latest"
snapshot # snapshot the (broken) current state first
tar -xzf "$latest" -C "$APP_DIR"
rebuild; verify
rebuild; verify; reload_proxy
ok "Rolled back to $latest"
exit 0
fi
@@ -106,5 +124,6 @@ if [ "$DO_PULL" -eq 1 ]; then
fi
rebuild
verify
reload_proxy
ok "Deploy complete. Backups kept: $KEEP_BACKUPS (in $BK_DIR)."
echo " Rollback with: ./deploy.sh --rollback"
+52
View File
@@ -0,0 +1,52 @@
# Biz Connect Desktop — packaging & updates
## How updates reach installed apps (two kinds)
1. **Web / UI / feature / bug-fix changes → instant, no app update.**
The app loads the live UI from `https://remote.bizgaze.com`. Deploy the server
(`./deploy.sh`) and every installed desktop app has it on next open/reload. This is ~95%
of all changes.
2. **Native shell changes (`main.js` / `preload.js`) → auto-update.**
Baked into the `.exe`. Shipped via **electron-updater** against a **self-hosted feed** on
`https://remote.bizgaze.com/downloads/`. On launch (and every 6h) the app checks
`latest.yml`, downloads a newer version in the background, and installs on next restart.
## Build an installer
```bash
cd desktop
npm install
npm run dist # electron-builder → dist/ (Win: NSIS .exe + latest.yml + .blockmap)
```
Output in `desktop/dist/`:
- `Biz Connect Setup <version>.exe` — the installer
- `latest.yml` — the update manifest electron-updater reads
- `*.blockmap` — enables delta downloads
A PACKAGED build points at production (`main.js` defaults `SERVER_URL` to
`https://remote.bizgaze.com` when `app.isPackaged`); running from source in dev defaults to
`http://localhost:8090`. `SERVER_URL` overrides either.
## Publish a release (self-hosted feed)
1. Bump `version` in `desktop/package.json` (semver — electron-updater compares this).
2. `npm run dist`.
3. Upload **all** of `dist/` (the `.exe`, `latest.yml`, `.blockmap`) to whatever the server
serves at `https://remote.bizgaze.com/downloads/`.
- Behind Nginx Proxy Manager: point `/downloads/` at a static folder, or add a static
route in the app. The files are large binaries — host them on disk/volume, **not** git.
4. Installed apps pick it up within 6h (or on next launch).
> First release: users install the `.exe` manually (download link on your site). Every
> release after that updates automatically.
## Code signing (add when the cert is ready)
Unsigned installers work but trip Windows SmartScreen ("More info → Run anyway"). To sign:
- **Azure Trusted Signing** (recommended): set `win.azureSignOptions` (or use the
`@electron/windows-sign` path) with the Trusted Signing account/endpoint. Cloud, no token.
- **EV/OV cert (.pfx or token)**: set env `CSC_LINK` (path to .pfx) + `CSC_KEY_PASSWORD`,
or configure a hardware-token signing tool. electron-builder signs automatically.
Once signing is on, auto-updates are silent (no SmartScreen).
## App identity
`appId` = `com.bizgaze.connect.desktop`; the NSIS installer registers this as the
AppUserModelID and creates a Start-menu shortcut — which is also the prerequisite for the
**Phase D inline-reply Windows Toast notifications** (see ../CLIENTS.md).
+30
View File
@@ -0,0 +1,30 @@
# Biz Connect — Desktop client
Electron shell that loads the live Connect web UI and adds native screen capture. See the
overall plan in [../CLIENTS.md](../CLIENTS.md).
## Run (dev = local testing)
```bash
npm install
npm start # dev auto-targets http://localhost:8090 (your local server)
SERVER_URL=https://remote.bizgaze.com npm start # …or point dev at production to compare
```
`npm start` IS the local desktop test — no separate "local" installer needed. In dev (unpackaged)
the shell defaults to the local server; a PACKAGED installer defaults to production. `SERVER_URL`
overrides either. (Bash/Git-Bash syntax above; in PowerShell: `$env:SERVER_URL='…'; npm start`.)
## Build installers
```bash
npm run dist # electron-builder → Win NSIS / Mac dmg / Linux AppImage
```
Signed, trusted installers need certificates:
- **Windows:** an EV (or OV) code-signing certificate.
- **macOS:** Apple Developer ID cert + notarization (`CSC_LINK`, `APPLE_ID`, `APPLE_APP_SPECIFIC_PASSWORD`).
## Notes
- The window loads `${SERVER_URL}/home`; relative `/api` and `/ws` URLs work because the
origin is the server itself — no web-code changes.
- `setDisplayMediaRequestHandler` in `main.js` is what makes "Share Screen" work in Electron;
it currently defaults to the primary display. Swap in a source-picker for production.
- The session is persisted (`persist:bizconnect`) so login survives restarts.
- `window.__NATIVE__ === 'desktop'` is exposed for the web UI to feature-detect.
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+144
View File
@@ -0,0 +1,144 @@
// OS input injection layer.
//
// Cross-platform mouse/keyboard control via @nut-tree-fork/nut-js (optional
// native dependency). If nut-js isn't installed (e.g. CI, or a sandbox without
// a display), this module degrades to a logging no-op so the rest of the agent
// still runs and can be tested. On Windows, nut-js drives the Win32 SendInput
// API under the hood — the same mechanism TeamViewer/AnyDesk use.
let nut = null;
try {
// eslint-disable-next-line import/no-extraneous-dependencies
nut = require('@nut-tree-fork/nut-js');
nut.mouse.config.autoDelayMs = 0;
nut.keyboard.config.autoDelayMs = 0;
} catch {
nut = null;
}
const available = !!nut;
// Map the PHYSICAL key (KeyboardEvent.code) to a nut-js Key. This is the correct way to drive a remote
// keyboard: press the same physical key the viewer pressed and let the remote OS apply its own modifier
// state. Mapping by CHARACTER (mapKey below) broke shifted keys — e.g. Shift+1 typed "1" instead of "!"
// and symbols came out wrong ("keyboard performs differently on the sharer's device").
const CODE_MAP = {
Backspace: 'Backspace', Tab: 'Tab', Enter: 'Enter', NumpadEnter: 'Enter', Escape: 'Escape', Space: 'Space',
ShiftLeft: 'LeftShift', ShiftRight: 'RightShift',
ControlLeft: 'LeftControl', ControlRight: 'RightControl',
AltLeft: 'LeftAlt', AltRight: 'RightAlt',
MetaLeft: 'LeftSuper', MetaRight: 'RightSuper',
CapsLock: 'CapsLock',
PageUp: 'PageUp', PageDown: 'PageDown', End: 'End', Home: 'Home',
ArrowLeft: 'Left', ArrowUp: 'Up', ArrowRight: 'Right', ArrowDown: 'Down',
Insert: 'Insert', Delete: 'Delete',
Minus: 'Minus', Equal: 'Equal', BracketLeft: 'LeftBracket', BracketRight: 'RightBracket',
Backslash: 'Backslash', Semicolon: 'Semicolon', Quote: 'Quote', Backquote: 'Grave',
Comma: 'Comma', Period: 'Period', Slash: 'Slash',
NumpadAdd: 'Add', NumpadSubtract: 'Subtract', NumpadMultiply: 'Multiply', NumpadDivide: 'Divide', NumpadDecimal: 'Decimal',
};
function mapCode(code) {
if (!nut || !code) return null;
const K = nut.Key;
const named = CODE_MAP[code];
if (named && K[named] !== undefined) return [K[named]];
let m;
if ((m = /^Key([A-Z])$/.exec(code)) && K[m[1]] !== undefined) return [K[m[1]]];
if ((m = /^Digit([0-9])$/.exec(code)) && K['Num' + m[1]] !== undefined) return [K['Num' + m[1]]];
if ((m = /^Numpad([0-9])$/.exec(code)) && K['NumPad' + m[1]] !== undefined) return [K['NumPad' + m[1]]];
if ((m = /^(F\d{1,2})$/.exec(code)) && K[m[1]] !== undefined) return [K[m[1]]];
return null;
}
// Map browser KeyboardEvent.key values to nut-js Key enum names. (Fallback when there's no usable code.)
function mapKey(key, code) {
if (!nut) return null;
const K = nut.Key;
const direct = {
'Enter': K.Enter, 'Backspace': K.Backspace, 'Tab': K.Tab, 'Escape': K.Escape,
' ': K.Space, 'ArrowLeft': K.Left, 'ArrowRight': K.Right, 'ArrowUp': K.Up, 'ArrowDown': K.Down,
'Home': K.Home, 'End': K.End, 'PageUp': K.PageUp, 'PageDown': K.PageDown, 'Delete': K.Delete,
'Control': K.LeftControl, 'Shift': K.LeftShift, 'Alt': K.LeftAlt, 'Meta': K.LeftSuper,
'CapsLock': K.CapsLock,
};
if (direct[key] !== undefined) return [direct[key]];
if (/^F\d{1,2}$/.test(key) && K[key] !== undefined) return [K[key]];
if (key && key.length === 1) {
const upper = key.toUpperCase();
if (/[A-Z]/.test(upper) && K[upper] !== undefined) return [K[upper]];
if (/[0-9]/.test(key) && K['Num' + key] !== undefined) return [K['Num' + key]];
// Fall back to typing the literal character (handles symbols/shifted chars)
return { type: key };
}
return null;
}
// Cache the screen size (this nut-js exposes screen.width()/height(), not getResolution()).
// Recomputed once per session (cleared in releaseAll) so a resolution change is picked up.
let _screen = null;
async function screenSize() {
if (!_screen) _screen = { w: await nut.screen.width(), h: await nut.screen.height() };
return _screen;
}
async function moveTo(xNorm, yNorm) {
if (!nut) return;
const { w, h } = await screenSize();
await nut.mouse.setPosition(new nut.Point(Math.round(xNorm * w), Math.round(yNorm * h)));
}
function buttonEnum(b) {
if (!nut) return null;
return b === 2 ? nut.Button.RIGHT : b === 1 ? nut.Button.MIDDLE : nut.Button.LEFT;
}
const pressed = new Set();
// Inject a single normalized input event coming from the viewer.
async function inject(evt) {
if (!nut) {
if (evt.kind !== 'mousemove') console.log('[input:noop]', JSON.stringify(evt));
return;
}
try {
switch (evt.kind) {
case 'mousemove':
await moveTo(evt.x, evt.y); break;
case 'mousedown':
await moveTo(evt.x, evt.y); await nut.mouse.pressButton(buttonEnum(evt.button)); break;
case 'mouseup':
await nut.mouse.releaseButton(buttonEnum(evt.button)); break;
case 'dblclick':
await moveTo(evt.x, evt.y); await nut.mouse.doubleClick(nut.Button.LEFT); break;
case 'scroll':
if (evt.dy) await (evt.dy > 0 ? nut.mouse.scrollDown(Math.abs(evt.dy)) : nut.mouse.scrollUp(Math.abs(evt.dy)));
if (evt.dx) await (evt.dx > 0 ? nut.mouse.scrollRight(Math.abs(evt.dx)) : nut.mouse.scrollLeft(Math.abs(evt.dx)));
break;
case 'keydown': {
// Prefer the PHYSICAL key so the remote OS applies its own shift/altgr state (correct symbols).
const m = mapCode(evt.code) || mapKey(evt.key, evt.code);
if (!m) break;
if (m.type) { await nut.keyboard.type(m.type); break; } // last-resort: type the literal character
await nut.keyboard.pressKey(...m); m.forEach((k) => pressed.add(k));
break;
}
case 'keyup': {
const m = mapCode(evt.code) || mapKey(evt.key, evt.code);
if (!m || m.type) break;
await nut.keyboard.releaseKey(...m); m.forEach((k) => pressed.delete(k));
break;
}
}
} catch (e) {
console.error('[input] inject error:', e.message);
}
}
// Safety: release any stuck modifier keys when a session ends.
async function releaseAll() {
if (!nut) { pressed.clear(); return; }
for (const k of pressed) { try { await nut.keyboard.releaseKey(k); } catch {} }
pressed.clear();
_screen = null;
}
module.exports = { inject, releaseAll, available, mapKey };
+539
View File
@@ -0,0 +1,539 @@
// Biz Connect — technician desktop client (Electron main process).
//
// This is a thin shell: it loads the live Connect web UI from the server origin, so every
// relative /api and /ws URL in the web app keeps working unchanged. What it adds over a
// browser tab:
// - native full-screen capture for "Share Screen" (setDisplayMediaRequestHandler)
// - a real desktop window (no browser chrome), persisted login session
// - external links open in the user's browser, not inside the app
//
// Server origin is configurable so the same build works against prod or a dev server.
const { app, BrowserWindow, session, desktopCapturer, shell, Menu, MenuItem, Tray, ipcMain, nativeImage, Notification } = require('electron');
const path = require('path');
const fs = require('fs');
const os = require('os');
const crypto = require('crypto');
// A stable per-install id (persisted in userData), so the server can count installs and
// associate them with the user who signs in. Created once, then reused across launches.
function getInstallId() {
try {
const p = path.join(app.getPath('userData'), 'install-id');
if (fs.existsSync(p)) { const v = fs.readFileSync(p, 'utf8').trim(); if (v) return v; }
const id = crypto.randomUUID();
fs.writeFileSync(p, id);
return id;
} catch (_) { return 'unknown'; }
}
// The renderer (web app) reads this synchronously to report telemetry after login.
ipcMain.on('get-install-info', (e) => {
e.returnValue = { installId: getInstallId(), appVersion: app.getVersion(), os: process.platform + ' ' + os.release() };
});
// Auto-update: only NATIVE shell changes (this .exe) need this — all web/UI changes arrive
// live from the server. Checks the self-hosted feed (publish config in package.json →
// https://remote.bizgaze.com/downloads/latest.yml), downloads in the background, and installs
// on the next restart. No-op in dev (unpackaged).
let autoUpdater = null;
try { ({ autoUpdater } = require('electron-updater')); } catch (_) { /* not installed in dev */ }
let _lastUpdateCheck = 0;
// Background update check — called on launch, on a timer, AND whenever the window is revealed from the tray
// (so re-opening the app actually looks for a new version instead of waiting up to 6h). Throttled so rapid
// tray open/close doesn't spam the feed. Combined with autoInstallOnAppQuit=true (set in whenReady), a
// downloaded update installs the next time the app truly quits — e.g. a normal PC restart — so close-to-tray
// users get updated even if they never pick "Quit" from the tray icon.
function bgUpdateCheck() {
if (!app.isPackaged || !autoUpdater) return;
const now = Date.now();
if (now - _lastUpdateCheck < 10 * 60 * 1000) return; // at most once / 10 min
_lastUpdateCheck = now;
autoUpdater.checkForUpdates().catch(() => {});
}
// #12: manual "Check for updates" from Settings. Returns the current status; the background updater
// (configured in app.whenReady) downloads and prompts to restart when a build is ready.
ipcMain.handle('check-updates', async () => {
const current = app.getVersion();
if (!app.isPackaged || !autoUpdater) return { status: 'dev', current };
try {
const r = await autoUpdater.checkForUpdates();
const v = r && r.updateInfo && r.updateInfo.version;
return (v && v !== current) ? { status: 'available', version: v, current } : { status: 'current', current };
} catch (e) { return { status: 'error', message: String((e && e.message) || e), current }; }
});
// #3: restart-and-install, triggered from the web update banner's "Restart" button.
ipcMain.handle('restart-to-update', () => { try { if (autoUpdater) autoUpdater.quitAndInstall(); } catch (_) {} });
// Chat toast: sender/group avatar + message; clicking it raises the app and opens that chat.
// Uses Electron's OWN Notification (native, no SnoreToast) whose 'click' event fires reliably.
const APP_ID = 'com.bizgaze.connect.desktop';
// Resolve the sender/group avatar to a local temp PNG for the toast icon. Accepts either a data:
// URL (legacy) or an http(s) DP URL, which we download (external photos can't be drawn to a canvas
// in the renderer without tainting it, so the renderer now passes the URL straight through).
function tmpPngPath() { return path.join(app.getPath('temp'), 'bizc-toast-' + crypto.randomBytes(4).toString('hex') + '.png'); }
// Cache downloaded DPs for the session (keyed by URL) so the SAME sender's photo is instant on the
// next notification — the first one may still show without a photo if the download is slow, but after
// that it's cached. Cached files are NOT deleted after use.
const avatarCache = new Map();
function avatarToTempPng(src) {
return new Promise((resolve) => {
try {
if (!src) return resolve(null);
const cached = avatarCache.get(src);
if (cached) { try { if (fs.existsSync(cached)) return resolve(cached); } catch (_) {} avatarCache.delete(src); }
if (/^data:image\/png;base64,/.test(src)) { const p = tmpPngPath(); fs.writeFileSync(p, Buffer.from(src.split(',')[1], 'base64')); avatarCache.set(src, p); return resolve(p); }
if (/^https?:\/\//i.test(src)) {
const mod = src.startsWith('https') ? require('https') : require('http');
const p = tmpPngPath(); const file = fs.createWriteStream(p);
const req = mod.get(src, (res) => {
if (res.statusCode !== 200) { res.resume(); file.close(() => { try { fs.unlinkSync(p); } catch (_) {} }); return resolve(null); }
res.pipe(file); file.on('finish', () => file.close(() => { avatarCache.set(src, p); resolve(p); }));
});
req.on('error', () => resolve(null));
req.setTimeout(4000, () => { try { req.destroy(); } catch (_) {} resolve(null); });
return;
}
resolve(null);
} catch (_) { resolve(null); }
});
}
// ---- Hard refresh -------------------------------------------------------------------------------
// The app closes to TRAY, so it can run for weeks on the page it first loaded and never see a new web
// deploy. This clears the shell's HTTP cache and reloads ignoring cache, so a stale UI is always
// recoverable. Reachable from: the in-app "Refresh" banner / Settings, Ctrl+R (reload),
// Ctrl+Shift+R or F5 (hard reload), and the tray menu.
async function hardReloadWin() {
try { await session.fromPartition('persist:bizconnect').clearCache(); } catch (_) {}
try { if (win && !win.isDestroyed()) win.webContents.reloadIgnoringCache(); } catch (_) {}
}
ipcMain.handle('hard-reload', async () => { await hardReloadWin(); return true; });
// ---- Remote control: OS input injection for a screen the local user is SHARING ----
// The renderer (share flow) forwards a viewer's mouse/keyboard events here for injection. Injection is
// HARD-GATED behind an explicit consent flag (rcArmed): nothing is injected until the local user clicks
// "Allow control", and it stops the instant they revoke or the session ends. nut-js is optional — if the
// native module isn't present it degrades to a no-op (no crash), so control simply won't take effect.
let injector = null;
try { injector = require('./input/inject'); } catch (_) { injector = null; }
let rcArmed = false;
// The renderer arms/disarms control (mirrors the on-screen consent banner). Disarming releases any
// stuck keys immediately.
ipcMain.on('rc-arm', (_e, on) => { rcArmed = !!on; if (!rcArmed && injector && injector.releaseAll) { try { injector.releaseAll(); } catch (_) {} } });
ipcMain.on('rc-input', (_e, evt) => { if (rcArmed && injector && injector.inject && evt) { try { injector.inject(evt); } catch (_) {} } });
// Whether OS injection is even possible on this machine (native module loaded). The renderer uses this
// to show "control needs the desktop app" vs an actual Allow prompt.
ipcMain.on('rc-available', (e) => { e.returnValue = !!(injector && injector.available); });
// Pre-warm the DP cache for the renderer's contacts (called after chats load), so the FIRST
// notification from anyone already has their photo — no per-toast download wait.
ipcMain.handle('precache-avatars', async (_e, urls = []) => {
try { for (const u of (Array.isArray(urls) ? urls : []).slice(0, 100)) { try { await avatarToTempPng(u); } catch (_) {} } } catch (_) {}
return true;
});
// Keep STRONG references to live notifications. Electron/Windows garbage-collects a Notification
// with no reference, which closed the toast within ~1s and made clicks do nothing.
const activeNotifs = new Set();
// Resolves {open} when the toast is clicked (renderer then opens that chat), else null.
ipcMain.handle('reply-notification', async (_e, payload = {}) => {
if (!Notification.isSupported()) return null;
// Fire the toast IMMEDIATELY — NEVER block on a download (waiting made notifications lag; a late
// call/chat alert is worse than one without a photo). Use the DP only if it's ALREADY cached
// (instant). If not, kick off a background fetch so the SAME sender's NEXT notification has it.
// Contacts are also pre-warmed on load (precache-avatars), so the photo is usually already cached.
let img = null;
try {
const src = payload.avatar;
if (src && /^data:image\//i.test(src)) {
img = await avatarToTempPng(src); // generated icon (initials/group) — synchronous, always use immediately
} else if (src) {
const c = avatarCache.get(src);
if (c && fs.existsSync(c)) img = c; // http DP already warmed (contacts pre-cached on load) → instant
else avatarToTempPng(src).catch(() => {}); // not cached yet → fire now, warm for next time
}
} catch (_) {}
return await new Promise((resolve) => {
let done = false;
let n;
const finish = (v) => {
if (done) return; done = true;
if (n) { activeNotifs.delete(n); }
resolve(v); // note: img is cached, not deleted
};
try {
// No timeoutType:'never' — on Windows that added an unwanted "Close" action button. Windows'
// default toast behavior + our strong reference keep it visible long enough; the in-app call
// popup provides the persistent Join/Decline for calls.
n = new Notification({
title: payload.title || 'Biz Connect',
body: payload.body || '',
icon: img ? nativeImage.createFromPath(img) : undefined,
silent: false,
});
activeNotifs.add(n); // strong ref → toast isn't collected; click stays live
n.on('click', () => {
if (win) { if (win.isMinimized()) win.restore(); win.show(); win.focus(); } // raise the app
finish({ kind: payload.kind, id: payload.id, open: true });
});
n.on('close', () => finish(null)); // user/system dismissed it → no action
n.show();
setTimeout(() => finish(null), payload.persistent ? 45000 : 25000); // don't leak the promise
} catch (_) { finish(null); }
});
});
// Windows attributes notifications to the AppUserModelID. Without setting it, toasts read
// "electron.app.<name>"; setting it to the installer's appId makes Windows resolve the
// installed "Biz Connect" shortcut, so notifications show "Biz Connect".
app.setAppUserModelId('com.bizgaze.connect.desktop');
// Renderer asks (via preload) to raise the window — e.g. when an OS notification is clicked.
ipcMain.on('focus-window', () => {
if (!win) return;
if (win.isMinimized()) win.restore();
win.show();
win.focus();
});
// Unread badge on the taskbar icon. The renderer computes the count (chats with unread) and
// draws the badge image (it has a canvas); Windows shows it via an overlay icon, macOS/Linux
// via the dock badge count.
ipcMain.on('set-unread', (_e, { count, dataUrl } = {}) => {
try {
if (typeof app.setBadgeCount === 'function') app.setBadgeCount(count || 0); // macOS/Linux dock
if (!win) return;
const overlay = (count > 0 && dataUrl) ? nativeImage.createFromDataURL(dataUrl) : null;
win.setOverlayIcon(overlay, count > 0 ? (count + ' unread chats') : ''); // Windows taskbar
} catch (_) {}
});
// Server origin: a PACKAGED build (the installer) points at production; running from source in dev
// (`npm start`, unpackaged) defaults to the local server so you can test the shell against localhost
// with no flags or separate "local" build. SERVER_URL always overrides (e.g. point dev at prod).
const SERVER_URL = (process.env.SERVER_URL || (app.isPackaged ? 'https://remote.bizgaze.com' : 'http://localhost:8090')).replace(/\/+$/, '');
let win;
let splash;
let tray = null;
let isQuitting = false; // true only during a real Quit (tray menu / before-quit) — otherwise close = hide to tray
// Close-to-tray: closing the window HIDES it instead of quitting, so the app keeps running in the
// background with its chat WebSocket alive. That's what lets call/message notifications still fire when
// the window is "closed" (General #1/#2) — a fully-quit Electron app gets no push. The tray icon + menu
// bring it back or quit for real.
function createTray() {
if (tray) return;
try {
let img = nativeImage.createFromPath(path.join(__dirname, 'tray.ico'));
if (img.isEmpty()) img = nativeImage.createFromPath(path.join(process.resourcesPath || __dirname, 'tray.ico'));
tray = new Tray(img.isEmpty() ? nativeImage.createEmpty() : img);
tray.setToolTip('Biz Connect');
const showApp = () => { if (!win) return createWindow(); if (win.isMinimized()) win.restore(); win.show(); win.focus(); };
tray.setContextMenu(Menu.buildFromTemplate([
{ label: 'Open Biz Connect', click: showApp },
{ label: 'Refresh app (get latest)', click: () => { showApp(); hardReloadWin(); } },
{ type: 'separator' },
{ label: 'Quit', click: () => { isQuitting = true; app.quit(); } },
]));
tray.on('click', showApp); // single-click (Windows)
tray.on('double-click', showApp);
} catch (_) { tray = null; }
}
// A tiny brand-blue splash (splash.html) shown while the web UI loads, so launch feels instant
// and on-brand instead of a blank window. Closed as soon as the main window is ready to show.
function createSplash() {
splash = new BrowserWindow({
width: 440, height: 440, frame: false, resizable: false, center: true,
backgroundColor: '#1F3B73', skipTaskbar: true, alwaysOnTop: true, show: true,
webPreferences: { contextIsolation: true, nodeIntegration: false },
});
splash.loadFile(path.join(__dirname, 'splash.html'));
splash.on('closed', () => { splash = null; });
}
function closeSplash() { if (splash) { try { splash.close(); } catch (_) {} splash = null; } }
function createWindow() {
win = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 880,
minHeight: 600,
title: 'Biz Connect',
backgroundColor: '#1F3B73',
show: false, // reveal only once the page is ready — the splash covers the gap
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
// Persist cookies/localStorage so the technician stays logged in between launches.
partition: 'persist:bizconnect',
// Keep the renderer at full speed when the window is in the BACKGROUND/minimized. Electron
// throttles hidden windows by default, which stalled the chat WebSocket's onmessage + timers —
// so incoming messages and their notifications only landed when you refocused the app (the
// "notifications slow / messages don't update live" report). Off = real-time even in the tray.
backgroundThrottling: false,
},
});
// Reveal the main window when its first paint is ready, and retire the splash. A fallback
// timer guarantees we never get stuck on the splash if the load stalls.
const reveal = () => { closeSplash(); if (win && !win.isVisible()) { win.show(); win.focus(); } };
win.once('ready-to-show', reveal);
setTimeout(reveal, 12000);
// Every time the window is shown — X-to-tray then reopened, taskbar click, relaunch (second-instance),
// tray icon — check for a new version. This is the catch-all that covers ALL reveal paths (closing the
// window with the X and opening it again included), not just minimize/restore. Throttled to 1/10 min.
win.on('show', () => bgUpdateCheck());
// The menu bar is hidden, so the usual reload accelerators don't exist — wire them by hand. Without
// these there was literally no way to force the app off a stale page.
win.webContents.on('before-input-event', (e, input) => {
if (input.type !== 'keyDown') return;
const k = String(input.key || '').toLowerCase();
const mod = input.control || input.meta;
if ((mod && k === 'r') || k === 'f5') {
e.preventDefault();
if (input.shift || k === 'f5') hardReloadWin(); // hard: clear cache + reload
else { try { win.webContents.reload(); } catch (_) {} } // plain reload
}
});
// Close = hide to tray (keep running for notifications). First time, tell the user where it went.
let toldTray = false;
win.on('close', (e) => {
if (isQuitting) return; // real quit → let it close
e.preventDefault();
win.hide();
if (!toldTray && Notification.isSupported()) {
toldTray = true;
try { const n = new Notification({ title: 'Biz Connect is still running', body: 'It stays in the system tray so you keep getting calls & messages. Quit from the tray icon.' }); n.show(); } catch (_) {}
}
});
// Open the landing page (same entry as the website): the "before login" screen with the
// no-login "Share my screen" option + sign-in. It redirects logged-in users straight to /home.
win.loadURL(SERVER_URL + '/');
// Links: EXTERNAL ones go to the system browser. OUR OWN urls (e.g. a meeting invite link clicked in
// chat) must NOT spawn a second app window (#5) — navigate the main window instead.
win.webContents.setWindowOpenHandler(({ url }) => {
if (!url.startsWith(SERVER_URL)) { shell.openExternal(url); return { action: 'deny' }; }
try { if (win && !win.isDestroyed()) { if (win.isMinimized()) win.restore(); win.show(); win.focus(); win.loadURL(url); } } catch (_) {}
return { action: 'deny' };
});
// Spell-check menu. Two ways in:
// - RIGHT-click: full editing menu (suggestions + cut/copy/paste), the standard desktop behavior.
// - LEFT-click on a misspelled word: the renderer asks us (spell-suggest) to synthesize a
// right-click at that point, so Chromium hands us the real dictionary suggestions — then we show
// a SUGGESTIONS-ONLY menu. This gives the user corrections on a plain left click.
win.webContents.on('context-menu', (_e, params) => {
const fromLeftClick = spellClickPending; spellClickPending = false;
if (fromLeftClick) {
if (!params.misspelledWord) return; // clicked a correctly-spelled word → no menu, don't disturb typing
const menu = new Menu();
for (const s of (params.dictionarySuggestions || [])) menu.append(new MenuItem({ label: s, click: () => win.webContents.replaceMisspelling(s) }));
if (!menu.items.length) menu.append(new MenuItem({ label: 'No suggestions', enabled: false }));
menu.append(new MenuItem({ type: 'separator' }));
menu.append(new MenuItem({ label: 'Add to dictionary', click: () => win.webContents.session.addWordToSpellCheckerDictionary(params.misspelledWord) }));
menu.popup();
return;
}
const menu = new Menu();
for (const s of (params.dictionarySuggestions || [])) {
menu.append(new MenuItem({ label: s, click: () => win.webContents.replaceMisspelling(s) }));
}
if (params.misspelledWord) {
if (params.dictionarySuggestions && params.dictionarySuggestions.length) menu.append(new MenuItem({ type: 'separator' }));
menu.append(new MenuItem({ label: 'Add to dictionary', click: () => win.webContents.session.addWordToSpellCheckerDictionary(params.misspelledWord) }));
}
if (params.isEditable || params.editFlags.canCopy) {
if (menu.items.length) menu.append(new MenuItem({ type: 'separator' }));
if (params.editFlags.canCut) menu.append(new MenuItem({ role: 'cut' }));
if (params.editFlags.canCopy) menu.append(new MenuItem({ role: 'copy' }));
if (params.isEditable) menu.append(new MenuItem({ role: 'paste' }));
if (params.isEditable && params.editFlags.canSelectAll) menu.append(new MenuItem({ role: 'selectAll' }));
}
if (menu.items.length) menu.popup();
});
}
// Set just before we synthesize a right-click from a renderer LEFT-click, so the context-menu handler
// knows to show a suggestions-only menu (and to stay silent on correctly-spelled words).
let spellClickPending = false;
ipcMain.on('spell-suggest', (_e, pos) => {
try {
if (!win || win.isDestroyed() || !pos) return;
const x = Math.round(pos.x), y = Math.round(pos.y);
if (!(x >= 0 && y >= 0)) return;
spellClickPending = true;
win.webContents.sendInputEvent({ type: 'mouseDown', x, y, button: 'right', clickCount: 1 });
win.webContents.sendInputEvent({ type: 'mouseUp', x, y, button: 'right', clickCount: 1 });
setTimeout(() => { spellClickPending = false; }, 500); // guard: clear if no context-menu fired
} catch (_) { spellClickPending = false; }
});
// The full Connect experience needs several web capabilities that Electron denies by
// default. We grant them for our own trusted origin:
// - media → camera + mic for meetings/calls (getUserMedia)
// - display-capture → "Share my screen" (getDisplayMedia)
// - notifications → in-app alerts
// - clipboard, fullscreen, pointerLock → chat paste + meeting UX
// Without this, meetings silently have no camera/mic and notifications never fire.
const GRANTED = new Set([
'media', 'display-capture', 'notifications',
'clipboard-read', 'clipboard-sanitized-write', 'fullscreen', 'pointerLock',
]);
// Custom "Share your screen" picker. Enumerates screens + windows, shows a branded modal grid with
// live thumbnails, and resolves to the chosen desktopCapturer source (or null if cancelled). Replaces
// the unreliable OS system picker. Only one picker at a time.
let pickerWin = null;
function pickShareSource() {
return new Promise((resolve) => {
let settled = false;
const finish = (v) => { if (settled) return; settled = true; ipcMain.removeListener('picker-choose', onChoose); if (pickerWin && !pickerWin.isDestroyed()) { try { pickerWin.close(); } catch (_) {} } pickerWin = null; resolve(v); };
let allSources = [];
const onChoose = (_e, id) => {
if (!id) return finish(null);
finish(allSources.find((s) => s.id === id) || null);
};
desktopCapturer.getSources({ types: ['screen', 'window'], thumbnailSize: { width: 320, height: 200 }, fetchWindowIcons: true })
.then((sources) => {
allSources = sources;
const payload = { screen: [], window: [] };
for (const s of sources) {
const bucket = s.id.startsWith('screen:') ? 'screen' : 'window';
payload[bucket].push({
id: s.id,
name: s.name || (bucket === 'screen' ? 'Screen' : 'Window'),
thumb: s.thumbnail ? s.thumbnail.toDataURL() : '',
appIcon: s.appIcon && !s.appIcon.isEmpty() ? s.appIcon.toDataURL() : null,
});
}
if (pickerWin && !pickerWin.isDestroyed()) { try { pickerWin.close(); } catch (_) {} }
pickerWin = new BrowserWindow({
width: 760, height: 560, parent: win || undefined, modal: !!win, resizable: true,
minimizable: false, maximizable: false, title: 'Share your screen', backgroundColor: '#f4f6fb',
show: false, autoHideMenuBar: true,
webPreferences: { preload: undefined, nodeIntegration: true, contextIsolation: false },
});
pickerWin.setMenu(null);
pickerWin.loadFile(path.join(__dirname, 'picker.html'));
pickerWin.once('ready-to-show', () => { pickerWin.show(); pickerWin.webContents.send('picker-sources', payload); });
pickerWin.on('closed', () => { if (!settled) finish(null); }); // closed via the X → cancel
ipcMain.on('picker-choose', onChoose);
})
.catch(() => finish(null));
});
}
function configureSession() {
const ses = session.fromPartition('persist:bizconnect');
// getDisplayMedia: show OUR OWN branded screen/window picker. The Electron `useSystemPicker`
// option silently no-ops on many Windows 11 builds (it needs a specific WebRTC feature) and then
// auto-shares the primary display with no choice — which is exactly the "no picker appears" bug.
// So we enumerate sources ourselves and pop a picker window (pickShareSource) to let the user
// pick a specific screen or window.
ses.setDisplayMediaRequestHandler((request, callback) => {
pickShareSource().then((source) => {
callback(source ? { video: source, audio: 'loopback' } : {}); // {} = user cancelled → no share
}).catch(() => callback({}));
}, { useSystemPicker: false });
// Async grant (getUserMedia, notifications, …)
ses.setPermissionRequestHandler((_wc, permission, callback) => callback(GRANTED.has(permission)));
// Sync check (some getUserMedia paths query this before requesting)
ses.setPermissionCheckHandler((_wc, permission) => GRANTED.has(permission));
// Spell check for the message box (red squiggles) with right-click corrections. Uses the OS
// dictionaries; en-US by default plus whatever the OS UI language is, so mixed typing still checks.
try {
ses.setSpellCheckerEnabled(true);
const langs = ['en-US'];
const sys = (app.getLocale && app.getLocale()) || '';
const avail = (ses.availableSpellCheckerLanguages || []);
if (sys && sys !== 'en-US' && (!avail.length || avail.includes(sys))) langs.push(sys);
ses.setSpellCheckerLanguages(langs);
} catch (_) {}
// Downloads go STRAIGHT to the OS Downloads folder — no "where do you want to save?" dialog. If a file of
// the same name already exists, suffix " (n)" so nothing is overwritten. (item.setSavePath suppresses the
// save dialog entirely.)
ses.on('will-download', (_e, item) => {
try {
const dir = app.getPath('downloads');
const name = item.getFilename() || 'download';
const ext = path.extname(name), base = path.basename(name, ext);
let target = path.join(dir, name), n = 1;
while (fs.existsSync(target)) target = path.join(dir, `${base} (${n++})${ext}`);
item.setSavePath(target);
// Since we suppressed the save dialog, the download would otherwise be completely silent. Give feedback
// when it finishes: a notification (click → reveal the file in Explorer) so the user knows it saved and
// where. Also tell the web UI so it can show its own toast. On failure, say so.
item.once('done', (_ev, state) => {
try {
const ok = state === 'completed';
const savedName = ok ? path.basename(target) : (item.getFilename() || 'file');
// Always tell the web UI (it shows a branded toast when the window is up).
try { if (win && !win.isDestroyed()) win.webContents.send('download-done', { name: savedName, path: ok ? target : '', ok }); } catch (_) {}
// If the window is focused, that toast is enough — skip the native notification to avoid a double
// notice. If the app is minimized/in the tray, show a native notification instead (click → reveal).
const focused = win && !win.isDestroyed() && win.isVisible() && win.isFocused();
if (!focused && Notification.isSupported()) {
if (ok) { const note = new Notification({ title: 'Download complete', body: savedName + ' — saved to your Downloads folder. Click to show it.' }); note.on('click', () => { try { shell.showItemInFolder(target); } catch (_) {} }); note.show(); }
else new Notification({ title: 'Download failed', body: savedName + ' could not be saved.' }).show();
}
} catch (_) {}
});
} catch (_) {}
});
}
// Single-instance: a tray app must not spawn a second copy. If another launch happens, focus the
// existing window (restoring it from the tray) instead.
if (!app.requestSingleInstanceLock()) {
app.quit();
} else {
app.on('second-instance', () => { if (win) { if (win.isMinimized()) win.restore(); win.show(); win.focus(); } });
}
app.on('before-quit', () => { isQuitting = true; });
app.whenReady().then(() => {
configureSession();
createSplash();
createWindow();
createTray(); // keep the app reachable while its window is hidden to tray
Menu.setApplicationMenu(null); // hide the default menu bar; the web UI is the chrome
app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); else if (win) { win.show(); win.focus(); } });
// Check for shell updates on launch, then every 6 hours. Only in packaged builds.
if (app.isPackaged && autoUpdater) {
// #3: surface update progress to the web UI so the user can SEE an update is downloading /
// installing, instead of it happening silently in the background.
const sendUpdate = (data) => { try { if (win && !win.isDestroyed()) win.webContents.send('update-event', data); } catch (_) {} };
autoUpdater.on('checking-for-update', () => sendUpdate({ phase: 'checking' }));
autoUpdater.on('update-available', (info) => sendUpdate({ phase: 'available', version: info && info.version }));
autoUpdater.on('update-not-available', () => sendUpdate({ phase: 'current' }));
autoUpdater.on('download-progress', (p) => sendUpdate({ phase: 'downloading', percent: Math.round((p && p.percent) || 0) }));
autoUpdater.on('error', () => sendUpdate({ phase: 'error' }));
// When an update finishes downloading, tell the web UI so it can show a BRANDED "Update ready —
// Restart now" banner (restartToUpdate IPC does the install). No native dialog — that was
// unbranded. It still installs on next launch if the user never clicks Restart.
autoUpdater.on('update-downloaded', (info) => {
sendUpdate({ phase: 'ready', version: info && info.version });
// If the window is hidden in the tray, the branded in-app banner isn't visible — nudge with a native
// notification so tray users know an update is waiting (it also installs automatically on next quit).
try { if ((!win || !win.isVisible()) && Notification.isSupported()) new Notification({ title: 'Biz Connect update ready', body: 'Version ' + ((info && info.version) || '') + ' installs when you restart. Open Biz Connect to restart now.' }).show(); } catch (_) {}
});
// Install a downloaded update on the next real quit (PC restart / tray-Quit) even if the user never
// clicks "Restart now" — so close-to-tray users don't get stuck on an old version. (This is the
// electron-updater default; set explicitly to be safe.)
autoUpdater.autoInstallOnAppQuit = true;
// checkForUpdates (NOT ...AndNotify): ...AndNotify pops electron-updater's OWN native "Update ready
// — Restart/Later" toast on download, which duplicated our branded in-app banner (the user saw TWO
// restart prompts). Plain checkForUpdates still auto-downloads and fires 'update-downloaded'.
bgUpdateCheck();
setInterval(bgUpdateCheck, 6 * 60 * 60 * 1000);
}
});
// With close-to-tray the window is HIDDEN, not destroyed, so this normally won't fire while the app is
// meant to keep running. Only quit here if we're actually quitting (belt-and-braces).
app.on('window-all-closed', () => { if (isQuitting && process.platform !== 'darwin') app.quit(); });
+5676
View File
File diff suppressed because it is too large Load Diff
+59
View File
@@ -0,0 +1,59 @@
{
"name": "biz-connect-desktop",
"version": "0.1.20",
"description": "Biz Connect technician desktop client — loads the Connect web UI with native screen capture",
"author": {
"name": "BizGaze",
"email": "support@bizgaze.com"
},
"main": "main.js",
"scripts": {
"start": "electron .",
"dist": "electron-builder"
},
"dependencies": {
"electron-updater": "^6.3.9"
},
"optionalDependencies": {
"@nut-tree-fork/nut-js": "^4.2.0"
},
"devDependencies": {
"electron": "^31.0.0",
"electron-builder": "^24.13.3"
},
"build": {
"appId": "com.bizgaze.connect.desktop",
"productName": "Biz Connect",
"directories": {
"buildResources": "build",
"output": "dist"
},
"publish": [
{
"provider": "generic",
"url": "https://remote.bizgaze.com/downloads/"
}
],
"win": {
"target": "nsis",
"icon": "build/icon.ico"
},
"nsis": {
"oneClick": true,
"perMachine": false,
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "Biz Connect",
"runAfterFinish": true
},
"mac": {
"target": "dmg",
"category": "public.app-category.business",
"icon": "build/icon.ico"
},
"linux": {
"target": "AppImage",
"category": "Network"
}
}
}
+83
View File
@@ -0,0 +1,83 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'">
<title>Choose what to share</title>
<style>
:root{ --brand:#1F3B73; --bg:#f4f6fb; --card:#fff; --line:#e3e8f2; --muted:#64748b; }
*{ box-sizing:border-box; }
html,body{ margin:0; height:100%; font-family:'Segoe UI',system-ui,sans-serif; background:var(--bg); color:#0f172a; }
.wrap{ display:flex; flex-direction:column; height:100%; }
header{ padding:16px 20px 10px; }
header h1{ margin:0; font-size:17px; font-weight:700; color:var(--brand); }
header p{ margin:3px 0 0; font-size:12.5px; color:var(--muted); }
.tabs{ display:flex; gap:6px; padding:8px 20px 0; }
.tab{ border:0; background:transparent; font:inherit; font-size:13px; font-weight:600; color:var(--muted); padding:7px 12px; border-radius:8px 8px 0 0; cursor:pointer; }
.tab.on{ color:var(--brand); background:var(--card); box-shadow:inset 0 -2px 0 var(--brand); }
.grid{ flex:1; overflow:auto; display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:12px; padding:14px 20px; align-content:start; }
.src{ background:var(--card); border:1.5px solid var(--line); border-radius:12px; padding:8px; cursor:pointer; text-align:left; font:inherit; transition:border-color .12s, transform .08s; overflow:hidden; }
.src:hover{ border-color:var(--brand); transform:translateY(-1px); }
.src.sel{ border-color:var(--brand); box-shadow:0 0 0 2px rgba(31,59,115,.18); }
.thumb{ width:100%; height:112px; border-radius:8px; background:#0b1220; object-fit:contain; display:block; }
.meta{ display:flex; align-items:center; gap:7px; padding:8px 4px 2px; }
.appic{ width:18px; height:18px; border-radius:4px; flex:0 0 auto; }
.nm{ font-size:12.5px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.empty{ grid-column:1/-1; text-align:center; color:var(--muted); font-size:13px; padding:40px 0; }
footer{ display:flex; justify-content:flex-end; gap:10px; padding:12px 20px; border-top:1px solid var(--line); background:var(--card); }
button.act{ font:inherit; font-size:13.5px; font-weight:600; padding:9px 18px; border-radius:9px; cursor:pointer; border:1.5px solid var(--line); background:#fff; color:#334155; }
button.act.primary{ background:var(--brand); border-color:var(--brand); color:#fff; }
button.act.primary:disabled{ opacity:.45; cursor:default; }
</style>
</head>
<body>
<div class="wrap">
<header>
<h1>Share your screen</h1>
<p>Choose a screen or a window to share with the call.</p>
</header>
<div class="tabs">
<button class="tab on" data-t="screen">Entire screen</button>
<button class="tab" data-t="window">Application window</button>
</div>
<div class="grid" id="grid"></div>
<footer>
<button class="act" id="cancel">Cancel</button>
<button class="act primary" id="share" disabled>Share</button>
</footer>
</div>
<script>
const { ipcRenderer } = require('electron');
let SOURCES = { screen:[], window:[] };
let tab='screen', selected=null;
ipcRenderer.on('picker-sources', (_e, data)=>{ SOURCES=data||{screen:[],window:[]}; render(); });
document.querySelectorAll('.tab').forEach(b=>b.onclick=()=>{
tab=b.dataset.t; selected=null; document.getElementById('share').disabled=true;
document.querySelectorAll('.tab').forEach(x=>x.classList.toggle('on', x===b));
render();
});
document.getElementById('cancel').onclick=()=>ipcRenderer.send('picker-choose', null);
document.getElementById('share').onclick=()=>{ if(selected) ipcRenderer.send('picker-choose', selected); };
window.addEventListener('keydown', e=>{ if(e.key==='Escape') ipcRenderer.send('picker-choose', null); });
function render(){
const grid=document.getElementById('grid'); grid.innerHTML='';
const list=SOURCES[tab]||[];
if(!list.length){ grid.innerHTML='<div class="empty">Nothing available to share here.</div>'; return; }
list.forEach(s=>{
const card=document.createElement('button'); card.className='src'; card.dataset.id=s.id;
const ap = s.appIcon ? '<img class="appic" src="'+s.appIcon+'">' : '';
card.innerHTML='<img class="thumb" src="'+s.thumb+'">'
+ '<div class="meta">'+ap+'<span class="nm">'+esc(s.name||'Untitled')+'</span></div>';
card.onclick=()=>{ selected=s.id; document.getElementById('share').disabled=false;
document.querySelectorAll('.src').forEach(x=>x.classList.toggle('sel', x===card)); };
card.ondblclick=()=>{ selected=s.id; ipcRenderer.send('picker-choose', selected); };
grid.appendChild(card);
});
}
function esc(s){ return String(s).replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c])); }
</script>
</body>
</html>
+48
View File
@@ -0,0 +1,48 @@
// Minimal, safe bridge into the web UI. Runs with contextIsolation, so it only exposes a
// frozen marker the web app can feature-detect against (e.g. to hide the PWA install prompt
// or prefer native push). No Node APIs are exposed to page JS.
const { contextBridge, ipcRenderer } = require('electron');
// Pull the stable install id + version/os from main (synchronous, one-time at preload).
let info = { installId: '', appVersion: '', os: '' };
try { info = ipcRenderer.sendSync('get-install-info') || info; } catch (_) {}
contextBridge.exposeInMainWorld('__NATIVE__', 'desktop');
contextBridge.exposeInMainWorld('bizConnectNative', Object.freeze({
platform: 'desktop',
version: info.appVersion || '0.1.0',
installId: info.installId || '',
os: info.os || '',
// Bring the app window to the foreground (e.g. when a notification is clicked) — the web
// Notification's window.focus() can't raise an Electron window; the main process must.
focusApp: () => ipcRenderer.send('focus-window'),
// Show the unread-chat count as a badge on the taskbar icon. count=number of chats with
// unread; dataUrl=a small PNG badge the renderer drew (null to clear).
setUnread: (count, dataUrl) => ipcRenderer.send('set-unread', { count, dataUrl }),
// Native Windows toast with an inline reply box. Resolves to {text} (replied), {open} (clicked)
// or null. Lets the user reply to a chat straight from the notification.
replyNotify: (payload) => ipcRenderer.invoke('reply-notification', payload),
// Pre-warm the notification DP cache with contact photo URLs (called after chats load) so the first
// toast from anyone already has their photo — no per-notification download lag.
precacheAvatars: (urls) => { try { return ipcRenderer.invoke('precache-avatars', urls); } catch (_) { return Promise.resolve(false); } },
// Ask the shell to show native spelling suggestions for the word at page coords (x,y) — used to bring
// up corrections on a LEFT click in the message box (not just right-click).
spellSuggestAt: (x, y) => { try { ipcRenderer.send('spell-suggest', { x, y }); } catch (_) {} },
// Remote control (screen the local user is sharing): whether OS injection is possible on this machine,
// arm/disarm the consent gate, and forward a viewer's input event for injection. Injection only happens
// while armed (the user granted control) — see main.js rcArmed.
rcAvailable: () => { try { return !!ipcRenderer.sendSync('rc-available'); } catch (_) { return false; } },
rcArm: (on) => { try { ipcRenderer.send('rc-arm', !!on); } catch (_) {} },
rcInput: (evt) => { try { ipcRenderer.send('rc-input', evt); } catch (_) {} },
// Force the newest web build: clears the shell's HTTP cache and reloads ignoring cache. The app closes
// to tray and can run for weeks, so without this it would keep serving the page it first loaded.
hardReload: () => { try { return ipcRenderer.invoke('hard-reload'); } catch (_) { return Promise.resolve(false); } },
// Manual "Check for updates" from Settings. Resolves {status:'available'|'current'|'dev'|'error', version?}.
// On 'available' the shell downloads in the background and prompts to restart when ready.
checkForUpdates: () => ipcRenderer.invoke('check-updates'),
// #3: subscribe to auto-update lifecycle events so the UI can show download progress + "ready".
// cb receives {phase:'checking'|'available'|'downloading'|'ready'|'current'|'error', percent?, version?}.
onUpdateEvent: (cb) => { try { ipcRenderer.on('update-event', (_e, data) => { try { cb(data); } catch (_) {} }); } catch (_) {} },
onDownloadDone: (cb) => { try { ipcRenderer.on('download-done', (_e, data) => { try { cb(data); } catch (_) {} }); } catch (_) {} }, // desktop: a file finished downloading to the Downloads folder → show a toast
restartToUpdate: () => ipcRenderer.invoke('restart-to-update'),
}));
+26
View File
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
html,body{margin:0;height:100%;overflow:hidden;}
body{background:#1F3B73;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:22px;
font-family:'Segoe UI',system-ui,sans-serif;-webkit-user-select:none;user-select:none;}
/* Branded orbit mark (white C + circling yellow dot) — matches the app icon/loader */
.mark{width:96px;height:96px;}
.mark .dot{transform-origin:50px 50px;animation:spin 1.1s linear infinite;}
@keyframes spin{to{transform:rotate(360deg);}}
.name{color:#fff;font-size:20px;font-weight:700;letter-spacing:.3px;}
.name b{color:#FFC708;font-weight:700;}
.sub{color:rgba(255,255,255,.66);font-size:12.5px;margin-top:-14px;}
</style>
</head>
<body>
<svg class="mark" viewBox="0 0 100 100" aria-label="Biz Connect">
<circle cx="50" cy="50" r="34" fill="none" stroke="#ffffff" stroke-width="9" stroke-linecap="round" stroke-dasharray="165 300" transform="rotate(38 50 50)"/>
<g class="dot"><circle cx="84" cy="50" r="7" fill="#FFC708"/></g>
</svg>
<div class="name">Biz <b>Connect</b></div>
<div class="sub">Starting…</div>
</body>
</html>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+83 -2
View File
@@ -10,7 +10,19 @@ services:
restart: unless-stopped
environment:
- PORT=8090
- DB_PATH=/data/data.db
# Desktop installers + auto-update feed live on the persistent volume so uploaded
# builds survive image rebuilds (a plain image path would be wiped on every deploy).
- DOWNLOADS_DIR=/data/downloads
# Chat uploads / recordings / transcripts on the persistent volume too, so they survive image
# rebuilds (otherwise old shared images 404 as "broken image" after every deploy).
- UPLOADS_DIR=/data/uploads
# Max chat-attachment size in MB (default 1024 = 1 GB). The app streams uploads to /data/uploads, so
# large files don't buffer in memory. IMPORTANT: also set Nginx Proxy Manager's client_max_body_size
# for remote.bizgaze.com to at least this (Advanced tab: `client_max_body_size 1024m;`) or the proxy
# rejects big uploads before they reach the app.
- MAX_UPLOAD_MB=1024
- REC_DIR=/data/recordings
- TRANS_DIR=/data/transcripts
# Secrets (TURN credentials, SSO_SECRET, BIZGAZE_WEBHOOK_URL, etc.) live in
# a .env file next to this compose file. It is gitignored — never committed.
# See .env.example for the expected keys.
@@ -18,7 +30,75 @@ services:
- path: .env
required: false
volumes:
- bizgaze_support_data:/data # persists data.db across rebuilds
- bizgaze_support_data:/data # persists uploads / recordings / transcripts / downloads across rebuilds
networks:
- npm
# The DB is Postgres (SQLite retired 2026-08-12), so wait for it to be healthy before the app starts —
# otherwise the first queries race the DB coming up.
depends_on:
bizgazepg:
condition: service_healthy
# PostgreSQL — the app's data store (DB_BACKEND=pg; the only backend since SQLite was retired). Distinct
# service/container name so it never collides with the other postgres containers on the shared NPM
# network; the app reaches it as `bizgaze-postgres`. Data on its own named volume.
bizgazepg:
image: postgres:16
container_name: bizgaze-postgres
restart: unless-stopped
environment:
- POSTGRES_USER=bizgaze
- POSTGRES_DB=bizgaze
# Password comes from the same .env as the app (compose interpolates ${...} from the .env in this dir).
# NOTE: Postgres only applies POSTGRES_PASSWORD on FIRST init of an empty data volume.
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-bizgaze_local}
volumes:
- bizgaze_pg_data:/var/lib/postgresql/data
networks:
- npm
healthcheck:
test: ["CMD-SHELL", "pg_isready -U bizgaze -d bizgaze"]
interval: 5s
timeout: 3s
retries: 12
# Redis — cross-instance real-time fan-out (chat/presence), used only when PUBSUB_BACKEND=redis. Dormant
# by default (behind the 'scale' profile, like livekit), so a normal deploy never starts it and the app
# stays single-instance on the in-memory pubsub. To run multiple app instances: start this
# (`docker compose --profile scale up -d`), set PUBSUB_BACKEND=redis + REDIS_URL in .env, and put the app
# behind a load balancer with sticky sessions for the /ws WebSocket. (Meeting SIGNALING state is still
# per-process — cross-instance meetings need sticky routing or further work; chat/presence fan out here.)
bizgazeredis:
image: redis:7-alpine
container_name: bizgaze-redis
restart: unless-stopped
profiles: ["scale"]
networks:
- npm
# LiveKit SFU — meeting media server. Optional: only started/used when the app's .env has
# LIVEKIT_URL/API_KEY/API_SECRET set (otherwise meetings use the built-in P2P mesh). NPM proxies
# wss://livekit.bizgaze.com -> livekit:7880 (signaling); media flows over the published UDP/TCP
# ports below, NOT through NPM. Single-node (no Redis) — consistent with the app's single-instance rule.
livekit:
# v1.8+ implements the /rtc/v1 signaling path (protocol 17) that the bundled
# livekit-client@2.20 uses. On the older v1.7 the client fell back to the legacy path and
# track publishing broke (mic/cam wouldn't turn on). Keep this within one minor of the client.
image: livekit/livekit-server:v1.9
container_name: bizgaze-livekit
restart: unless-stopped
# Dormant by default: a normal `docker compose up -d` / deploy.sh does NOT start it. Enable SFU
# explicitly with `docker compose --profile sfu up -d` after setting the LIVEKIT_* vars (see DEPLOY.md).
profiles: ["sfu"]
command: --config /etc/livekit.yaml
environment:
# key: secret, sourced from the same .env as the app so both sign/verify with the same secret.
- "LIVEKIT_KEYS=${LIVEKIT_API_KEY}: ${LIVEKIT_API_SECRET}"
volumes:
- ./livekit.yaml:/etc/livekit.yaml:ro
ports:
- "7881:7881" # WebRTC over TCP (fallback)
- "50000:50000/udp" # single WebRTC media UDP port (must match livekit.yaml rtc.udp_port)
networks:
- npm
@@ -29,3 +109,4 @@ networks:
volumes:
bizgaze_support_data:
bizgaze_pg_data:
+87
View File
@@ -0,0 +1,87 @@
# coturn + app config for TURN (remote.bizgaze.com)
Status: self-hosted **coturn** is working on **UDP 3478** (verified — a `relay`
candidate was returned by the Trickle ICE test). This doc adds **TCP 3478** and
optional **TLS 5349** for wider firewall coverage, and points the BizGaze Connect
app at coturn.
TURN makes the WebRTC *connection* work across cellular / strict NATs. It does NOT
let a phone share its screen in a browser — that is a separate platform limitation.
---
## 1. coturn — turnserver.conf
Verify the first block (already working) and ADD the TLS block.
```conf
# --- core (already working on UDP 3478) ---
listening-port=3478 # serves BOTH UDP and TCP on 3478
fingerprint
lt-cred-mech
realm=remote.bizgaze.com
external-ip=118.95.33.89 # coturn server's PUBLIC ip (from the relay result)
user=USERNAME:PASSWORD # the TURN username:password
# --- ADD: TLS on 5349 (turns:) ---
tls-listening-port=5349
cert=/etc/letsencrypt/live/remote.bizgaze.com/fullchain.pem
pkey=/etc/letsencrypt/live/remote.bizgaze.com/privkey.pem
# --- relay media port range (must be open in the firewall) ---
min-port=49152
max-port=65535
```
Notes:
- TLS needs a cert for `remote.bizgaze.com`. Nginx Proxy Manager already issues a
Let's Encrypt cert for that host — point coturn at those `fullchain.pem` /
`privkey.pem` (copy or mount them so coturn can read them).
- TCP 3478 alone already widens coverage a lot; TLS/5349 can be added later.
Restart coturn after editing:
```
systemctl restart coturn # or: restart the coturn container
```
---
## 2. Firewall / cloud security group — open these ports
- UDP 3478 (already open — relay works)
- TCP 3478 <- add
- TCP 5349 <- add (only if doing TLS)
- UDP 49152-65535 (relay media range; should already be open)
---
## 3. App .env (next to docker-compose.yml)
Point BizGaze Connect at coturn. Without TLS yet:
```env
TURN_URLS=turn:remote.bizgaze.com:3478,turn:remote.bizgaze.com:3478?transport=tcp
TURN_USERNAME=your-coturn-username
TURN_CREDENTIAL=your-coturn-password
```
After TLS (5349) is confirmed working, use:
```env
TURN_URLS=turn:remote.bizgaze.com:3478,turn:remote.bizgaze.com:3478?transport=tcp,turns:remote.bizgaze.com:5349?transport=tcp
TURN_USERNAME=your-coturn-username
TURN_CREDENTIAL=your-coturn-password
```
Reload the app:
```
docker compose up -d
```
---
## 4. Verify
1. Open `https://remote.bizgaze.com/api/ice` — should show the
`remote.bizgaze.com` TURN entry with the username.
(The app only *sends* TURN to mobile clients by design, but /api/ice still lists it.)
2. Trickle ICE test (https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/):
- Add `turn:remote.bizgaze.com:3478?transport=tcp` + username + credential → expect a `relay` row.
- If TLS is set up, also test `turns:remote.bizgaze.com:5349?transport=tcp`.
A `relay` candidate = success. No relay row = TURN not reachable on that transport.
+23
View File
@@ -0,0 +1,23 @@
# LiveKit SFU config (non-secret — the API key/secret are injected via the LIVEKIT_KEYS env var
# in docker-compose, sourced from .env, so nothing secret lives in git).
#
# Media plane: LiveKit needs UDP reachable from clients (NPM only proxies the HTTP/WS signaling on
# 7880). The UDP range + TCP fallback below are published as HOST ports in docker-compose. On the
# VPS, if the server sits behind NAT and can't auto-detect its public IP, set rtc.node_ip to it.
port: 7880 # signaling (HTTP/WS) — NPM proxies wss://livekit.bizgaze.com -> here
rtc:
tcp_port: 7881 # WebRTC-over-TCP fallback (restrictive networks)
udp_port: 50000 # SINGLE UDP media port (all participants mux over it) — minimizes
# the NAT port-forward to one UDP + one TCP port.
# This box sits behind NAT (private 192.168.88.61 behind public 118.95.33.89). Auto-detection
# would find the wrong (outbound) IP, so pin the inbound public IP clients actually reach.
use_external_ip: false
node_ip: 118.95.33.89
# Embedded TURN over TLS on 443 helps clients on locked-down networks. Left off by default because
# NPM already owns 443; enable via a dedicated hostname + NPM stream if you need it (see DEPLOY.md).
turn:
enabled: false
logging:
level: info
+110
View File
@@ -0,0 +1,110 @@
# Biz Connect — Android build & push setup
Step-by-step to go from this repo to a running Android app with working FCM push.
You have **Android Studio (Quail 2026.1.1)** installed — that bundles the Android SDK and a
JDK, so no separate Java install is needed.
> The app is a Capacitor shell that loads the live Connect UI (`server.url` in
> `capacitor.config.json`, default `https://remote.bizgaze.com`). The native side only adds
> push, camera/mic, status bar, and store packaging. App id / Android package:
> **`com.bizgaze.connect`** — this must match the Firebase app you create below.
---
## 1. One-time Android Studio setup
1. Launch Android Studio once and let it finish "SDK Components Setup" (downloads the
Android SDK + platform-tools).
2. **More Actions → SDK Manager** → install **Android SDK Platform 34** (or latest) and
**Android SDK Build-Tools**.
3. To test on an emulator: **More Actions → Virtual Device Manager** → create a Pixel device
(any recent API ≥ 33 so you can test the notification permission prompt). Or enable
**USB debugging** on a physical phone and plug it in.
## 2. Generate the native Android project
```bash
cd mobile
npm install
npm run assets # builds icons/splash from resources/ (already provided)
npx cap add android # creates mobile/android/ (gitignored)
npx cap sync # copies config + web assets + plugins into the project
```
## 3. App permissions
Capacitor adds `INTERNET` automatically. Add the rest to
`mobile/android/app/src/main/AndroidManifest.xml` (inside `<manifest>`, above `<application>`).
A ready-to-paste copy is in [`android-permissions.xml`](android-permissions.xml):
```xml
<!-- Push (Android 13+ runtime prompt) -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<!-- Voice / video calls + camera from the web UI -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
```
> WebRTC in the WebView: Capacitor grants `getUserMedia` to the page when the app holds the
> CAMERA/RECORD_AUDIO permissions, so the existing call/screen-share UI works once these are
> present and the user accepts the runtime prompts.
## 4. Firebase / FCM (push)
1. [Firebase console](https://console.firebase.google.com) → **Add project** (or reuse one).
2. **Add app → Android**. Package name: **`com.bizgaze.connect`**. Register.
3. Download **`google-services.json`** → place it in **`mobile/android/app/`**.
4. Add the Google Services Gradle plugin (Capacitor 6 template):
- `mobile/android/build.gradle``buildscript { dependencies { ... } }`:
```gradle
classpath 'com.google.gms:google-services:4.4.2'
```
- **bottom** of `mobile/android/app/build.gradle`:
```gradle
apply plugin: 'com.google.gms.google-services'
```
5. `npx cap sync` again.
That's the **client** half. The **server** half (already built) needs the matching credential:
- Firebase console → **Project settings → Service accounts → Generate new private key** →
download the JSON.
- On the production server, set **`FCM_SERVICE_ACCOUNT`** to that file's path (or its inline
JSON) and restart. See [../DEPLOY.md](../DEPLOY.md). With that set, `push.sendToUser`
delivers to Android devices automatically; the app already registers its token via
`POST /api/v1/devices` on launch (see `setupNativePush` in `server/public/home.html`).
## 5. Run it
```bash
npx cap open android # opens the project in Android Studio → press Run ▶
# or headless:
npx cap run android
```
First launch will prompt for notifications (Android 13+); accept it, then check the server log
/ DB `device_tokens` shows a row for your user.
### Testing against a LOCAL dev server (optional)
The app points at `https://remote.bizgaze.com` by default. To hit your laptop instead, edit
`capacitor.config.json`:
```json
"server": { "url": "http://<your-LAN-IP>:8090", "cleartext": true, "androidScheme": "https" }
```
then `npx cap sync`. (`cleartext` is required for plain `http`.) Revert before shipping.
## 6. Build for the Play Store
1. Create an upload keystore (once):
```bash
keytool -genkey -v -keystore biz-connect.keystore -alias bizconnect -keyalg RSA -keysize 2048 -validity 10000
```
2. Android Studio → **Build → Generate Signed App Bundle** → AAB → select the keystore.
(Or `cd android && ./gradlew bundleRelease`.)
3. Upload the `.aab` to **Google Play Console** (one-time $25 developer account). Fill in the
store listing, data-safety form (declare camera/mic/notifications), and roll out to
internal testing first.
---
## Checklist
- [ ] Android Studio SDK + an emulator/device ready
- [ ] `npm install` → `npm run assets` → `npx cap add android` → `npx cap sync`
- [ ] Permissions added to AndroidManifest
- [ ] `google-services.json` in `android/app/` + Gradle plugin lines + `cap sync`
- [ ] App runs; notification permission accepted; `device_tokens` row appears
- [ ] Server `FCM_SERVICE_ACCOUNT` set in prod → end-to-end push works
- [ ] Signed AAB built and uploaded to Play (internal testing)
+159
View File
@@ -0,0 +1,159 @@
# Biz Connect — App Store submission pack
Everything App Store Connect asks for, drafted. Fill the **`<< … >>`** placeholders (they're
account-specific or secret and must NOT be committed). Order below ≈ the order App Store Connect walks you through.
---
## 0. Before you submit (gates that cause rejection)
- [x] **Verified build** uploaded from Codemagic to App Store Connect (splash build; multi-device tiles, transcripts, calls ring; moderation + meeting-push are live web-side).
- [x] **Reviewer demo account** — connect@bizgaze.com / Qwerty@789 (works; non-admin so it sees Report/Block but not the admin Reports view).
- [x] **Privacy Policy URL** — https://remote.bizgaze.com/privacy (live, public).
- [x] **Support URL** — https://remote.bizgaze.com/support (live, public).
- [x] **Screenshots** — 6.9" set (1320×2868) in mobile/appstore-screenshots/ (01-chats, 02-conversation, 03-meetings).
- [x] **Export compliance** — ITSAppUsesNonExemptEncryption=false baked into the build (App Store Connect won't ask).
---
## 1. App information
| Field | Value |
|---|---|
| **App name** | BizGaze Connect (App Store listing name; renamed 2026-08-21) |
| **Subtitle** (30 char max) | Team chat, calls & meetings |
| **Primary category** | Business |
| **Secondary category** | Productivity |
| **Bundle ID** | com.bizgaze.connect |
| **Privacy Policy URL** | https://remote.bizgaze.com/privacy |
| **Support URL** | https://remote.bizgaze.com/support |
| **Marketing URL** (optional) | leave blank, or your product page |
| **Age rating** | 4+ (answer all content questions "None". Note: user-generated content via chat — see §8) |
---
## 2. Description
> Biz Connect keeps your team connected — chat, voice and video calls, and meetings, in one place.
>
> **Chat that works the way your team does**
> • Direct messages and group conversations
> • Reactions, replies, mentions, pinned messages, and polls
> • Share photos, videos, and files
> • Read receipts and typing indicators
>
> **Calls that ring like a real phone**
> • One-to-one and group voice & video calls
> • Full-screen incoming call ringing, even when the app is closed
> • Calls keep working when you switch apps or lock your phone
>
> **Meetings, built in**
> • Start instantly or schedule ahead
> • Screen sharing and camera, front or back
> • Live transcripts you can save and download
> • Meeting recordings for later
>
> **Everywhere you are**
> Your conversations stay in sync across iPhone, desktop, and the web.
>
> Biz Connect is for organizations using the BizGaze platform. Sign in with your BizGaze account to get started.
**Keywords** (100 char max, comma-separated, no spaces after commas):
`team chat,business messaging,video call,voice call,meetings,screen share,transcript,collaboration,work`
**Promotional text** (170 char, editable without a new build):
> Chat, call, and meet with your team — with real-phone-style ringing, screen sharing, and live meeting transcripts.
---
## 3. What's New (release notes for this version)
> • Live meeting transcripts on iPhone — for both calls and scheduled meetings
> • Join the same meeting from two devices at once, each as its own participant
> • Stability and audio-routing improvements
---
## 4. App Privacy ("nutrition label")
Answer these in App Store Connect → App Privacy. **Verify each against what the BizGaze backend actually stores**
before publishing — this is a legal declaration. Sensible defaults for a business comms app:
**Data used to identify the user (Linked to identity):**
- **Contact Info → Name, Email address** — App Functionality, Account management. (BizGaze login.)
- **User Content → Photos or Videos, Other User Content (messages, files)** — App Functionality. (Chat/meeting content stored on your server.)
- **Identifiers → User ID** — App Functionality.
**Diagnostics / Usage:** declare only if you actually collect analytics/crash data. If not, mark **"Data Not Collected"** for those.
**Important clarifications to make in the notes:**
- **Microphone & Camera** audio/video for calls is transmitted between participants (via your LiveKit server) but is only *recorded/stored* when a user explicitly starts a recording or transcript. Say so.
- **Speech recognition** for transcripts runs **on-device** (Apple's `SFSpeechRecognizer`, on-device mode) — the audio is not sent to Apple, and only the finished text is added to the meeting transcript. This is a good thing to state explicitly; it reassures review.
- **Third-party:** if BizGaze/LiveKit are your own infrastructure, no third-party SDK data-sharing to declare. Confirm you have no analytics/ad SDKs.
**Privacy usage strings** (already in the build via `ios-patch.sh` — for reference):
- Camera: "Biz Connect uses the camera for video calls and to share photos and your screen."
- Microphone: "Biz Connect uses the microphone for voice and video calls."
- Speech Recognition: "Biz Connect uses speech recognition to create live meeting transcripts from your microphone."
- Photo Library / Add: send/save images.
---
## 5. Screenshots
Required (App Store Connect accepts one size and scales, but do at least these two):
- [ ] **6.9" iPhone** (1320 × 2868) — iPhone 16 Pro Max class
- [ ] **6.5" iPhone** (1242 × 2688) — fallback for older devices
- [ ] (Optional) iPad if you enable iPad support
Ready-made set in `mobile/appstore-screenshots/` (1320×2868, anonymized). Upload in this order:
`01-chats → 02-conversation → 04-group → 03-meetings → 06-screenshare → 05-schedule`
---
## 6. App Review notes (paste into "Notes")
> Biz Connect requires a BizGaze account to sign in.
>
> Demo account for review:
> Email: << demo@yourdomain >>
> Password: << demo password >>
>
> How to test:
> 1. Open the app and sign in with the demo account above.
> 2. Chat tab: open a conversation to see messaging.
> 3. Start a call from a conversation, or the Meetings tab to start/join a meeting.
> 4. In a meeting, tap "Live transcript" to see on-device speech-to-text.
>
> Notes on permissions:
> • Microphone/Camera — used for voice and video calls.
> • Speech Recognition — used only to generate live meeting transcripts; recognition runs on-device.
> • Screen recording (broadcast) — used only when the user chooses to share their screen in a meeting.
> • VoIP push (PushKit) + CallKit — used to ring incoming calls like a normal phone call.
**Create the demo account now** and confirm it can actually log in and start a call. A dead demo login is the #1 rejection cause for account-gated apps.
---
## 7. Export compliance
The app uses only standard encryption (HTTPS/TLS, WebRTC/DTLS-SRTP) — no proprietary/custom crypto.
- In App Store Connect: **"Does your app use encryption?" → Yes**, then **"only … standard encryption algorithms" → Yes** → qualifies for the exemption (no CCATS/year-end self-classification report needed for standard encryption).
- Optional: set `ITSAppUsesNonExemptEncryption = NO` in Info.plist to skip the question each submission (add to `ios-patch.sh` if you want it permanent — say the word and I'll add it).
---
## 8. Likely review questions / risks (and answers)
- **Account-gated app** → mitigated by the demo account (§6). Also fine per guideline 3.1.1 since it's a business tool, not gating features behind sign-in for a consumer app.
- **User-generated content (chat)** → guideline 1.2 satisfied (shipped 2026-08-19): every message has **Report** (long-press / ⋮ → Report, canned reasons) and **Block user**; blocked users can't message or call you (server-enforced). A **Blocked users** manager lives in the profile menu (unblock anytime), and workspace **admins** get a **Reported messages** review screen (delete content / block / resolve). Reports are org-internal (routed to the workspace's own admins). Reviewer note suggestion: "Report and Block are available on any message via long-press; Blocked users are managed from the profile menu."
- **CallKit + VoIP push** → legitimate; the demo/reviewer flow should show a real incoming call if possible.
- **Background modes** (audio, voip) → justified by calls; the review notes cover it.
---
## 9. Nice-to-haves (not blockers)
- App Store promotional/preview **video** (optional).
- Localized metadata if you target non-English regions.
- A short **"in-app account deletion"** path — Apple requires apps with account creation to offer account deletion (guideline 5.1.1(v)). If BizGaze accounts are created/managed externally (admin-provisioned, not self-signup in the app), note that in review; if users *can* self-register in the app, an in-app "delete my account" (or a clear link to do so) is required.
+29
View File
@@ -0,0 +1,29 @@
# Connecting Codemagic to our self-hosted Gitea (SSH)
We build the iOS app on Codemagic's macOS cloud (no Mac needed). Codemagic must clone the repo from
`code.bizgaze.com`, but that Gitea only exposes **HTTPS (443)** — its **SSH port is not reachable** from
the internet, so Codemagic can't connect yet. This is a one-time infra + Codemagic setup.
## Part 1 — IT: expose Gitea's SSH port (git host `118.95.33.93`)
1. **Find Gitea's SSH port.** In `app.ini``[server]``SSH_PORT` / `SSH_LISTEN_PORT`. Or open a repo
in the Gitea web UI → **clone dropdown → SSH** and read the port in the URL, e.g.
`ssh://git@code.bizgaze.com:2222/Sravan/BizGaze_Remote.git`.
2. **Port-forward a public TCP port → that Gitea SSH port.** Suggested public port: **2222**.
- ⚠️ Nginx Proxy Manager proxies HTTP/HTTPS only. SSH needs a **raw TCP forward** at the firewall/router
(or an NPM **Stream** rule) — not an HTTP proxy host.
3. Confirm reachable, then send the DevOps/AI the **SSH clone URL** (with port) to verify.
Security: Gitea SSH is **key-only** (no password auth), same model as GitHub's public port 22. Access is
further limited to a **read-only deploy key** (below), so a leaked key could only *read* this one repo.
## Part 2 — Codemagic: connect the repo (once the port is open)
1. Codemagic → **Add application → "Other"** (self-hosted / SSH) → paste the SSH clone URL.
2. Copy the **SSH public key** Codemagic shows.
3. Gitea → this repo → **Settings → Deploy Keys → Add Deploy Key** → paste it, **Enable write access = OFF**.
4. Codemagic **Test connection** → it clones and reads [`codemagic.yaml`](../codemagic.yaml).
Then follow [IOS_SETUP.md](IOS_SETUP.md) for the App Store Connect key + first build.
## Auto-build on push (optional, later)
Manual **Start build** works immediately. Automatic builds on push work natively only for
GitHub/GitLab/Bitbucket; for Gitea we'd add a webhook Codemagic can accept — a later nicety, not required.
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "860472998800",
"project_id": "bizgaze-connect",
"storage_bucket": "bizgaze-connect.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:860472998800:android:107cc0fc6936d6898dd115",
"android_client_info": {
"package_name": "com.bizgaze.connect"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyB6gSqIDYr21GKYA4c1e7plUBQMXIcX1Dw"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
+146
View File
@@ -0,0 +1,146 @@
# Biz Connect — iOS App Store setup (Codemagic, no Mac needed)
The iOS app is a Capacitor shell that loads the live Connect web UI (`https://remote.bizgaze.com`).
Building/signing/uploading happens on **Codemagic's macOS cloud** — you never need a Mac.
Bundle id: **`com.bizgaze.connect`** · CI config: [`codemagic.yaml`](../codemagic.yaml) (repo root).
---
## Step 0 — Register the App ID (Identifiers → + → App IDs → App)
On the **Register an App ID** page, only three fields matter — leave everything else default:
- **Platform**: leave as-is (the default `iOS, iPadOS, macOS…` combined App ID is fine).
- **Description**: `Biz Connect` (label only; no `@ & * "`).
- **Bundle ID**: keep **Explicit**`com.bizgaze.connect`.
- **Capabilities**: tick **Push Notifications** only. Leave all others unchecked. (Camera/mic are NOT
here — they're Info.plist runtime strings, added by the build pipeline.)
- Continue → Register. *(The App ID Prefix shown is your Team ID — note it for Step 5's APNs.)*
## Step 1 — App Store Connect: create the app record
1. [appstoreconnect.apple.com](https://appstoreconnect.apple.com) → **Apps → +****New App**.
2. Platform **iOS**, Name **Biz Connect**, primary language, **Bundle ID** = `com.bizgaze.connect`
(the App ID you registered in Step 0 now appears in the dropdown).
3. SKU: anything unique (e.g. `bizconnect-ios`). Create.
## Step 2 — App Store Connect API key (for Codemagic to sign + upload)
1. App Store Connect → **Users and Access → Integrations → App Store Connect API****+**.
2. Access **App Manager**. Generate. Note the **Issuer ID** (top of the page) and the key's **Key ID**,
and **download the `.p8`** (you can only download it once).
## Step 3 — Codemagic: connect + add the key
1. [codemagic.io](https://codemagic.io) → sign in with the git provider → add this repository.
2. **Teams → Integrations → App Store Connect → Connect**, upload the `.p8`, paste the **Issuer ID** and
**Key ID**. **Name it exactly `BizGaze App Store Connect`** (the `codemagic.yaml` references that name).
3. Codemagic detects `codemagic.yaml`. That's all the signing setup — automatic signing creates the
distribution certificate + provisioning profile from this key on the first build.
## Step 4 — Run the build
- Codemagic → the app → **Start new build** → workflow **"Biz Connect iOS → TestFlight"**.
- ~1015 min. On success the build appears in **App Store Connect → TestFlight**.
- Add yourself under **TestFlight → Internal Testing** to install via the TestFlight app on your iPhone.
## Step 5 — Push notifications (APNs) — do this once, then tell me
So the app gets **calls/messages while it's closed**. Two independent pieces must BOTH be in place:
> **A. App ID capability (client side).** The App ID `com.bizgaze.connect` must have **Push Notifications**
> enabled (Step 0 ticks it). The build now injects the `aps-environment` entitlement automatically
> (`ios-patch.sh`), so the app can obtain an APNs token — but if the App ID lacks the Push capability, the
> archive fails code-signing on `aps-environment`. If a build errors on that after you enable the
> capability, delete the app's provisioning profile in App Store Connect so the next Codemagic run
> regenerates one that includes push.
>
> **B. APNs key (server side).** Do the two steps below so the server can actually SEND to that token.
1. developer.apple.com → **Keys → +** → enable **Apple Push Notifications service (APNs)** → download the
**`.p8`**. Note its **Key ID** and your **Team ID** (top-right of the developer portal).
2. **Send me**: the `.p8` contents, the **Key ID**, and the **Team ID**. I set these in the server `.env`
(server-side only, like the LiveKit/Giphy keys):
```
APNS_KEY=<contents of the .p8>
APNS_KEY_ID=<key id>
APNS_TEAM_ID=<team id>
APNS_BUNDLE_ID=com.bizgaze.connect
APNS_PRODUCTION=1
```
The APNs sender is already built into the server — it's a no-op until these are set.
## Step 6 — Public App Store submission (when you're ready to leave TestFlight)
In App Store Connect, fill the listing: **screenshots** (6.7" + 6.1" iPhone), description, keywords,
support URL, and a **Privacy Policy URL** (required). Complete the **App Privacy** questionnaire (we
collect account info + usage for chat/calls). Then submit for review (or flip `submit_to_app_store` in
`codemagic.yaml`).
---
### App Review note (Guideline 4.2 — "Minimum Functionality")
Apple scrutinises apps that look like "just a website". Ours passes because it ships **real native
capabilities** — push notifications, camera/microphone for calls, photo sharing. Make sure push (Step 5)
is live before the **public** submission, and in the reviewer notes mention the **native video/voice
calling + push notifications**. Do **not** advertise "share your screen" as an iOS feature in the store
listing yet — see the follow-up below (you can still *view* a screen someone else shares).
---
## Known iOS limitations & follow-ups (phase 2 — after TestFlight)
### 1. Sharing YOUR iOS screen into a meeting → needs a ReplayKit Broadcast Upload Extension
- **Why:** the app's screen share uses the web `getDisplayMedia` API, which **iOS WebViews and Safari do
not support**. Apple only allows capturing the *device* screen via **ReplayKit**.
- **What works today on iOS:** *viewing* a screen another participant shares (it's just incoming video),
chat, voice/video calls, camera, photo sharing.
- **What's needed to broadcast the iOS screen:** a native **Broadcast Upload Extension** target that
captures frames via ReplayKit and feeds them into the LiveKit/WebRTC session, plus the **App Groups**
capability (to pass data between the app and the extension). This is native Swift work — NOT part of
the Capacitor wrapper — so it's tracked as a separate task, done after the app is on TestFlight.
- **Store impact:** don't claim iOS screen-sharing in the listing until this ships, or a reviewer may
test it and it will fail.
### 2. Native mobile audio routing (speaker / earpiece / Bluetooth) — needs a Capacitor audio plugin
- Mobile **web** can't switch the audio output route (`setSinkId` is unimplemented on iOS/Android), so the
in-meeting speaker/earpiece/Bluetooth control is web-only where it works and hidden where it doesn't.
- True routing on iOS needs a small native plugin driving `AVAudioSession`. Phase-2 native task.
---
## Share Extension ("Biz Connect" in the iOS share sheet) — one-time Apple portal setup
The app now has a **Share Extension** target (`com.bizgaze.connect.share`) so users can share a photo /
video / file FROM the Photos or Files app INTO a Biz Connect conversation. The Codemagic build injects the
target and fetches a profile for it automatically, but two things can ONLY be done once, by hand, in the
Apple Developer portal — CI cannot toggle App capabilities:
1. **Create the App Group** (developer.apple.com → Identifiers → App Groups → +):
identifier **`group.com.bizgaze.connect`**.
2. **Enable the App Groups capability on BOTH App IDs** and assign them to that group:
- `com.bizgaze.connect` (the app)
- `com.bizgaze.connect.share` (the extension — create this App ID if the first build hasn't yet;
`fetch-signing-files --create` will register it, then edit it to add App Groups)
After enabling the capability, the provisioning profiles must be regenerated — the next Codemagic build
does that via `fetch-signing-files`, so just re-run it once the capability is on.
If the App Group isn't set up, the app and the extension can't see each other's files: sharing will appear
to do nothing (the extension stages the file, but the app finds an empty inbox). Everything else — download
to the Files folder, the Photos "Connect" album, Manage storage — works without it.
Also enabled by this change (main app Info.plist, done automatically by `ios-patch.sh`):
- `UIFileSharingEnabled` + `LSSupportsOpeningDocumentsInPlace` → the **Biz Connect** folder in Files.
- `CFBundleURLTypes` scheme **`bizconnect`** → lets the extension bounce back into the app after staging.
## Broadcast Extension (share your iPhone SCREEN in a call) — one-time Apple portal setup
Screen sharing from iOS uses a **Broadcast Upload Extension** (`com.bizgaze.connect.broadcast`) — the same
pattern as the Share Extension. The Codemagic build injects the target, links LiveKit into it, and fetches a
profile automatically, but the **App Group capability can only be toggled by hand** in the Apple portal:
1. Reuse the SAME App Group as the Share Extension: **`group.com.bizgaze.connect`** (no new group needed).
2. **Enable the App Groups capability on the broadcast App ID** and assign it to that group:
- `com.bizgaze.connect.broadcast` (create this App ID if the first build hasn't yet — `fetch-signing-files
--create` registers it, then edit it to add App Groups). The app (`com.bizgaze.connect`) already has the
group from the Share Extension setup above.
After enabling it, re-run the Codemagic build so `fetch-signing-files` regenerates the profile.
Until the App Group is on the broadcast App ID, the **archive fails code-signing** (entitlement mismatch) —
that's the expected first-build failure. The shared App Group is how the extension (ReplayKit capture) hands
screen frames to the app over LiveKit's IPC socket. Receiving OTHERS' shared screens needs none of this — it
already works. `ios-patch.sh` sets `RTCScreenSharingExtension` + `RTCAppGroupIdentifier` in the app Info.plist
so LiveKit finds the extension + group.
+43
View File
@@ -0,0 +1,43 @@
# Biz Connect — Mobile app (Capacitor)
A Capacitor shell that loads the live Connect web UI (`server.url` in
`capacitor.config.json`) and adds native push, camera/mic, and store distribution. See the
overall plan in [../CLIENTS.md](../CLIENTS.md).
> **Android:** follow the step-by-step in **[ANDROID_SETUP.md](ANDROID_SETUP.md)** (project
> generation, icons/splash, permissions, Firebase/FCM, run, and Play Store build).
## Prerequisites
- Node + `npm install` here.
- **Android:** Android Studio + SDK.
- **iOS:** macOS + Xcode (+ an Apple Developer account to run on device / ship).
## Setup
```bash
npm install
npm run assets # generate app icons + splash from resources/
npx cap add android
npx cap add ios # macOS only
npx cap sync
```
## Run / build
```bash
npx cap open android # build & run from Android Studio
npx cap open ios # build & run from Xcode
```
## Server origin
The app loads `server.url` from `capacitor.config.json` (default
`https://remote.bizgaze.com`). For a local device test against a dev server, set it to your
machine's LAN URL (and allow cleartext for plain http).
## Native push (next step)
Native push uses the Capacitor Push Notifications plugin (FCM on Android, APNs on iOS) and a
server endpoint to register device tokens — tracked in [../CLIENTS.md](../CLIENTS.md) Phase B.
This is separate from the existing Web Push (VAPID) the PWA already uses. Needs Google/Apple
credentials to test end-to-end.
## Shipping (gated on accounts)
- **Google Play:** one-time $25; upload an AAB; signing key.
- **App Store:** Apple Developer $99/yr; archive via Xcode; App Store Connect listing.
Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

+35
View File
@@ -0,0 +1,35 @@
{
"appId": "com.bizgaze.connect",
"appName": "Biz Connect",
"webDir": "www",
"server": {
"url": "https://remote.bizgaze.com",
"cleartext": false,
"androidScheme": "https"
},
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
},
"SafeArea": {
"detectViewportFitCoverChanges": true,
"initialViewportFitCover": true,
"offsetForKeyboardInsetBug": true,
"statusBarStyle": "DARK",
"navigationBarStyle": "DARK"
},
"SystemBars": {
"insetsHandling": "disable"
},
"Keyboard": {
"resize": "none"
},
"SplashScreen": {
"launchShowDuration": 900,
"launchAutoHide": true,
"backgroundColor": "#16294F",
"showSpinner": false,
"iosSpinnerStyle": "large"
}
}
}
Binary file not shown.
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.bizgaze.connect</string>
</array>
</dict>
</plist>
+29
View File
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>Biz Connect Screen</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.broadcast-services-upload</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).SampleHandler</string>
<key>RPBroadcastProcessMode</key>
<string>RPBroadcastProcessModeSampleBuffer</string>
</dict>
</dict>
</plist>
+16
View File
@@ -0,0 +1,16 @@
import ReplayKit
import LiveKit
// Principal class of the Broadcast Upload Extension (ReplayKit) that lets the iOS user share their screen.
//
// HOW IT WORKS: when the user starts a system broadcast, iOS launches THIS extension. LiveKit's LKSampleHandler
// does everything on broadcastStarted it opens an IPC socket in the shared App Group (group.com.bizgaze.connect)
// and streams the ReplayKit sample buffers to the MAIN app, whose LiveKit connection publishes them as a
// screen-share track. The extension itself never creates a Room / initialises WebRTC, so it stays well under the
// 50 MB extension memory limit. So this subclass can be empty.
//
// The extension finds the app group + reports state to the app via LiveKit's Darwin-notification/socket
// convention, keyed off this extension's bundle id (com.bizgaze.connect.broadcast) and the default app group
// group.<appBundleId>. Both are also set explicitly on the app side (RTCScreenSharingExtension /
// RTCAppGroupIdentifier in Info.plist) so there's no ambiguity.
final class SampleHandler: LKSampleHandler, @unchecked Sendable {}
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.bizgaze.connect</string>
</array>
<key>aps-environment</key>
<string>production</string>
</dict>
</plist>
+50
View File
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Biz Connect</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
<!-- No storyboard: the extension has no UI of its own (see ShareViewController). -->
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
<key>NSExtensionAttributes</key>
<dict>
<!-- What Biz Connect offers to accept from the share sheet. Without a matching rule here the
app simply does not appear for that content type. -->
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>20</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>10</integer>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>20</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.bizgaze.connect</string>
</array>
</dict>
</plist>
+628
View File
@@ -0,0 +1,628 @@
import UIKit
import AVFoundation
import UniformTypeIdentifiers
// Share Extension puts "Biz Connect" in the iOS share sheet AND does the whole send right here, the way
// Teams/WhatsApp do: pick one or more chats in the sheet, it uploads and sends, no app-open needed.
//
// How it can send without the app: the app writes a bearer token + API base into the App Group each launch
// (via /api/share/token ShareInbox.setAuth). This extension reads that token and calls the same server
// API the native client uses GET /api/messages/conversations, POST /api/messages/upload, POST
// /api/messages.
//
// Manifest lifecycle (why the app doesn't also pop a "Send to" sheet): the App Group manifest represents an
// UNSENT share. We only write it when this extension can't send (no token) or a send fails so a
// successful in-sheet send leaves nothing behind and the app never re-offers it. Cancel/success clear any
// staged files too, so the App Group doesn't accumulate orphans.
struct ShareChat {
let kind: String // "dm" | "group"
let id: String
let name: String
let avatar: String?
let subtitle: String
var key: String { kind + ":" + id }
}
struct ShareItem {
let name: String
let url: URL
let mime: String
let isText: Bool
let text: String
var isImage: Bool { mime.hasPrefix("image/") }
var isVideo: Bool { mime.hasPrefix("video/") }
}
class ShareViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
private let appGroup = "group.com.bizgaze.connect"
private let maxItems = 20
private let brandNavy = UIColor(red: 0x1F/255.0, green: 0x3B/255.0, blue: 0x73/255.0, alpha: 1)
private var token = ""
private var apiBase = "https://remote.bizgaze.com"
private var items: [ShareItem] = []
private var chats: [ShareChat] = []
private var filtered: [ShareChat] = []
private var selected = Set<String>()
private var avatarCache: [String: UIImage] = [:]
private var sending = false
private let table = UITableView(frame: .zero, style: .grouped)
private let search = UISearchBar()
private let statusLabel = UILabel()
private let spinner = UIActivityIndicatorView(style: .medium)
private let previewStack = UIStackView()
private let previewScroll = UIScrollView()
private var sendButton: UIBarButtonItem!
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
readAuth()
buildUI()
ingest()
}
private func readAuth() {
if let d = UserDefaults(suiteName: appGroup) {
token = d.string(forKey: "bzc_token") ?? ""
let b = d.string(forKey: "bzc_base") ?? ""
if !b.isEmpty { apiBase = b }
}
}
// MARK: - UI
private func buildUI() {
view.backgroundColor = .systemGroupedBackground
let nav = UINavigationBar()
nav.translatesAutoresizingMaskIntoConstraints = false
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = brandNavy
appearance.titleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont.systemFont(ofSize: 17, weight: .bold)]
nav.standardAppearance = appearance
nav.scrollEdgeAppearance = appearance
nav.tintColor = .white
let navItem = UINavigationItem(title: "Share to Biz Connect")
// Clean, light SF Symbols instead of a heavy grey X-circle / bold pill (thin xmark + paper-plane).
let symCfg = UIImage.SymbolConfiguration(pointSize: 16, weight: .regular)
navItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "xmark", withConfiguration: symCfg), style: .plain, target: self, action: #selector(cancelTapped))
let sendCfg = UIImage.SymbolConfiguration(pointSize: 18, weight: .semibold)
sendButton = UIBarButtonItem(image: UIImage(systemName: "paperplane.fill", withConfiguration: sendCfg), style: .plain, target: self, action: #selector(sendTapped))
sendButton.isEnabled = false
navItem.rightBarButtonItem = sendButton
nav.setItems([navItem], animated: false)
view.addSubview(nav)
// Preview strip thumbnails of what's being shared (like Teams' attachment row).
previewScroll.translatesAutoresizingMaskIntoConstraints = false
previewScroll.showsHorizontalScrollIndicator = false
previewStack.axis = .horizontal
previewStack.spacing = 8
previewStack.alignment = .center
previewStack.translatesAutoresizingMaskIntoConstraints = false
previewScroll.addSubview(previewStack)
view.addSubview(previewScroll)
search.placeholder = "Search for people or groups"
search.delegate = self
search.searchBarStyle = .minimal
search.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(search)
table.dataSource = self
table.delegate = self
table.rowHeight = 60
table.backgroundColor = .systemGroupedBackground
table.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(table)
statusLabel.font = .systemFont(ofSize: 15)
statusLabel.textColor = .secondaryLabel
statusLabel.textAlignment = .center
statusLabel.numberOfLines = 0
statusLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(statusLabel)
spinner.translatesAutoresizingMaskIntoConstraints = false
spinner.hidesWhenStopped = true
view.addSubview(spinner)
NSLayoutConstraint.activate([
nav.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
nav.leadingAnchor.constraint(equalTo: view.leadingAnchor),
nav.trailingAnchor.constraint(equalTo: view.trailingAnchor),
previewScroll.topAnchor.constraint(equalTo: nav.bottomAnchor, constant: 10),
previewScroll.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
previewScroll.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
previewScroll.heightAnchor.constraint(equalToConstant: 56),
previewStack.topAnchor.constraint(equalTo: previewScroll.topAnchor),
previewStack.bottomAnchor.constraint(equalTo: previewScroll.bottomAnchor),
previewStack.leadingAnchor.constraint(equalTo: previewScroll.leadingAnchor),
previewStack.trailingAnchor.constraint(equalTo: previewScroll.trailingAnchor),
previewStack.heightAnchor.constraint(equalTo: previewScroll.heightAnchor),
search.topAnchor.constraint(equalTo: previewScroll.bottomAnchor, constant: 8),
search.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 6),
search.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -6),
table.topAnchor.constraint(equalTo: search.bottomAnchor, constant: 2),
table.leadingAnchor.constraint(equalTo: view.leadingAnchor),
table.trailingAnchor.constraint(equalTo: view.trailingAnchor),
table.bottomAnchor.constraint(equalTo: view.bottomAnchor),
statusLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
statusLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor),
statusLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 32),
statusLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -32),
spinner.centerXAnchor.constraint(equalTo: view.centerXAnchor),
spinner.topAnchor.constraint(equalTo: statusLabel.bottomAnchor, constant: 14)
])
}
private func setStatus(_ text: String?, busy: Bool = false) {
DispatchQueue.main.async {
self.statusLabel.text = text
self.statusLabel.isHidden = (text == nil)
if busy { self.spinner.startAnimating() } else { self.spinner.stopAnimating() }
}
}
private func updateSendButton() {
// Icon-only paper-plane (like Teams); the radio checks show what's selected. Just enable/disable.
sendButton.isEnabled = !selected.isEmpty && !sending
}
// MARK: - Preview thumbnails
private func buildPreviews() {
for f in items where !f.isText {
let iv = UIImageView()
iv.translatesAutoresizingMaskIntoConstraints = false
iv.contentMode = .scaleAspectFill
iv.clipsToBounds = true
iv.layer.cornerRadius = 8
iv.backgroundColor = .tertiarySystemFill
iv.tintColor = .secondaryLabel
iv.widthAnchor.constraint(equalToConstant: 56).isActive = true
iv.heightAnchor.constraint(equalToConstant: 56).isActive = true
iv.image = UIImage(systemName: f.isVideo ? "video.fill" : "doc.fill")
previewStack.addArrangedSubview(iv)
thumbnail(for: f) { img in if let img = img { DispatchQueue.main.async { iv.image = img; iv.contentMode = .scaleAspectFill } } }
}
if items.contains(where: { $0.isText }) {
let lbl = UILabel()
lbl.text = "🔗 link"
lbl.font = .systemFont(ofSize: 13)
lbl.textColor = .secondaryLabel
previewStack.addArrangedSubview(lbl)
}
}
private func thumbnail(for item: ShareItem, completion: @escaping (UIImage?) -> Void) {
DispatchQueue.global(qos: .userInitiated).async {
if item.isImage, let img = UIImage(contentsOfFile: item.url.path) {
return completion(img)
}
if item.isVideo {
let asset = AVURLAsset(url: item.url)
let gen = AVAssetImageGenerator(asset: asset)
gen.appliesPreferredTrackTransform = true
gen.maximumSize = CGSize(width: 168, height: 168)
if let cg = try? gen.copyCGImage(at: CMTime(seconds: 0.1, preferredTimescale: 600), actualTime: nil) {
return completion(UIImage(cgImage: cg))
}
}
completion(nil)
}
}
// MARK: - Ingest
private func ingest() {
setStatus("Preparing…", busy: true)
let providers = (extensionContext?.inputItems as? [NSExtensionItem] ?? [])
.flatMap { $0.attachments ?? [] }
.prefix(maxItems)
guard !providers.isEmpty else { return finishFail("Nothing to share.") }
var collected: [ShareItem] = []
let lock = NSLock()
let group = DispatchGroup()
for provider in providers {
group.enter()
load(provider) { item in
if let item = item { lock.lock(); collected.append(item); lock.unlock() }
group.leave()
}
}
group.notify(queue: .main) { [weak self] in
guard let self = self else { return }
self.items = collected
if collected.isEmpty { return self.finishFail("Couldnt read the shared file.") }
self.buildPreviews()
self.loadChats()
}
}
private func load(_ provider: NSItemProvider, completion: @escaping (ShareItem?) -> Void) {
let fileTypes: [UTType] = [.movie, .image, .audio, .pdf, .item]
if let type = fileTypes.first(where: { provider.hasItemConformingToTypeIdentifier($0.identifier) }) {
provider.loadFileRepresentation(forTypeIdentifier: type.identifier) { [weak self] url, _ in
guard let self = self, let url = url else { return completion(nil) }
completion(self.stage(url))
}
return
}
if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
provider.loadItem(forTypeIdentifier: UTType.url.identifier) { item, _ in
if let u = item as? URL { completion(ShareItem(name: "", url: URL(fileURLWithPath: "/"), mime: "", isText: true, text: u.absoluteString)) }
else { completion(nil) }
}
return
}
if provider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) {
provider.loadItem(forTypeIdentifier: UTType.plainText.identifier) { item, _ in
if let s = item as? String { completion(ShareItem(name: "", url: URL(fileURLWithPath: "/"), mime: "", isText: true, text: s)) }
else { completion(nil) }
}
return
}
completion(nil)
}
private func stage(_ src: URL) -> ShareItem? {
guard let dir = sharedDir() else { return nil }
let name = src.lastPathComponent.isEmpty ? "shared-file" : src.lastPathComponent
let dest = uniqueURL(in: dir, preferred: name)
do { try FileManager.default.copyItem(at: src, to: dest) } catch { return nil }
return ShareItem(name: dest.lastPathComponent, url: dest, mime: Self.mimeType(for: dest), isText: false, text: "")
}
// MARK: - Chat list
private func loadChats() {
guard !token.isEmpty else {
writeManifest(items) // no token let the app pick these up
setStatus("Open Biz Connect and sign in first, then share again.\n\nYour file is saved and will be waiting in the app.")
return
}
setStatus("Loading your chats…", busy: true)
api("GET", "/api/messages/conversations") { [weak self] data, _ in
guard let self = self else { return }
guard let data = data,
let arr = (try? JSONSerialization.jsonObject(with: data)) as? [[String: Any]] else {
self.writeManifest(self.items)
self.setStatus("Couldnt load your chats.\n\nOpen Biz Connect once, then try sharing again.")
return
}
let parsed: [ShareChat] = arr.compactMap { row in
guard let kind = row["kind"] as? String, let id = idString(row["id"]), let name = row["name"] as? String else { return nil }
let sub = kind == "group" ? "Group" + ((row["members"] as? Int).map { " · \($0) members" } ?? "") : "Direct message"
return ShareChat(kind: kind, id: id, name: name, avatar: row["avatar"] as? String, subtitle: sub)
}
DispatchQueue.main.async {
self.chats = parsed
self.filtered = parsed
self.setStatus(parsed.isEmpty ? "No chats yet." : nil)
self.table.reloadData()
}
}
}
// MARK: - Table
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { filtered.count }
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
filtered.isEmpty ? nil : "Recent chats"
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "chat") ?? UITableViewCell(style: .subtitle, reuseIdentifier: "chat")
let c = filtered[indexPath.row]
cell.textLabel?.text = c.name
cell.textLabel?.font = .systemFont(ofSize: 16)
cell.detailTextLabel?.text = c.subtitle
cell.detailTextLabel?.textColor = .secondaryLabel
// Radio selector on the right (empty circle filled navy check), always visible like Teams.
let selImg = selected.contains(c.key)
? UIImage(systemName: "checkmark.circle.fill")?.withTintColor(brandNavy, renderingMode: .alwaysOriginal)
: UIImage(systemName: "circle")?.withTintColor(.systemGray3, renderingMode: .alwaysOriginal)
let selView = UIImageView(image: selImg)
selView.frame = CGRect(x: 0, y: 0, width: 26, height: 26)
cell.accessoryView = selView
// Round avatar
cell.imageView?.layer.cornerRadius = 20
cell.imageView?.layer.masksToBounds = true
if let img = avatarCache[c.key] {
cell.imageView?.image = img
} else {
cell.imageView?.image = initialsImage(c.name)
loadAvatar(for: c)
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard !sending else { return }
let key = filtered[indexPath.row].key
if selected.contains(key) { selected.remove(key) } else { selected.insert(key) }
tableView.reloadRows(at: [indexPath], with: .none)
updateSendButton()
}
// MARK: - Avatars
private func loadAvatar(for chat: ShareChat) {
guard let av = chat.avatar, !av.isEmpty else { return }
if av.hasPrefix("data:") {
if let comma = av.firstIndex(of: ","),
let d = Data(base64Encoded: String(av[av.index(after: comma)...])),
let img = Self.circularImage(from: d) {
cache(img, for: chat)
}
return
}
let urlStr = av.hasPrefix("/") ? (apiBase + av) : av
guard let url = URL(string: urlStr) else { return }
var req = URLRequest(url: url)
if !token.isEmpty { req.setValue("Bearer " + token, forHTTPHeaderField: "Authorization") }
URLSession.shared.dataTask(with: req) { [weak self] d, _, _ in
guard let self = self, let d = d, let img = Self.circularImage(from: d) else { return }
self.cache(img, for: chat)
}.resume()
}
private func cache(_ img: UIImage, for chat: ShareChat) {
DispatchQueue.main.async {
self.avatarCache[chat.key] = img
if let idx = self.filtered.firstIndex(where: { $0.key == chat.key }) {
self.table.reloadRows(at: [IndexPath(row: idx, section: 0)], with: .none)
}
}
}
private func initialsImage(_ name: String, size: CGFloat = 40) -> UIImage {
let parts = name.split(separator: " ")
let initials = parts.prefix(2).compactMap { $0.first }.map { String($0) }.joined().uppercased()
let bg = Self.color(for: name)
let renderer = UIGraphicsImageRenderer(size: CGSize(width: size, height: size))
return renderer.image { _ in
bg.setFill()
UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: size, height: size)).fill()
let para = NSMutableParagraphStyle(); para.alignment = .center
let attrs: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: size * 0.4, weight: .semibold),
.foregroundColor: UIColor.white,
.paragraphStyle: para
]
let s = (initials.isEmpty ? "?" : initials) as NSString
let ts = s.size(withAttributes: attrs)
s.draw(in: CGRect(x: 0, y: (size - ts.height) / 2, width: size, height: ts.height), withAttributes: attrs)
}
}
private static func circularImage(from data: Data, size: CGFloat = 40) -> UIImage? {
guard let img = UIImage(data: data) else { return nil }
let renderer = UIGraphicsImageRenderer(size: CGSize(width: size, height: size))
return renderer.image { _ in
UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: size, height: size)).addClip()
let scale = max(size / img.size.width, size / img.size.height)
let w = img.size.width * scale, h = img.size.height * scale
img.draw(in: CGRect(x: (size - w) / 2, y: (size - h) / 2, width: w, height: h))
}
}
private static let palette: [UIColor] = [
UIColor(red: 0.20, green: 0.45, blue: 0.85, alpha: 1),
UIColor(red: 0.85, green: 0.35, blue: 0.45, alpha: 1),
UIColor(red: 0.30, green: 0.65, blue: 0.45, alpha: 1),
UIColor(red: 0.75, green: 0.55, blue: 0.20, alpha: 1),
UIColor(red: 0.50, green: 0.40, blue: 0.75, alpha: 1),
UIColor(red: 0.25, green: 0.60, blue: 0.70, alpha: 1)
]
private static func color(for name: String) -> UIColor {
var h: UInt32 = 0
for c in name.unicodeScalars { h = h &* 31 &+ c.value }
return palette[Int(h % UInt32(palette.count))]
}
// MARK: - Send
@objc private func sendTapped() {
guard !sending else { return }
let targets = chats.filter { selected.contains($0.key) }
guard !targets.isEmpty else { return }
sending = true
updateSendButton()
search.isHidden = true
table.isHidden = true
previewScroll.isHidden = true
let label = targets.count == 1 ? targets[0].name : "\(targets.count) chats"
setStatus("Sending to \(label)", busy: true)
DispatchQueue.global(qos: .userInitiated).async {
let files = self.items.filter { !$0.isText }
let texts = self.items.filter { $0.isText }.map { $0.text }
var ok = true
var attIds: [String] = []
for (i, f) in files.enumerated() {
if files.count > 1 { self.setStatus("Uploading \(i + 1) of \(files.count)", busy: true) }
guard let data = try? Data(contentsOf: f.url), let id = self.uploadSync(name: f.name, mime: f.mime, data: data) else { ok = false; break }
attIds.append(id)
}
if ok {
sendLoop: for chat in targets {
for id in attIds {
if !self.sendMessageSync(self.messageBody(chat: chat, attachmentId: id, text: nil)) { ok = false; break sendLoop }
}
if !texts.isEmpty {
if !self.sendMessageSync(self.messageBody(chat: chat, attachmentId: nil, text: texts.joined(separator: "\n"))) { ok = false; break sendLoop }
}
}
}
DispatchQueue.main.async {
if ok {
self.clearStaged() // sent leave nothing for the app to re-offer
self.setStatus("✓ Sent to \(label)")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) { self.finish() }
} else {
self.writeManifest(self.items) // failed let the app pick these up
self.sending = false
self.search.isHidden = false
self.table.isHidden = false
self.previewScroll.isHidden = false
self.updateSendButton()
self.setStatus("Couldnt send. Your file is saved — open Biz Connect to send it.")
DispatchQueue.main.asyncAfter(deadline: .now() + 2.4) { self.finish() }
}
}
}
}
private func messageBody(chat: ShareChat, attachmentId: String?, text: String?) -> [String: Any] {
var b: [String: Any] = [:]
if chat.kind == "group" { b["group"] = chat.id } else { b["to"] = chat.id }
if let a = attachmentId { b["attachmentId"] = a }
if let t = text { b["body"] = t }
return b
}
// MARK: - Networking
private func uploadSync(name: String, mime: String, data: Data) -> String? {
guard let url = URL(string: apiBase + "/api/messages/upload") else { return nil }
var req = URLRequest(url: url)
req.httpMethod = "POST"
req.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
req.setValue(mime.isEmpty ? "application/octet-stream" : mime, forHTTPHeaderField: "Content-Type")
req.setValue(name.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? name, forHTTPHeaderField: "X-Filename")
req.httpBody = data
req.timeoutInterval = 300
var out: String? = nil
let sem = DispatchSemaphore(value: 0)
URLSession.shared.dataTask(with: req) { d, resp, _ in
defer { sem.signal() }
guard let d = d, let http = resp as? HTTPURLResponse, (200..<300).contains(http.statusCode),
let obj = (try? JSONSerialization.jsonObject(with: d)) as? [String: Any] else { return }
out = idString(obj["id"])
}.resume()
sem.wait()
return out
}
private func sendMessageSync(_ body: [String: Any]) -> Bool {
guard let url = URL(string: apiBase + "/api/messages"),
let json = try? JSONSerialization.data(withJSONObject: body) else { return false }
var req = URLRequest(url: url)
req.httpMethod = "POST"
req.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.httpBody = json
req.timeoutInterval = 60
var ok = false
let sem = DispatchSemaphore(value: 0)
URLSession.shared.dataTask(with: req) { _, resp, _ in
if let http = resp as? HTTPURLResponse, (200..<300).contains(http.statusCode) { ok = true }
sem.signal()
}.resume()
sem.wait()
return ok
}
private func api(_ method: String, _ path: String, completion: @escaping (Data?, HTTPURLResponse?) -> Void) {
guard let url = URL(string: apiBase + path) else { return completion(nil, nil) }
var req = URLRequest(url: url)
req.httpMethod = method
req.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
req.timeoutInterval = 30
URLSession.shared.dataTask(with: req) { d, resp, _ in completion(d, resp as? HTTPURLResponse) }.resume()
}
// MARK: - App Group storage
private func sharedDir() -> URL? {
guard let base = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup) else { return nil }
let dir = base.appendingPathComponent("Shared", isDirectory: true)
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
return dir
}
private func uniqueURL(in dir: URL, preferred: String) -> URL {
let ext = (preferred as NSString).pathExtension
let stem = (preferred as NSString).deletingPathExtension
var candidate = dir.appendingPathComponent(preferred)
var i = 2
while FileManager.default.fileExists(atPath: candidate.path) {
let next = ext.isEmpty ? "\(stem) (\(i))" : "\(stem) (\(i)).\(ext)"
candidate = dir.appendingPathComponent(next)
i += 1
}
return candidate
}
// Written only when this extension can't send it marks an UNSENT share for the app to pick up.
private func writeManifest(_ its: [ShareItem]) {
guard let dir = sharedDir() else { return }
let records: [[String: Any]] = its.map { it in
it.isText ? ["kind": "text", "text": it.text]
: ["kind": "file", "name": it.name, "path": it.url.path, "mime": it.mime]
}
if let data = try? JSONSerialization.data(withJSONObject: records) {
try? data.write(to: dir.appendingPathComponent("manifest.json"), options: .atomic)
}
}
// Remove the staged files + any manifest, so the App Group doesn't accumulate and the app has nothing
// to re-offer after a successful send or a cancel.
private func clearStaged() {
guard let dir = sharedDir() else { return }
let fm = FileManager.default
if let entries = try? fm.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil) {
for e in entries { try? fm.removeItem(at: e) }
}
}
private static func mimeType(for url: URL) -> String {
if let t = UTType(filenameExtension: url.pathExtension.lowercased()), let m = t.preferredMIMEType { return m }
return "application/octet-stream"
}
// MARK: - Finish
@objc private func cancelTapped() {
clearStaged() // nothing sent don't leave orphans or let the app re-offer
extensionContext?.cancelRequest(withError: NSError(domain: "share", code: 0))
}
private func finish() {
extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
}
private func finishFail(_ msg: String) {
setStatus(msg)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.8) { self.finish() }
}
}
private func idString(_ v: Any?) -> String? {
if let s = v as? String { return s }
if let n = v as? NSNumber { return n.stringValue }
return nil
}
extension ShareViewController: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
let q = searchText.trimmingCharacters(in: .whitespaces).lowercased()
filtered = q.isEmpty ? chats : chats.filter { $0.name.lowercased().contains(q) }
table.reloadData()
}
}
+35
View File
@@ -0,0 +1,35 @@
{
"name": "biz-connect-mobile",
"version": "0.1.0",
"description": "Biz Connect mobile app — Capacitor shell loading the Connect web UI",
"scripts": {
"sync": "cap sync",
"assets": "capacitor-assets generate --android",
"assets:all": "capacitor-assets generate",
"android": "cap open android",
"ios": "cap open ios"
},
"dependencies": {
"audio-route": "file:plugins/audio-route",
"file-opener": "file:plugins/file-opener",
"media-library": "file:plugins/media-library",
"native-call": "file:plugins/native-call",
"share-inbox": "file:plugins/share-inbox",
"@capacitor-community/safe-area": "^8.0.0",
"@capacitor/android": "^8.0.0",
"@capacitor/app": "^8.0.0",
"@capacitor/camera": "^8.0.0",
"@capacitor/core": "^8.0.0",
"@capacitor/filesystem": "^8.0.0",
"@capacitor/ios": "^8.0.0",
"@capacitor/keyboard": "^8.0.0",
"@capacitor/share": "^8.0.0",
"@capacitor/push-notifications": "^8.0.0",
"@capacitor/splash-screen": "^8.0.0",
"@capacitor/status-bar": "^8.0.0"
},
"devDependencies": {
"@capacitor/assets": "^3.0.5",
"@capacitor/cli": "^8.0.0"
}
}
@@ -0,0 +1,21 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
Pod::Spec.new do |s|
# NOTE: the pod name MUST be 'AudioRoute' (PascalCase of the npm package name 'audio-route').
# Capacitor's `cap sync` writes `pod 'AudioRoute', :path => '../../plugins/audio-route'` into the
# generated Podfile, and CocoaPods then looks for a file literally named AudioRoute.podspec whose
# s.name is 'AudioRoute'. Any other name → "No podspec found for `AudioRoute`" and pod install fails.
s.name = 'AudioRoute'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = 'https://bizgaze.com'
s.author = 'BizGaze'
s.source = { :git => 'https://bizgaze.com/audio-route.git', :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m}'
s.ios.deployment_target = '15.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
end
+22
View File
@@ -0,0 +1,22 @@
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "AudioRoute",
platforms: [.iOS(.v15)],
products: [
.library(name: "AudioRoute", targets: ["AudioRoutePlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
],
targets: [
.target(
name: "AudioRoutePlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
],
path: "ios/Sources/AudioRoutePlugin")
]
)
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
// Native-only plugin — the web app calls window.Capacitor.Plugins.AudioRoute directly (it loads the UI from
// a remote URL, so nothing here is bundled). This stub only exists so the npm package resolves.
export {};
+2
View File
@@ -0,0 +1,2 @@
'use strict';
// Native-only plugin stub (see dist/esm/index.js).
@@ -0,0 +1,89 @@
import Foundation
import Capacitor
import AVFoundation
// Call-audio routing for the iOS app. Registered by cap sync as a real Capacitor plugin package, so it shows
// up as window.Capacitor.Plugins.AudioRoute (an app-embedded class gets stripped in release builds).
//
// KNOWN CEILING (WKWebView): the app does NOT own the AVAudioSession WebKit's media process does, and it
// re-asserts its own category (Bluetooth allowed) on every change. So the earpiece can't be forced, and the
// built-in speaker can't be held over an actively-connected Bluetooth device (a re-force just oscillates with
// WebKit proven on device). This plugin therefore does a SINGLE override per user tap and does NOT fight
// route changes; it only reports the active output so the web UI can show the correct icon.
// * setSpeaker(true) -> try to force the loudspeaker (drops Bluetooth options + overrideOutputAudioPort(.speaker))
// * setSpeaker(false) -> "Device": allow BT/wired and use the default port (routes to a connected headset)
// * getRoute() + 'routeChange' event -> the active output ('speaker'|'bluetooth'|'wired'|'receiver'|'airplay')
@objc(AudioRoutePlugin)
public class AudioRoutePlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "AudioRoutePlugin"
public let jsName = "AudioRoute"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "setSpeaker", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "getRoute", returnType: CAPPluginReturnPromise)
]
private static let nativeTag = "1.1.2-stable"
private var pending: DispatchWorkItem?
override public func load() {
try? configureDevice() // start in "device" mode (BT/wired allowed); the web forces speaker per call
NotificationCenter.default.addObserver(self, selector: #selector(routeChanged),
name: AVAudioSession.routeChangeNotification, object: nil)
}
deinit { NotificationCenter.default.removeObserver(self) }
private func configureSpeaker() throws {
let s = AVAudioSession.sharedInstance()
try s.setCategory(.playAndRecord, mode: .voiceChat, options: [.defaultToSpeaker])
try s.setActive(true)
try s.overrideOutputAudioPort(.speaker)
}
private func configureDevice() throws {
let s = AVAudioSession.sharedInstance()
try s.setCategory(.playAndRecord, mode: .voiceChat, options: [.allowBluetooth, .allowBluetoothA2DP])
try s.setActive(true)
try s.overrideOutputAudioPort(.none)
}
private func currentOutput() -> String {
for o in AVAudioSession.sharedInstance().currentRoute.outputs {
switch o.portType {
case .builtInSpeaker: return "speaker"
case .builtInReceiver: return "receiver"
case .bluetoothA2DP, .bluetoothHFP, .bluetoothLE, .carAudio: return "bluetooth"
case .headphones, .headsetMic, .usbAudio: return "wired"
case .airPlay: return "airplay"
default: continue
}
}
return "unknown"
}
// Report the active output to the web UI. Deliberately does NOT re-force any route fighting WebKit's
// re-assertion just oscillates the audio (see ceiling note above).
@objc private func routeChanged() {
pending?.cancel()
let work = DispatchWorkItem { [weak self] in
guard let self = self else { return }
self.notifyListeners("routeChange", data: ["output": self.currentOutput(), "native": AudioRoutePlugin.nativeTag])
}
pending = work
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: work)
}
@objc func setSpeaker(_ call: CAPPluginCall) {
let on = call.getBool("on") ?? true
do {
if on { try configureSpeaker() } else { try configureDevice() }
call.resolve(["output": currentOutput(), "native": AudioRoutePlugin.nativeTag])
} catch {
call.reject(error.localizedDescription)
}
}
@objc func getRoute(_ call: CAPPluginCall) {
call.resolve(["output": currentOutput(), "native": AudioRoutePlugin.nativeTag])
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"name": "audio-route",
"version": "1.1.2",
"description": "iOS earpiece/speaker audio route toggle for Biz Connect",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"author": "BizGaze",
"license": "MIT",
"files": [
"dist/",
"ios/",
"AudioRoute.podspec",
"Package.swift"
],
"capacitor": {
"ios": {
"src": "ios"
}
},
"devDependencies": {
"@capacitor/core": "^8.0.0"
},
"peerDependencies": {
"@capacitor/core": "^8.0.0"
}
}
@@ -0,0 +1,22 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
Pod::Spec.new do |s|
# NOTE: the pod name MUST be 'FileOpener' (PascalCase of the npm package name 'file-opener').
# `cap sync` writes `pod 'FileOpener', :path => '../../plugins/file-opener'` into the generated Podfile,
# and CocoaPods then looks for a file literally named FileOpener.podspec whose s.name is 'FileOpener'.
# Any other name → "No podspec found for `FileOpener`" and pod install fails. (Same trap that broke the
# AudioRoute build — see mobile/plugins/audio-route/AudioRoute.podspec.)
s.name = 'FileOpener'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = 'https://bizgaze.com'
s.author = 'BizGaze'
s.source = { :git => 'https://bizgaze.com/file-opener.git', :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m}'
s.ios.deployment_target = '15.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
end
+22
View File
@@ -0,0 +1,22 @@
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "FileOpener",
platforms: [.iOS(.v15)],
products: [
.library(name: "FileOpener", targets: ["FileOpenerPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
],
targets: [
.target(
name: "FileOpenerPlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
],
path: "ios/Sources/FileOpenerPlugin")
]
)
@@ -0,0 +1,71 @@
import Foundation
import Capacitor
import QuickLook
// Previews an already-downloaded file with iOS Quick Look the native "look at this file" surface: swipe,
// pinch-zoom, print, and its own share button. Registered by cap sync as window.Capacitor.Plugins.FileOpener.
//
// WHY A PLUGIN: the app loads its UI from a REMOTE origin (remote.bizgaze.com), so it cannot open a local
// file:// URL in the WebView (cross-origin / capacitor local-serving isn't on this origin). @capacitor/share
// only offers the share SHEET ("open in another app"), not a preview. Only QLPreviewController, presented
// from native code, gives a real in-app preview. Quick Look picks the renderer from the file extension, which
// is why the web layer now saves downloads with a correct extension (see bzEnsureExt in home.html).
@objc(FileOpenerPlugin)
public class FileOpenerPlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "FileOpenerPlugin"
public let jsName = "FileOpener"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "preview", returnType: CAPPluginReturnPromise)
]
// QLPreviewController holds its dataSource weakly, so we must keep a strong reference alive for the
// lifetime of the presented preview otherwise it deallocates and the preview shows blank.
private var dataSource: QLDataSource?
@objc func preview(_ call: CAPPluginCall) {
guard let raw = call.getString("path"), !raw.isEmpty else {
call.reject("path is required"); return
}
let url = FileOpenerPlugin.fileURL(from: raw)
guard FileManager.default.fileExists(atPath: url.path) else {
call.reject("file not found: \(url.path)"); return
}
DispatchQueue.main.async {
let ds = QLDataSource(url: url)
self.dataSource = ds
let controller = QLPreviewController()
controller.dataSource = ds
controller.modalPresentationStyle = .fullScreen
guard let base = self.bridge?.viewController else {
call.reject("no view controller to present from"); return
}
// Present on top of whatever is already showing (a modal, another sheet) so it never fails silently.
var presenter = base
while let top = presenter.presentedViewController { presenter = top }
presenter.present(controller, animated: true) {
call.resolve(["ok": true])
}
}
}
// Accepts either a file:// URI (what Filesystem.writeFile returns) or a bare absolute path.
private static func fileURL(from raw: String) -> URL {
if raw.hasPrefix("file://") {
if let u = URL(string: raw) { return u }
// Un-encoded spaces make URL(string:) fail percent-encode and retry before giving up.
let encoded = raw.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? raw
if let u = URL(string: encoded) { return u }
}
return URL(fileURLWithPath: raw)
}
}
// Single-item data source. NSURL already conforms to QLPreviewItem.
final class QLDataSource: NSObject, QLPreviewControllerDataSource {
private let url: URL
init(url: URL) { self.url = url }
func numberOfPreviewItems(in controller: QLPreviewController) -> Int { 1 }
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
return url as NSURL
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"name": "file-opener",
"version": "1.0.0",
"description": "Preview a downloaded file with native iOS Quick Look for Biz Connect",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"author": "BizGaze",
"license": "MIT",
"files": [
"dist/",
"ios/",
"FileOpener.podspec",
"Package.swift"
],
"capacitor": {
"ios": {
"src": "ios"
}
},
"devDependencies": {
"@capacitor/core": "^8.0.0"
},
"peerDependencies": {
"@capacitor/core": "^8.0.0"
}
}
@@ -0,0 +1,22 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
Pod::Spec.new do |s|
# NOTE: the pod name MUST be 'MediaLibrary' (PascalCase of the npm package name 'media-library').
# `cap sync` writes `pod 'MediaLibrary', :path => '../../plugins/media-library'` into the generated
# Podfile, and CocoaPods then looks for a file literally named MediaLibrary.podspec whose s.name is
# 'MediaLibrary'. Any other name → "No podspec found for `MediaLibrary`" and pod install fails.
# (Same trap that broke the AudioRoute build — see mobile/plugins/audio-route/AudioRoute.podspec.)
s.name = 'MediaLibrary'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = 'https://bizgaze.com'
s.author = 'BizGaze'
s.source = { :git => 'https://bizgaze.com/media-library.git', :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m}'
s.ios.deployment_target = '15.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
end
@@ -0,0 +1,22 @@
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "MediaLibrary",
platforms: [.iOS(.v15)],
products: [
.library(name: "MediaLibrary", targets: ["MediaLibraryPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
],
targets: [
.target(
name: "MediaLibraryPlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
],
path: "ios/Sources/MediaLibraryPlugin")
]
)
@@ -0,0 +1,126 @@
import Foundation
import Capacitor
import Photos
// Copies a downloaded photo/video into the user's Photos library, inside a named album ("Connect"), the
// way WhatsApp puts saved media in a WhatsApp album. Registered by cap sync as a real Capacitor plugin
// package, so it appears as window.Capacitor.Plugins.MediaLibrary (an app-embedded class would be
// stripped in release builds).
//
// WHY A PLUGIN AT ALL: the app already saves downloads into its own Documents folder (visible in Files),
// but Files is not where people look for photos and videos the Photos app is, and only PhotoKit can put
// something there. @capacitor/filesystem cannot: an app's sandbox and the photo library are separate stores.
//
// PERMISSION NOTE: .addOnly is enough to add an asset, but NOT to look up or create an ALBUM that needs
// .readWrite. So we request .readWrite, and both NSPhotoLibraryUsageDescription and
// NSPhotoLibraryAddUsageDescription must be present (ios-patch.sh sets them).
@objc(MediaLibraryPlugin)
public class MediaLibraryPlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "MediaLibraryPlugin"
public let jsName = "MediaLibrary"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "saveToAlbum", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "checkPermission", returnType: CAPPluginReturnPromise)
]
// MARK: - API
@objc func checkPermission(_ call: CAPPluginCall) {
call.resolve(["status": MediaLibraryPlugin.label(PHPhotoLibrary.authorizationStatus(for: .readWrite))])
}
@objc func saveToAlbum(_ call: CAPPluginCall) {
guard let raw = call.getString("path"), !raw.isEmpty else {
call.reject("path is required"); return
}
let album = (call.getString("album") ?? "Connect").trimmingCharacters(in: .whitespacesAndNewlines)
let url = MediaLibraryPlugin.fileURL(from: raw)
guard FileManager.default.fileExists(atPath: url.path) else {
call.reject("file not found: \(url.path)"); return
}
// Trust an explicit kind if the web layer passed one (it knows the MIME); otherwise fall back to
// the file extension.
let isVideo: Bool = {
if let kind = call.getString("kind") { return kind == "video" }
return MediaLibraryPlugin.videoExtensions.contains(url.pathExtension.lowercased())
}()
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
guard status == .authorized || status == .limited else {
call.reject("permission denied", MediaLibraryPlugin.label(status)); return
}
self.album(named: album) { collection in
PHPhotoLibrary.shared().performChanges({
// addResource(with:fileURL:) works uniformly for photo and video and, unlike the
// creationRequestForAssetFrom* helpers, is non-optional no silent no-op path.
let request = PHAssetCreationRequest.forAsset()
let options = PHAssetResourceCreationOptions()
options.shouldMoveFile = false // keep our own copy in the app folder
options.originalFilename = url.lastPathComponent
request.addResource(with: isVideo ? .video : .photo, fileURL: url, options: options)
// If the album couldn't be resolved (e.g. "limited" access), still save the asset
// landing in the camera roll beats failing outright.
if let collection = collection,
let placeholder = request.placeholderForCreatedAsset,
let add = PHAssetCollectionChangeRequest(for: collection) {
add.addAssets([placeholder] as NSArray)
}
}) { ok, err in
if ok {
call.resolve(["saved": true, "album": album, "inAlbum": collection != nil])
} else {
call.reject(err?.localizedDescription ?? "could not save to Photos")
}
}
}
}
}
// MARK: - Helpers
private static let videoExtensions: Set<String> = ["mp4", "mov", "m4v", "3gp", "avi", "mkv", "webm"]
private static func label(_ s: PHAuthorizationStatus) -> String {
switch s {
case .authorized: return "granted"
case .limited: return "limited"
case .denied: return "denied"
case .restricted: return "restricted"
case .notDetermined: return "prompt"
@unknown default: return "unknown"
}
}
// Accepts either a file:// URI (what Filesystem.writeFile returns) or a bare absolute path.
private static func fileURL(from raw: String) -> URL {
if raw.hasPrefix("file://") {
if let u = URL(string: raw) { return u }
// Un-encoded spaces make URL(string:) fail percent-encode and retry before giving up.
let encoded = raw.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? raw
if let u = URL(string: encoded) { return u }
}
return URL(fileURLWithPath: raw)
}
/// Find the album by title, creating it the first time. Returns nil if it can't be resolved.
private func album(named name: String, completion: @escaping (PHAssetCollection?) -> Void) {
if let existing = MediaLibraryPlugin.findAlbum(name) { completion(existing); return }
var placeholder: PHObjectPlaceholder?
PHPhotoLibrary.shared().performChanges({
let req = PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: name)
placeholder = req.placeholderForCreatedAssetCollection
}) { ok, _ in
guard ok, let id = placeholder?.localIdentifier else {
// A racing create (two downloads at once) means it exists now look again before failing.
completion(MediaLibraryPlugin.findAlbum(name)); return
}
completion(PHAssetCollection.fetchAssetCollections(withLocalIdentifiers: [id], options: nil).firstObject)
}
}
private static func findAlbum(_ name: String) -> PHAssetCollection? {
let opts = PHFetchOptions()
opts.predicate = NSPredicate(format: "localizedTitle = %@", name)
return PHAssetCollection.fetchAssetCollections(with: .album, subtype: .albumRegular, options: opts).firstObject
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"name": "media-library",
"version": "1.0.0",
"description": "Save downloaded photos & videos into a named Photos album for Biz Connect",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"author": "BizGaze",
"license": "MIT",
"files": [
"dist/",
"ios/",
"MediaLibrary.podspec",
"Package.swift"
],
"capacitor": {
"ios": {
"src": "ios"
}
},
"devDependencies": {
"@capacitor/core": "^8.0.0"
},
"peerDependencies": {
"@capacitor/core": "^8.0.0"
}
}
@@ -0,0 +1,31 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
Pod::Spec.new do |s|
# NOTE: the pod name MUST be 'NativeCall' (PascalCase of the npm package name 'native-call').
# Capacitor's `cap sync` writes `pod 'NativeCall', :path => '../../plugins/native-call'` into the
# generated Podfile, and CocoaPods then looks for a file literally named NativeCall.podspec whose
# s.name is 'NativeCall'. Any other name → "No podspec found for `NativeCall`" and pod install fails.
s.name = 'NativeCall'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = 'https://bizgaze.com'
s.author = 'BizGaze'
s.source = { :git => 'https://bizgaze.com/native-call.git', :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m}'
s.ios.deployment_target = '15.0'
s.dependency 'Capacitor'
# LiveKit iOS SDK — carries the call media NATIVELY so audio survives backgrounding AND coordinates with
# CallKit's audio session (auto-config OFF via AudioManager.shared.audioSession.isAutomaticConfigurationEnabled
# + setEngineAvailability in CXProvider didActivate/didDeactivate), which the WebView's WebRTC could not do.
# NOTE ON VERSION: this constraint stays '~> 2.0', but the actual version is pinned to 2.15.3 by a git-tag
# `pod 'LiveKitClient', :git => ...` line that ios-patch.sh injects into the generated Podfile — because the
# CallKit audio API needs 2.1+, which LiveKit publishes SPM-only (the CocoaPods TRUNK caps at 2.0.18, but the
# repo still ships a valid podspec at tag 2.15.3, and its deps are on trunk). 2.15.3 satisfies '~> 2.0'.
s.dependency 'LiveKitClient', '~> 2.0'
# CallKit + PushKit + AVFoundation are system frameworks (no external pod).
s.frameworks = 'CallKit', 'PushKit', 'AVFoundation'
s.swift_version = '5.1'
end
+27
View File
@@ -0,0 +1,27 @@
// swift-tools-version: 5.9
import PackageDescription
// SPM manifest for the native-call Capacitor plugin (Capacitor 8 uses SPM). LiveKit is declared here as a
// REAL SPM dependency LiveKit 2.1+ is SPM-native, so this replaces the CocoaPods git-tag pin hack entirely.
// SPM resolves LiveKit + its LiveKitWebRTC / LiveKitUniFFI / SwiftProtobuf sub-packages directly.
let package = Package(
name: "NativeCall",
platforms: [.iOS(.v15)],
products: [
.library(name: "NativeCall", targets: ["NativeCallPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
.package(url: "https://github.com/livekit/client-sdk-swift.git", exact: "2.15.3")
],
targets: [
.target(
name: "NativeCallPlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm"),
.product(name: "LiveKit", package: "client-sdk-swift")
],
path: "ios/Sources/NativeCallPlugin")
]
)
@@ -0,0 +1,829 @@
import Foundation
import UIKit
import WebKit
import Capacitor
import PushKit
import CallKit
import AVFoundation
import Speech // #5 native transcript: SFSpeechRecognizer (iOS on-device speech-to-text; WKWebView has no Web Speech API)
import LiveKit // SPM product name is 'LiveKit' (Package.swift). (The old CocoaPods module was 'LiveKitClient'.)
// Native calling for Biz Connect (iOS). Registered by `cap sync` as window.Capacitor.Plugins.NativeCall.
//
// ARCHITECTURE (native media):
// * PushKit: registers for VoIP pushes, reports the VoIP token to JS (-> /api/v1/devices 'ios-voip').
// * CallKit: incoming VoIP push -> full-screen system ring (works when force-killed). The CallKit call
// stays ACTIVE for the whole call (that's what foregrounds/unlocks the app on answer and keeps the call
// alive in the background).
// * LiveKit: the call MEDIA runs NATIVELY via the LiveKit iOS SDK so the mic works with an active CallKit
// call (WebKit's WebRTC could not) and audio survives backgrounding. The VoIP payload carries the
// LiveKit url+token so we can connect immediately on answer, even from a killed state; outgoing calls get
// the token from the WebView via reportOutgoingCall(). The WebView is UI only for native calls (it must
// NOT also join the room LiveKit allows one connection per identity).
@objc(NativeCallPlugin)
public class NativeCallPlugin: CAPPlugin, CAPBridgedPlugin, PKPushRegistryDelegate, CXProviderDelegate, BroadcastManagerDelegate {
public let identifier = "NativeCallPlugin"
public let jsName = "NativeCall"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "getToken", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "reportOutgoingCall", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "reportIncomingCall", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "reconnectRoom", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "setMuted", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "setCamera", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "switchCamera", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "startScreenShare", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "stopScreenShare", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "startMeetingScreenShare", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "stopMeetingScreenShare", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "setHolePunch", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "setTileZoom", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "syncVideoTiles", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "startTranscription", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "stopTranscription", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "feedAudio", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "endCall", returnType: CAPPluginReturnPromise)
]
private var pushRegistry: PKPushRegistry?
private var provider: CXProvider?
private let callController = CXCallController()
private var voipToken: String = ""
// callUUID -> the call's data (room, kind, callerId, livekitUrl, livekitToken, ).
private var calls: [UUID: [String: Any]] = [:]
// Calls we've already ended locally so a LATE cancel push doesn't re-report (which briefly re-rang).
private var endedCalls = Set<UUID>()
private var room: Room?
private var activeUUID: UUID?
// Native video: one native video view per visible participant (key "__local" or the remote user id),
// drawn over the WebView and positioned to match the web meeting tiles (see syncVideoTiles). UIKit views
// only ever touched on the main thread. TileVideoView adds pinch-zoom/pan for shared screens.
private var tileViews: [String: TileVideoView] = [:]
// Hole-punch: draw the native video BEHIND a transparent WebView so all web UI (bar, menus, panels) floats
// on top. Saved so we can restore the WebView when the call ends.
private var holePunchOn = false
private var savedVCBg: UIColor? // the WebView parent's original background, restored when the call ends
// #5 native transcript: transcribes THIS device's mic (WKWebView has no Web Speech API). Fed by a LiveKit
// AudioRenderer on the local mic track, so it reuses the call's already-open mic (no 2nd audio engine).
private let transcriber = SpeechTranscriber()
override public func load() {
let config = CXProviderConfiguration(localizedName: "Biz Connect")
config.supportsVideo = true
config.maximumCallGroups = 1
config.maximumCallsPerCallGroup = 1
config.supportedHandleTypes = [.generic]
let p = CXProvider(configuration: config)
p.setDelegate(self, queue: nil)
provider = p
let registry = PKPushRegistry(queue: .main)
registry.delegate = self
registry.desiredPushTypes = [.voIP]
pushRegistry = registry
// CallKit audio coordination (LiveKit 2.15+, pinned to the git tag in ios-patch.sh). LiveKit's automatic
// AVAudioSession config RACES CallKit's own activation intermittent dead mic / no audio + the output
// route only settling once audio flows ("speaker turns on late"). Fix: turn auto-config OFF and keep the
// engine OFF; we configure the session and enable the engine ONLY in didActivate.
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false
try? AudioManager.shared.setEngineAvailability(.none)
// Re-assert the LOUDSPEAKER whenever iOS routes call audio back to the quiet earpiece. The LiveKit
// audio engine starting up right after CallKit activates the session flips the route to the built-in
// receiver that's the "sound is on the earpiece until I tap something" bug (tapping mic/cam re-ran
// preferSpeaker and fixed it). Listening for route changes makes that self-healing.
NotificationCenter.default.addObserver(self, selector: #selector(audioRouteChanged(_:)),
name: AVAudioSession.routeChangeNotification, object: nil)
// Screen sharing (ReplayKit broadcast extension). LiveKit tells us when a broadcast starts/stops and
// (with shouldPublishTrack=true, the default) auto-publishes/unpublishes the screen-share track.
BroadcastManager.shared.delegate = self
// #5 native transcript: each finalized speech segment the web (meeting-transcript over the WS), which
// merges it into the shared meeting transcript (same path as desktop's Web Speech API).
transcriber.onFinal = { [weak self] text in self?.notifyListeners("transcript", data: ["text": text]) }
// Make the WebView transparent at STARTUP. WKWebView can IGNORE isOpaque=false when it's flipped after
// the page has already rendered the likely reason the hole-punch showed no video. Doing it once, up
// front, makes the transparent-meeting areas actually reveal the native video behind the WebView. The
// web body is opaque, so the app looks normal outside a call.
DispatchQueue.main.async { [weak self] in self?.makeWebViewTransparent() }
}
private func makeWebViewTransparent() {
guard let web = bridge?.webView else { return }
web.isOpaque = false
web.backgroundColor = .clear
web.scrollView.isOpaque = false // the scrollView being opaque can occlude native content behind the WebView
web.scrollView.backgroundColor = .clear
}
@objc private func audioRouteChanged(_ note: Notification) {
guard room != nil else { return } // only steer the route during an active native call
// Let the engine's own route change settle first, then override if we landed on the earpiece.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) { [weak self] in self?.preferSpeaker() }
}
// MARK: - LiveKit media
private func connectRoom(url: String, token: String) {
guard !url.isEmpty, !token.isEmpty else { return }
// Ask for mic permission now (we still connect MUTED). If it stays "undetermined", enabling the audio
// engine in didActivate can block on first use determining it up front avoids that.
AVAudioSession.sharedInstance().requestRecordPermission { _ in }
let old = room
// Route screen-share through the ReplayKit broadcast extension (so the user can share their screen
// even when the app is backgrounded, and it captures the whole phone, not just the WebView).
let opts = RoomOptions(defaultScreenShareCaptureOptions: ScreenShareCaptureOptions(useBroadcastExtension: true))
let r = Room(roomOptions: opts)
room = r
Task { [weak self] in
await old?.disconnect() // drop any previous/stale connection so we never leave DUPLICATE participants
do {
try await r.connect(url: url, token: token)
// House rule: answer MUTED. Not enabling the mic here means nothing is captured/published
// until the user taps Mic in the meeting UI ( setMuted(false) setMicrophone(true)), which
// is also when iOS asks for mic permission. Playback (hearing others) is unaffected.
try await r.localParticipant.setMicrophone(enabled: false)
self?.notifyListeners("callConnected", data: ["ok": true])
} catch {
self?.notifyListeners("callError", data: ["error": String(describing: error)])
}
}
}
private func disconnectRoom() {
let r = room
room = nil
transcriber.stop() // #5: end any live transcription with the call
Task { await r?.disconnect() }
removeAllTileViews()
DispatchQueue.main.async { [weak self] in guard let self = self, let web = self.bridge?.webView else { return }; self.applyHolePunchRestore(web) }
}
// MARK: - Native video (tile rendering, Increment 2b)
//
// The WebView owns the meeting UI (grid, roster, controls) but for a native call has NO LiveKit
// connection, so it can't render any video. The video lives only in the plugin's LiveKit connection.
// So we draw native VideoViews on top of the WebView, positioned to match each web tile: the web reports
// each tile's on-screen rect + the participant's user id (syncVideoTiles), and we place/size a VideoView
// for whichever participants currently have a live camera track. Views are subviews of the WKWebView, so
// their frames use the SAME coordinate space as getBoundingClientRect (CSS px == points, both
// viewport-relative) and stay aligned as the page scrolls.
// Find the live (unmuted, subscribed) camera track for a user id nil when the camera is off, so the web
// tile's avatar shows through instead.
private func cameraTrack(forUid uid: String, isLocal: Bool) -> VideoTrack? {
guard let room = room else { return nil }
let pubs: [TrackPublication]
if isLocal {
pubs = room.localParticipant.videoTracks
} else {
guard let p = room.remoteParticipants[Participant.Identity(from: uid)] else { return nil }
pubs = p.videoTracks
}
guard let pub = pubs.first(where: { $0.source == .camera && !$0.isMuted && $0.track != nil }) else { return nil }
return pub.track as? VideoTrack
}
// The remote screen-share track for a user id nil if they aren't sharing (or it isn't subscribed yet).
// (Local screen-share isn't supported on iOS no ReplayKit broadcast extension so this is remote-only.)
private func screenTrack(forUid uid: String) -> VideoTrack? {
guard let room = room, let p = room.remoteParticipants[Participant.Identity(from: uid)] else { return nil }
guard let pub = p.videoTracks.first(where: { $0.source == .screenShareVideo && !$0.isMuted && $0.track != nil }) else { return nil }
return pub.track as? VideoTrack
}
private func tileKey(uid: String, isLocal: Bool) -> String { isLocal ? "__local" : uid }
private func removeAllTileViews() {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
for (_, vv) in self.tileViews { vv.removeFromSuperview() }
self.tileViews.removeAll()
}
}
// Create a tile view BEHIND the whole WebView (in its superview). WKWebView does NOT composite native
// subviews placed under its scrollView through transparent web content, so the video must sit behind the
// (transparent) WebView itself; the web UI then paints on top. No native overlays the web tile draws them.
private func makeTileView(host: WKWebView, key: String) -> TileVideoView {
let v = TileVideoView(frame: .zero)
if let sup = host.superview { sup.insertSubview(v, belowSubview: host) } else { host.addSubview(v) }
tileViews[key] = v
return v
}
// Turn hole-punch on/off. Transparency is already set at startup (makeWebViewTransparent); here we just add
// a BLACK backing to the WebView's parent (the layer directly behind the video tiles) during the call, and
// remove it + the tiles afterwards.
@objc func setHolePunch(_ call: CAPPluginCall) {
let on = call.getBool("on") ?? false
DispatchQueue.main.async { [weak self] in
guard let self = self, let web = self.bridge?.webView else { call.resolve(); return }
self.makeWebViewTransparent() // belt-and-braces
let parent = web.superview
if on {
if !self.holePunchOn { self.savedVCBg = parent?.backgroundColor }
parent?.backgroundColor = .black
self.holePunchOn = true
} else {
self.applyHolePunchRestore(web)
for (_, vv) in self.tileViews { vv.removeFromSuperview() }
self.tileViews.removeAll()
}
call.resolve()
}
}
// Remove the black backing (leave the WebView transparent the web body is opaque, so it looks normal).
private func applyHolePunchRestore(_ web: WKWebView) {
guard holePunchOn else { return }
web.superview?.backgroundColor = savedVCBg
holePunchOn = false
}
// Web-forwarded zoom: touches land on the WebView (on top), so the web captures pinch/pan on the shared
// screen and forwards the transform here; we apply it to that tile's inner video.
@objc func setTileZoom(_ call: CAPPluginCall) {
let key = tileKey(uid: call.getString("uid") ?? "", isLocal: call.getBool("local") ?? false)
let scale = CGFloat(call.getDouble("scale") ?? 1)
let tx = CGFloat(call.getDouble("tx") ?? 0)
let ty = CGFloat(call.getDouble("ty") ?? 0)
DispatchQueue.main.async { [weak self] in self?.tileViews[key]?.applyZoom(scale: scale, tx: tx, ty: ty) }
call.resolve()
}
// Route call audio to the LOUDSPEAKER when we'd otherwise be on the quiet earpiece. Guarded so a connected
// wired/Bluetooth headset (any non-receiver route) still wins. Re-asserted on mute toggles because enabling
// the mic can flip the route back to the earpiece.
private func preferSpeaker() {
let s = AVAudioSession.sharedInstance()
if s.currentRoute.outputs.contains(where: { $0.portType == .builtInReceiver }) {
try? s.overrideOutputAudioPort(.speaker)
}
}
// MARK: - JS-callable methods
@objc func getToken(_ call: CAPPluginCall) { call.resolve(["token": voipToken]) }
// Outgoing call from the web app: start a CallKit outgoing call AND connect the LiveKit room natively.
@objc func reportOutgoingCall(_ call: CAPPluginCall) {
guard let uuidStr = call.getString("callUUID"), let uuid = UUID(uuidString: uuidStr) else {
call.reject("callUUID required"); return
}
let url = call.getString("url") ?? ""
let token = call.getString("token") ?? ""
let video = call.getBool("hasVideo") ?? false
calls[uuid] = ["room": call.getString("room") ?? "", "kind": call.getString("kind") ?? "dm",
"livekitUrl": url, "livekitToken": token]
activeUUID = uuid
let handle = CXHandle(type: .generic, value: call.getString("peerName") ?? "Call")
let start = CXStartCallAction(call: uuid, handle: handle)
start.isVideo = video
callController.request(CXTransaction(action: start)) { [weak self] error in
if let error = error { call.reject(error.localizedDescription); return }
self?.connectRoom(url: url, token: token)
// Start muted (house rule) also reflect it on the CallKit system call screen.
self?.callController.request(CXTransaction(action: CXSetMutedCallAction(call: uuid, muted: true))) { _ in }
self?.provider?.reportOutgoingCall(with: uuid, connectedAt: Date())
call.resolve()
}
}
// Ring CallKit from a WEBSOCKET call event (a 2nd path alongside the VoIP push). When the app is open the
// WS is connected and reliable, but the VoIP push can be delayed/dropped "sometimes it doesn't ring".
// Deduped by UUID: if the VoIP push already reported this call, this is a no-op (and vice-versa).
@objc func reportIncomingCall(_ call: CAPPluginCall) {
guard let uuidStr = call.getString("callUUID"), let uuid = UUID(uuidString: uuidStr) else {
call.reject("callUUID required"); return
}
// Already handled (ended, ringing, or active) don't re-report (CallKit would reject a dup anyway).
if endedCalls.contains(uuid) || calls[uuid] != nil || activeUUID == uuid { call.resolve(); return }
let callerName = call.getString("callerName") ?? call.getString("groupName") ?? "Incoming call"
let hasVideo = call.getBool("hasVideo") ?? false
calls[uuid] = [
"callUUID": uuidStr, "room": call.getString("room") ?? "", "kind": call.getString("kind") ?? "dm",
"callerId": call.getString("callerId") ?? "", "callerName": callerName,
"groupId": call.getString("groupId") ?? "", "groupName": call.getString("groupName") ?? "",
"hasVideo": hasVideo, "livekitUrl": call.getString("url") ?? "", "livekitToken": call.getString("token") ?? "",
]
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: callerName)
update.localizedCallerName = callerName
update.hasVideo = hasVideo
update.supportsHolding = false; update.supportsGrouping = false; update.supportsUngrouping = false
provider?.reportNewIncomingCall(with: uuid, update: update) { _ in }
call.resolve()
}
// #12 Multi-device: swap the media connection to a token whose identity = this device's mesh peerId (unique
// per connection). The web calls this once the native WebView has joined the mesh and has a peerId. On
// answer we connected INSTANTLY with the push token (identity=userId) for zero-latency audio; this re-homes
// the media onto the unique peerId identity so two devices of the same user are distinct LiveKit
// participants (LiveKit allows one connection per identity otherwise the older device is kicked and
// "audio jumps to whichever joined last"). connectRoom disconnects the old room first; the CallKit call and
// its audio session stay active, so audio just re-attaches. callConnected fires on success web re-applies
// mic/cam. Guarded to only run during an active call.
@objc func reconnectRoom(_ call: CAPPluginCall) {
let url = call.getString("url") ?? ""
let token = call.getString("token") ?? ""
guard room != nil, !url.isEmpty, !token.isEmpty else { call.resolve(); return }
connectRoom(url: url, token: token)
call.resolve()
}
@objc func setMuted(_ call: CAPPluginCall) {
let muted = call.getBool("muted") ?? false
// Drive mute THROUGH CallKit so the system call screen and the in-app meeting UI stay in sync (the
// CXSetMutedCallAction handler does the actual setMicrophone). Fall back to a direct call if somehow
// there's no active CallKit call.
if let uuid = activeUUID {
callController.request(CXTransaction(action: CXSetMutedCallAction(call: uuid, muted: muted))) { _ in }
} else {
let r = room
Task { try? await r?.localParticipant.setMicrophone(enabled: !muted) }
}
call.resolve()
}
// Enable/disable the local camera. Publishing it makes this user's video appear for everyone else (their
// web/desktop clients render it via their own SFU subscription); locally it's drawn on the __local tile by
// syncVideoTiles (the web triggers a sync right after this resolves). Front camera only for now.
@objc func setCamera(_ call: CAPPluginCall) {
guard let r = room else { call.reject("no active call"); return }
let on = call.getBool("on") ?? false
Task {
do {
try await r.localParticipant.setCamera(
enabled: on,
captureOptions: CameraCaptureOptions(position: .front))
call.resolve(["on": on])
} catch {
call.reject("camera failed: \(String(describing: error))")
}
}
}
// Flip the local camera between front and back.
@objc func switchCamera(_ call: CAPPluginCall) {
guard let r = room else { call.reject("no active call"); return }
let pub = r.localParticipant.videoTracks.first(where: { $0.source == .camera })
guard let track = pub?.track as? LocalVideoTrack, let cam = track.capturer as? CameraCapturer else {
call.reject("camera not active"); return
}
Task {
do { _ = try await cam.switchCameraPosition(); call.resolve() }
catch { call.reject("switch failed: \(String(describing: error))") }
}
}
// Screen sharing from iOS: show the system broadcast picker. When the user starts the broadcast, the
// extension streams the screen to us over IPC and LiveKit publishes it (BroadcastManager.shouldPublishTrack
// defaults true). broadcastManager(didChangeState:) fires screenShareState back to the web either way.
@objc func startScreenShare(_ call: CAPPluginCall) {
guard room != nil else { call.reject("no active call"); return }
DispatchQueue.main.async { BroadcastManager.shared.requestActivation() } // presents RPSystemBroadcastPickerView
call.resolve()
}
@objc func stopScreenShare(_ call: CAPPluginCall) {
BroadcastManager.shared.requestStop()
call.resolve()
}
// Screen share into a SCHEDULED / code-joined SFU meeting. The WebView already holds the meeting
// connection (identity = peerId) and WKWebView has no getDisplayMedia so we open a SECOND, screen-ONLY
// native LiveKit connection under a distinct `<peerId>-screen` identity and publish the ReplayKit
// broadcast into the SAME room. The WebView maps that identity back onto the sharer's tile.
@objc func startMeetingScreenShare(_ call: CAPPluginCall) {
let url = call.getString("url") ?? ""
let token = call.getString("token") ?? ""
guard !url.isEmpty, !token.isEmpty else { call.reject("url/token required"); return }
connectScreenRoom(url: url, token: token)
DispatchQueue.main.async { BroadcastManager.shared.requestActivation() } // system broadcast picker
call.resolve()
}
@objc func stopMeetingScreenShare(_ call: CAPPluginCall) {
BroadcastManager.shared.requestStop()
let r = room; room = nil
Task { await r?.disconnect() } // drop the screen-only connection (no call/tile/transcriber side effects)
call.resolve()
}
// A screen-ONLY LiveKit connection (mic off, no camera) used purely to publish the ReplayKit broadcast
// into an SFU meeting. Unlike connectRoom() it enables no mic and fires no callConnected this is not a call.
private func connectScreenRoom(url: String, token: String) {
guard !url.isEmpty, !token.isEmpty else { return }
let old = room
let opts = RoomOptions(defaultScreenShareCaptureOptions: ScreenShareCaptureOptions(useBroadcastExtension: true))
let r = Room(roomOptions: opts)
room = r
Task { [weak self] in
await old?.disconnect() // never leave a duplicate connection
do { try await r.connect(url: url, token: token) }
catch { self?.notifyListeners("screenShareState", data: ["sharing": false, "error": String(describing: error)]) }
}
}
// MARK: - #5 Live transcript (native SFSpeechRecognizer)
// The current published local mic track the source we tap for transcription. nil until the user has
// unmuted at least once (the mic is published on unmute), or between reconnects.
private func localAudioTrack() -> LocalAudioTrack? {
return room?.localParticipant.audioTracks.first?.track as? LocalAudioTrack
}
// Start transcribing this device's mic (WKWebView has no Web Speech API). Two audio sources:
// * NATIVE CALL (default): the plugin owns the LiveKit room, so we tap the local mic track with a LiveKit
// AudioRenderer (reuses the call's open mic reliable, no 2nd capturer). Re-attaches on unmute.
// * SCHEDULED/WEB MEETING ({external:true}): the WebView owns the mic (the plugin has no room), so the web
// reads its own mic PCM via Web Audio and pushes it here with feedAudio() no second mic capture on iOS
// (two input units would fight and yield silence).
@objc func startTranscription(_ call: CAPPluginCall) {
if call.getBool("external") == true {
transcriber.startExternal()
} else {
transcriber.start(track: localAudioTrack())
}
call.resolve()
}
@objc func stopTranscription(_ call: CAPPluginCall) {
transcriber.stop()
call.resolve()
}
// Web-forwarded mic PCM for the {external:true} path (scheduled/web meetings). `pcm` = base64 little-endian
// Int16 mono at `rate` Hz (the web downsamples to 16 kHz). Fed straight into the recognizer.
@objc func feedAudio(_ call: CAPPluginCall) {
guard let b64 = call.getString("pcm"), let data = Data(base64Encoded: b64) else { call.resolve(); return }
let rate = call.getDouble("rate") ?? 16000
transcriber.appendPCM(int16: data, sampleRate: rate)
call.resolve()
}
// MARK: - BroadcastManagerDelegate
public func broadcastManager(didChangeState isBroadcasting: Bool) {
notifyListeners("screenShareState", data: ["sharing": isBroadcasting])
}
// Position native video views to match the web meeting tiles. `tiles` = [{uid, local, x, y, w, h}] in
// CSS px (== points; getBoundingClientRect coords). We create/move a VideoView for each participant that
// has a live camera track, and remove views for tiles that are gone or whose camera is off (so the web
// avatar shows). Called on a short poll by the web while a native call is on screen, plus on demand.
@objc func syncVideoTiles(_ call: CAPPluginCall) {
let tiles = (call.getArray("tiles") as? [[String: Any]]) ?? []
DispatchQueue.main.async { [weak self] in
guard let self = self else { call.resolve(); return }
guard let host = self.bridge?.webView else { call.resolve(); return }
var wanted = Set<String>()
for t in tiles {
guard let uid = t["uid"] as? String, !uid.isEmpty else { continue }
let isLocal = (t["local"] as? Bool) ?? false
func num(_ k: String) -> CGFloat { CGFloat((t[k] as? NSNumber)?.doubleValue ?? 0) }
let x = num("x"), y = num("y"), w = num("w"), h = num("h")
if w < 2 || h < 2 { continue }
let key = self.tileKey(uid: uid, isLocal: isLocal)
// A tile flagged `screen` is a sharer's stage tile show their screen-share track (fit, so it
// isn't cropped); otherwise the camera (fill). Either is nil when off web avatar shows.
let wantScreen = (t["screen"] as? Bool) ?? false
guard let track = wantScreen ? self.screenTrack(forUid: uid)
: self.cameraTrack(forUid: uid, isLocal: isLocal) else { continue }
wanted.insert(key)
let vv = self.tileViews[key] ?? self.makeTileView(host: host, key: key)
if vv.superview !== host.superview, let sup = host.superview { sup.insertSubview(vv, belowSubview: host) } // keep BEHIND the transparent WebView
vv.layoutMode = wantScreen ? .fit : .fill
if vv.track !== track { vv.track = track }
// The container tracks the tile rect. getBoundingClientRect is in the WebView's coordinate space;
// convert it into the superview (where the tiles live) robust to any WebView offset/inset. The
// zoom transform (web-forwarded via setTileZoom) lives on the INNER video, so this never fights it.
vv.frame = host.convert(CGRect(x: x, y: y, width: w, height: h), to: host.superview)
}
// Drop views for participants no longer present / camera turned off.
for (key, vv) in self.tileViews where !wanted.contains(key) {
vv.removeFromSuperview(); self.tileViews.removeValue(forKey: key)
}
call.resolve()
}
}
// End the CallKit call (remote hung up / user ended from the web UI). No callUUID -> end all.
@objc func endCall(_ call: CAPPluginCall) {
if let uuidStr = call.getString("callUUID"), let uuid = UUID(uuidString: uuidStr) {
requestEnd(uuid)
} else {
for uuid in calls.keys { requestEnd(uuid) }
if let a = activeUUID { requestEnd(a) }
}
call.resolve()
}
private func requestEnd(_ uuid: UUID) {
callController.request(CXTransaction(action: CXEndCallAction(call: uuid))) { _ in }
calls.removeValue(forKey: uuid)
endedCalls.insert(uuid)
}
// MARK: - PushKit (VoIP)
public func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let token = pushCredentials.token.map { String(format: "%02x", $0) }.joined()
voipToken = token
notifyListeners("voipToken", data: ["token": token])
}
public func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
voipToken = ""
}
// Incoming VoIP push. iOS 13+: we MUST reportNewIncomingCall for EVERY push before completion(), or the
// app is terminated.
public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
var dict: [String: Any] = [:]
for (k, v) in payload.dictionaryPayload { if let ks = k as? String { dict[ks] = v } }
let uuid = UUID(uuidString: (dict["callUUID"] as? String) ?? "") ?? UUID()
// CANCEL: caller hung up / declined / timed out. iOS requires a reported call per push, but blindly
// reporting a NEW incoming call is what caused the "rings back for a second" blip on a call we've
// already handled. So:
if (dict["type"] as? String) == "cancel" {
// iOS 13+ TERMINATES the app if a VoIP push doesn't result in reportNewIncomingCall before
// completion() that's the crash after several calls (my earlier "no-blip" optimization SKIPPED
// the report for known/ended calls, which iOS kills for). So ALWAYS report, then immediately end:
// * uuid already ringing/active the report errors harmlessly (NO second ring), reportCall ends it.
// * late/duplicate cancel (done) a brief, unavoidable blip (acceptable; a crash is not).
let u = CXCallUpdate()
u.remoteHandle = CXHandle(type: .generic, value: (dict["callerName"] as? String) ?? "Call")
let wasActive = (activeUUID == uuid)
var ev = calls[uuid] ?? [:]; ev["callUUID"] = uuid.uuidString
calls.removeValue(forKey: uuid)
endedCalls.insert(uuid)
if wasActive { disconnectRoom(); activeUUID = nil }
provider?.reportNewIncomingCall(with: uuid, update: u) { [weak self] _ in
self?.provider?.reportCall(with: uuid, endedAt: Date(), reason: .remoteEnded)
if wasActive { self?.notifyListeners("endCall", data: ev) } // active call cancelled leave the meeting
completion()
}
return
}
let callerName = (dict["callerName"] as? String) ?? (dict["groupName"] as? String) ?? "Incoming call"
let hasVideo = (dict["hasVideo"] as? Bool) ?? false
calls[uuid] = dict
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: callerName)
update.localizedCallerName = callerName
update.hasVideo = hasVideo
update.supportsHolding = false
update.supportsGrouping = false
update.supportsUngrouping = false
provider?.reportNewIncomingCall(with: uuid, update: update) { _ in completion() }
}
// MARK: - CXProviderDelegate
public func providerDidReset(_ provider: CXProvider) {
disconnectRoom()
calls.removeAll(); endedCalls.removeAll(); activeUUID = nil
}
public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
let uuid = action.callUUID
let data = calls[uuid] ?? [:]
activeUUID = uuid
action.fulfill()
// Keep the CallKit call ACTIVE (foregrounds the app + keeps the call alive). Connect the LiveKit room
// NATIVELY so the mic works with the active CallKit call and audio survives backgrounding.
connectRoom(url: (data["livekitUrl"] as? String) ?? "", token: (data["livekitToken"] as? String) ?? "")
// We answer muted (house rule) reflect that on the CallKit system call screen (the mic button there
// showed unmuted before, even though we were functionally muted).
callController.request(CXTransaction(action: CXSetMutedCallAction(call: uuid, muted: true))) { _ in }
var ev = data; ev["callUUID"] = uuid.uuidString
// Answering from a KILLED/locked state launches the app the WebView's JS listener may not be attached
// yet, so retain the event until it is. Without this the "answered" signal is lost, the server's
// unanswered timer fires, and the call is cancelled ~40s after pickup.
notifyListeners("answerCall", data: ev, retainUntilConsumed: true)
}
public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
var data: [String: Any] = calls[action.callUUID] ?? [:]
data["callUUID"] = action.callUUID.uuidString
disconnectRoom()
notifyListeners("endCall", data: data)
calls.removeValue(forKey: action.callUUID)
endedCalls.insert(action.callUUID)
if activeUUID == action.callUUID { activeUUID = nil }
action.fulfill()
}
public func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
provider.reportOutgoingCall(with: action.callUUID, startedConnectingAt: Date())
action.fulfill()
}
public func provider(_ provider: CXProvider, perform action: CXSetMutedCallAction) {
let r = room
Task { [weak self] in
try? await r?.localParticipant.setMicrophone(enabled: !action.isMuted)
self?.preferSpeaker() // toggling the mic can flip the route back to the earpiece re-assert speaker
// #5: unmuting publishes the mic track (re)attach the transcriber's renderer to it if transcript is on.
if !action.isMuted { self?.transcriber.refresh(track: self?.localAudioTrack()) }
}
notifyListeners("setMuted", data: ["callUUID": action.callUUID.uuidString, "muted": action.isMuted])
action.fulfill()
}
// CallKit owns the AVAudioSession lifecycle. Since LiveKit auto-config is OFF, configure the session HERE
// when CallKit activates it and enable LiveKit's audio engine. This is the fix for the intermittent
// dead mic / no-audio and late speaker routing. Don't call setActive(true): CallKit already activated it.
public func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
do {
// Route to the LOUDSPEAKER by default (earpiece was the .voiceChat default). .videoChat +
// .defaultToSpeaker prefers the speaker while still letting wired/Bluetooth headsets win.
try audioSession.setCategory(.playAndRecord, mode: .videoChat,
options: [.defaultToSpeaker, .allowBluetooth, .allowBluetoothA2DP])
try AudioManager.shared.setEngineAvailability(.default)
preferSpeaker() // belt-and-braces: if we still landed on the earpiece, force the speaker
let route = audioSession.currentRoute.outputs.first?.portType.rawValue ?? "none"
notifyListeners("audioActivated", data: ["ok": true, "route": route])
} catch {
notifyListeners("audioActivated", data: ["ok": false, "error": String(describing: error)])
}
}
public func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
try? AudioManager.shared.setEngineAvailability(.none)
notifyListeners("audioDeactivated", data: ["ok": true])
}
}
// A tile view = a container holding a LiveKit VideoView. We CANNOT subclass VideoView (it's `public`, not
// `open`, so subclassing outside its module is illegal), so we compose. Under hole-punch the video sits BEHIND
// the (transparent) WebView, so touches never reach it pinch-zoom is captured by the web and forwarded via
// applyZoom(). The container stays frame-synced to the web tile rect; the zoom transform lives on the inner
// video, so the two never fight.
final class TileVideoView: UIView {
let video = VideoView()
// Forward the two properties the plugin sets so call sites read like a VideoView.
var track: VideoTrack? { get { video.track } set { video.track = newValue } }
var layoutMode: VideoView.LayoutMode { get { video.layoutMode } set { video.layoutMode = newValue } }
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .clear // the web tile draws its own frame; gaps show the WebView's black bg
clipsToBounds = true
layer.cornerRadius = 12 // match .meet-tile's border-radius so corners don't poke past the web border
video.layoutMode = .fill
addSubview(video)
}
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
// Position via bounds+center (not frame) so it coexists with the zoom transform.
override func layoutSubviews() {
super.layoutSubviews()
video.bounds = CGRect(origin: .zero, size: bounds.size)
video.center = CGPoint(x: bounds.midX, y: bounds.midY)
}
// Web-forwarded zoom (scale + translation in points). scale<=1 clears the transform.
func applyZoom(scale: CGFloat, tx: CGFloat, ty: CGFloat) {
if scale <= 1.001 { if !video.transform.isIdentity { video.transform = .identity } }
else { video.transform = CGAffineTransform(translationX: tx, y: ty).scaledBy(x: scale, y: scale) }
}
}
// #5 Live transcript on iOS. WKWebView has no Web Speech API, so an iOS participant's speech was never captured
// into the meeting transcript (desktop Chrome/Edge already works). This transcribes THIS device's mic with
// SFSpeechRecognizer, fed by a LiveKit `AudioRenderer` attached to the local mic track so it reuses the call's
// already-open capture (no second AVAudioEngine fighting WebRTC for the audio session). Each finished utterance
// fires `onFinal`; the plugin relays it to the web, which sends it over the meeting WS exactly like the desktop
// path. Segments are cut on a short silence gap (and on the recognizer's own isFinal), and the request is
// restarted per segment so text flows continuously and stays within the recognizer's limits. On-device
// recognition is used when available (offline, continuous, no ~1-minute cap). All state is main-confined except
// the locked `request` that the audio-thread renderer appends to.
final class SpeechTranscriber: NSObject, AudioRenderer, @unchecked Sendable {
var onFinal: ((String) -> Void)?
private let recognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))
private let lock = NSLock()
private var request: SFSpeechAudioBufferRecognitionRequest?
private var task: SFSpeechRecognitionTask?
private weak var track: LocalAudioTrack?
private var running = false
private var latest = ""
private var lastEmitted = ""
private var silenceTimer: DispatchWorkItem?
// Begin transcription tapping a LiveKit local mic track (native calls). Idempotent; asks for Speech
// authorization once. Safe to call before the mic exists `refresh` re-attaches when it publishes (unmute).
func start(track: LocalAudioTrack?) { begin { self.attach(track) } }
// Begin transcription in EXTERNAL mode (scheduled/web meetings): no LiveKit track to tap PCM arrives via
// appendPCM() from the web. Same recognition pipeline.
func startExternal() { begin { } }
private func begin(_ afterStart: @escaping () -> Void) {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if self.running { afterStart(); return }
SFSpeechRecognizer.requestAuthorization { status in
DispatchQueue.main.async {
guard status == .authorized, !self.running else { return }
self.running = true
self.beginRequest()
afterStart()
}
}
}
}
// Web-forwarded PCM (external mode): little-endian Int16 mono Float32 buffer recognizer.
func appendPCM(int16 data: Data, sampleRate: Double) {
let count = data.count / 2
guard count > 0,
let fmt = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: sampleRate, channels: 1, interleaved: false),
let buf = AVAudioPCMBuffer(pcmFormat: fmt, frameCapacity: AVAudioFrameCount(count)) else { return }
buf.frameLength = AVAudioFrameCount(count)
guard let dst = buf.floatChannelData?[0] else { return }
data.withUnsafeBytes { (raw: UnsafeRawBufferPointer) in
let src = raw.bindMemory(to: Int16.self)
for i in 0..<count { dst[i] = Float(src[i]) / 32768.0 }
}
lock.lock(); let r = request; lock.unlock()
r?.append(buf)
}
// (Re)attach to the current local mic track called on start and whenever the mic (re)publishes on unmute.
func refresh(track: LocalAudioTrack?) { DispatchQueue.main.async { [weak self] in self?.attach(track) } }
func stop() {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
self.running = false
self.silenceTimer?.cancel(); self.silenceTimer = nil
self.track?.remove(audioRenderer: self); self.track = nil
self.lock.lock(); let r = self.request; self.request = nil; self.lock.unlock()
r?.endAudio(); self.task?.cancel(); self.task = nil
}
}
private func attach(_ t: LocalAudioTrack?) {
guard running, let t = t, track !== t else { return }
track?.remove(audioRenderer: self)
t.add(audioRenderer: self)
track = t
}
private func beginRequest() {
guard let recognizer = recognizer, recognizer.isAvailable else { return }
let req = SFSpeechAudioBufferRecognitionRequest()
req.shouldReportPartialResults = true // stream results; we only EMIT a segment on silence / isFinal
if recognizer.supportsOnDeviceRecognition { req.requiresOnDeviceRecognition = true }
lock.lock(); request = req; lock.unlock()
latest = ""; lastEmitted = ""
task = recognizer.recognitionTask(with: req) { [weak self] result, error in
guard let self = self else { return }
if let result = result {
let text = result.bestTranscription.formattedString
let isFinal = result.isFinal
DispatchQueue.main.async {
guard self.running else { return }
self.latest = text
if isFinal { self.flushAndRestart() } else { self.armSilenceTimer() }
}
} else if error != nil {
DispatchQueue.main.async { if self.running { self.flushAndRestart() } }
}
}
}
// A short pause = end of an utterance emit it and start a fresh request for the next one.
private func armSilenceTimer() {
silenceTimer?.cancel()
let work = DispatchWorkItem { [weak self] in guard let self = self, self.running else { return }; self.flushAndRestart() }
silenceTimer = work
DispatchQueue.main.asyncAfter(deadline: .now() + 1.4, execute: work)
}
private func flushAndRestart() {
silenceTimer?.cancel(); silenceTimer = nil
let text = latest.trimmingCharacters(in: .whitespacesAndNewlines)
if !text.isEmpty && text != lastEmitted { lastEmitted = text; onFinal?(text) }
guard running else { return }
lock.lock(); let r = request; request = nil; lock.unlock()
r?.endAudio(); task?.cancel(); task = nil
beginRequest()
}
// MARK: AudioRenderer receives the local mic PCM from LiveKit (audio thread).
func render(pcmBuffer: AVAudioPCMBuffer) {
lock.lock(); let r = request; lock.unlock()
r?.append(pcmBuffer)
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"name": "native-call",
"version": "1.0.0",
"description": "Native CallKit + PushKit VoIP calling for Biz Connect (iOS)",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"author": "BizGaze",
"license": "MIT",
"files": [
"dist/",
"ios/",
"NativeCall.podspec",
"Package.swift"
],
"capacitor": {
"ios": {
"src": "ios"
}
},
"devDependencies": {
"@capacitor/core": "^8.0.0"
},
"peerDependencies": {
"@capacitor/core": "^8.0.0"
}
}
+22
View File
@@ -0,0 +1,22 @@
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "ShareInbox",
platforms: [.iOS(.v15)],
products: [
.library(name: "ShareInbox", targets: ["ShareInboxPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
],
targets: [
.target(
name: "ShareInboxPlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
],
path: "ios/Sources/ShareInboxPlugin")
]
)
@@ -0,0 +1,19 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
Pod::Spec.new do |s|
# Pod name MUST be 'ShareInbox' (PascalCase of 'share-inbox') — same rule as the other plugins, or
# pod install fails with "No podspec found for `ShareInbox`".
s.name = 'ShareInbox'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = 'https://bizgaze.com'
s.author = 'BizGaze'
s.source = { :git => 'https://bizgaze.com/share-inbox.git', :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m}'
s.ios.deployment_target = '15.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
end
@@ -0,0 +1,82 @@
import Foundation
import Capacitor
// Reads the files the Share Extension staged into the App Group container, so the web app can pick a
// conversation and send them. The extension and the app are separate processes; the App Group's shared
// container is the only place both can read/write, and it is NOT one of @capacitor/filesystem's known
// directories hence this small bridge.
//
// getPending() { items: [ {kind, name, path, uri, mime, size} | {kind:"text", text} ] }
// `uri` is a file:// URL the web layer turns into a fetchable source with Capacitor.convertFileSrc,
// so the existing upload path can read the bytes without base64 marshalling.
// clear() removes the manifest and every staged file, once the app has taken them.
@objc(ShareInboxPlugin)
public class ShareInboxPlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "ShareInboxPlugin"
public let jsName = "ShareInbox"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "getPending", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "clear", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "setAuth", returnType: CAPPluginReturnPromise)
]
private let appGroup = "group.com.bizgaze.connect"
// The web app hands the extension a bearer token + API base (via /api/share/token) so the extension can
// list chats, upload and send on its own no app-open needed. Stored in the App Group's shared
// UserDefaults, which the extension reads directly. Passing an empty token clears it (e.g. on logout).
@objc func setAuth(_ call: CAPPluginCall) {
let token = call.getString("token") ?? ""
let base = call.getString("base") ?? ""
if let d = UserDefaults(suiteName: appGroup) {
if token.isEmpty { d.removeObject(forKey: "bzc_token"); d.removeObject(forKey: "bzc_base") }
else { d.set(token, forKey: "bzc_token"); d.set(base, forKey: "bzc_base") }
}
call.resolve(["ok": true])
}
@objc func getPending(_ call: CAPPluginCall) {
guard let dir = sharedDir() else { return call.resolve(["items": []]) }
let manifest = dir.appendingPathComponent("manifest.json")
guard let data = try? Data(contentsOf: manifest),
let records = try? JSONSerialization.jsonObject(with: data) as? [[String: Any]] else {
return call.resolve(["items": []])
}
var items: [[String: Any]] = []
for r in records {
let kind = r["kind"] as? String ?? "file"
if kind == "text" {
if let text = r["text"] as? String { items.append(["kind": "text", "text": text]) }
continue
}
// A file record is only usable if its staged copy is still on disk.
guard let path = r["path"] as? String,
FileManager.default.fileExists(atPath: path) else { continue }
let url = URL(fileURLWithPath: path)
items.append([
"kind": "file",
"name": r["name"] as? String ?? url.lastPathComponent,
"path": path,
"uri": url.absoluteString,
"mime": r["mime"] as? String ?? "application/octet-stream",
"size": r["size"] as? Int64 ?? (r["size"] as? Int ?? 0)
])
}
call.resolve(["items": items])
}
@objc func clear(_ call: CAPPluginCall) {
if let dir = sharedDir() {
let fm = FileManager.default
if let entries = try? fm.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil) {
for e in entries { try? fm.removeItem(at: e) }
}
}
call.resolve()
}
private func sharedDir() -> URL? {
guard let base = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup) else { return nil }
return base.appendingPathComponent("Shared", isDirectory: true)
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"name": "share-inbox",
"version": "1.0.0",
"description": "Read files handed to Biz Connect from the iOS share sheet (via the App Group)",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"author": "BizGaze",
"license": "MIT",
"files": [
"dist/",
"ios/",
"ShareInbox.podspec",
"Package.swift"
],
"capacitor": {
"ios": {
"src": "ios"
}
},
"devDependencies": {
"@capacitor/core": "^8.0.0"
},
"peerDependencies": {
"@capacitor/core": "^8.0.0"
}
}
+21
View File
@@ -0,0 +1,21 @@
# App icon & splash source images
`@capacitor/assets` generates every Android (and iOS) icon/splash density from these masters.
| File | Size | Purpose |
|------|------|---------|
| `icon.png` | 1024×1024 | App icon (all densities + Android adaptive icon) |
| `splash.png` | 2732×2732 | Launch splash (light) |
| `splash-dark.png` | 2732×2732 | Launch splash (dark mode) |
These were generated from the existing PWA icon (`server/public/icon-512.png`) + brand blue
`#1F3B73`. To rebrand, replace these three files (keep the sizes) and re-run:
```bash
cd mobile
npm run assets # Android only (npm run assets:all for iOS too)
npx cap sync
```
Tip: for the sharpest result, drop a true 1024×1024 `icon.png` (and a 2732×2732 `splash.png`)
exported from the design source rather than an upscale.
+19
View File
@@ -0,0 +1,19 @@
<!-- Paste these into mobile/android/app/src/main/AndroidManifest.xml, inside <manifest> and
directly above the <application> element. INTERNET is already added by Capacitor.
See ANDROID_SETUP.md §3. -->
<!-- Push notifications: Android 13 (API 33)+ shows a runtime prompt -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<!-- Voice / video calls + camera, used by the WebRTC features in the web UI -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<!-- Camera is optional hardware (tablets without one can still install) -->
<uses-feature android:name="android.hardware.camera" android:required="false" />
<!-- Later, for screen-sharing FROM the phone (needs a screen-capture plugin):
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
-->
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

+122
View File
@@ -0,0 +1,122 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# Inject the Broadcast Upload Extension (ReplayKit screen sharing) into the Capacitor-generated Xcode project.
# Mirrors add-share-extension.rb, with the extra step that this extension LINKS the LiveKit Swift package
# (LKSampleHandler lives in the LiveKit product), so it adds a package product dependency to the new target.
#
# WHAT IT WIRES:
# * a new app-extension target "BroadcastExtension" (bundle id <app>.broadcast) whose source is our
# SampleHandler.swift (subclass of LiveKit's LKSampleHandler) + Info.plist + entitlements, copied from
# mobile/ios-broadcast/
# * the App Group entitlement (group.com.bizgaze.connect) on the extension (LiveKit's IPC socket lives there)
# * a Swift Package product dependency on LiveKit (github.com/livekit/client-sdk-swift 2.15.3) so the
# extension can subclass LKSampleHandler
# * the extension embedded into the app ("Embed App Extensions") + set as a build dependency
#
# Idempotent: if the target already exists it is removed and rebuilt.
require 'xcodeproj'
require 'fileutils'
ROOT = File.expand_path('..', __dir__)
PROJECT = File.join(ROOT, 'ios', 'App', 'App.xcodeproj')
SRC_DIR = File.join(ROOT, 'ios-broadcast')
APP_DIR = File.join(ROOT, 'ios', 'App')
EXT_NAME = 'BroadcastExtension'
EXT_DIR = File.join(APP_DIR, EXT_NAME)
APP_TARGET = 'App'
APP_BUNDLE = ENV.fetch('BUNDLE_ID', 'com.bizgaze.connect')
EXT_BUNDLE = "#{APP_BUNDLE}.broadcast"
APP_GROUP = 'group.com.bizgaze.connect'
LK_URL = 'https://github.com/livekit/client-sdk-swift.git'
LK_VERSION = '2.15.3'
abort "xcodeproj not found at #{PROJECT}" unless File.directory?(PROJECT)
project = Xcodeproj::Project.open(PROJECT)
app = project.targets.find { |t| t.name == APP_TARGET }
abort "App target not found" unless app
# ── Clean any previous injection so this is idempotent ──────────────────────────────────────────────
project.targets.select { |t| t.name == EXT_NAME }.each do |t|
t.build_configuration_list&.build_configurations&.each { |c| c.remove_from_project }
t.remove_from_project
end
if (grp = project.main_group.children.find { |g| g.respond_to?(:display_name) && g.display_name == EXT_NAME })
grp.remove_from_project
end
# ── Copy our sources into the app project so paths inside the .xcodeproj are stable ──────────────────
FileUtils.mkdir_p(EXT_DIR)
%w[SampleHandler.swift Info.plist BroadcastExtension.entitlements].each do |f|
FileUtils.cp(File.join(SRC_DIR, f), File.join(EXT_DIR, f))
end
# ── Create the extension target ──────────────────────────────────────────────────────────────────────
deployment = app.deployment_target || project.build_configurations.first&.build_settings&.[]('IPHONEOS_DEPLOYMENT_TARGET') || '15.0'
ext = project.new_target(:app_extension, EXT_NAME, :ios, deployment, project.products_group, :swift)
group = project.main_group.new_group(EXT_NAME, EXT_NAME.to_s)
swift_ref = group.new_reference(File.join(EXT_DIR, 'SampleHandler.swift'))
ext.add_file_references([swift_ref])
ext.build_configurations.each do |cfg|
s = cfg.build_settings
s['PRODUCT_BUNDLE_IDENTIFIER'] = EXT_BUNDLE
s['PRODUCT_NAME'] = '$(TARGET_NAME)'
s['INFOPLIST_FILE'] = "#{EXT_NAME}/Info.plist"
s['CODE_SIGN_ENTITLEMENTS'] = "#{EXT_NAME}/BroadcastExtension.entitlements"
s['IPHONEOS_DEPLOYMENT_TARGET'] = deployment
s['SWIFT_VERSION'] = '5.0'
s['TARGETED_DEVICE_FAMILY'] = '1,2'
s['GENERATE_INFOPLIST_FILE'] = 'NO'
s['SKIP_INSTALL'] = 'YES'
s['CODE_SIGN_STYLE'] = 'Manual'
s['MARKETING_VERSION'] = '1.0'
s['CURRENT_PROJECT_VERSION'] = ENV.fetch('BUILD_NUMBER', '1')
s['LD_RUNPATH_SEARCH_PATHS'] = '$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks'
end
# ── Link LiveKit (Swift Package product) so the extension can subclass LKSampleHandler ────────────────
# The app already resolves client-sdk-swift 2.15.3 (via the native-call plugin's Package.swift). Add a
# project-level remote package reference to the SAME repo+version (SPM dedupes it) and attach the "LiveKit"
# product to this extension target.
root = project.root_object
pkg = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == LK_URL }
unless pkg
pkg = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
pkg.repositoryURL = LK_URL
pkg.requirement = { 'kind' => 'exactVersion', 'version' => LK_VERSION }
root.package_references << pkg
end
prod = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
prod.package = pkg
prod.product_name = 'LiveKit'
ext.package_product_dependencies << prod
bf = project.new(Xcodeproj::Project::Object::PBXBuildFile)
bf.product_ref = prod
ext.frameworks_build_phase.files << bf
# ── App Group entitlement on the MAIN app target too (merge — keep aps-environment etc.) ──────────────
app_ent_path = File.join(APP_DIR, 'App', 'App.entitlements')
app_ent = File.exist?(app_ent_path) ? (Xcodeproj::Plist.read_from_path(app_ent_path) || {}) : {}
groups = app_ent['com.apple.security.application-groups'] || []
groups << APP_GROUP unless groups.include?(APP_GROUP)
app_ent['com.apple.security.application-groups'] = groups
Xcodeproj::Plist.write_to_path(app_ent, app_ent_path)
app.build_configurations.each { |cfg| cfg.build_settings['CODE_SIGN_ENTITLEMENTS'] = 'App/App.entitlements' }
# ── Embed the extension into the app + depend on it ──────────────────────────────────────────────────
app.add_dependency(ext)
embed = app.build_phases.find { |p| p.respond_to?(:symbol_dst_subfolder_spec) && p.symbol_dst_subfolder_spec == :plug_ins }
embed ||= begin
phase = app.new_copy_files_build_phase('Embed App Extensions')
phase.symbol_dst_subfolder_spec = :plug_ins
phase
end
build_file = embed.add_file_reference(ext.product_reference)
build_file.settings = { 'ATTRIBUTES' => ['RemoveHeadersOnCopy'] }
project.save
puts "Broadcast Extension injected: #{EXT_NAME} (#{EXT_BUNDLE}) linked to LiveKit #{LK_VERSION}, embedded in #{APP_TARGET}"
+136
View File
@@ -0,0 +1,136 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# Inject the Share Extension target into the Capacitor-generated Xcode project.
#
# WHY A SCRIPT: `npx cap add ios` scaffolds mobile/ios/App from a template that knows nothing about our
# extension, and Codemagic runs on a fresh checkout every time, so the target has to be (re)created on each
# build. This uses the `xcodeproj` gem, which ships with CocoaPods (already installed for `pod install`),
# so there is no extra dependency to add.
#
# WHAT IT WIRES:
# * a new app-extension target "ShareExtension" (bundle id <app>.share) whose sources are our
# ShareViewController.swift + Info.plist, copied in from mobile/ios-share/
# * the App Group entitlement on BOTH the App target and the extension (the only storage both processes
# can see), via the two .entitlements files
# * the extension embedded into the app ("Embed App Extensions" phase) and set as a build dependency
#
# Idempotent: if the target already exists it is removed and rebuilt, so re-runs never duplicate it.
require 'xcodeproj'
require 'fileutils'
ROOT = File.expand_path('..', __dir__) # repo/mobile (this script is in mobile/scripts)
PROJECT = File.join(ROOT, 'ios', 'App', 'App.xcodeproj')
SRC_DIR = File.join(ROOT, 'ios-share') # our checked-in extension sources
APP_DIR = File.join(ROOT, 'ios', 'App')
EXT_NAME = 'ShareExtension'
EXT_DIR = File.join(APP_DIR, EXT_NAME)
APP_TARGET = 'App'
APP_BUNDLE = ENV.fetch('BUNDLE_ID', 'com.bizgaze.connect')
EXT_BUNDLE = "#{APP_BUNDLE}.share"
abort "xcodeproj not found at #{PROJECT}" unless File.directory?(PROJECT)
project = Xcodeproj::Project.open(PROJECT)
app = project.targets.find { |t| t.name == APP_TARGET }
abort "App target not found" unless app
# ── Clean any previous injection so this is idempotent ──────────────────────────────────────────────
project.targets.select { |t| t.name == EXT_NAME }.each do |t|
t.build_configuration_list&.build_configurations&.each { |c| c.remove_from_project }
t.remove_from_project
end
if (grp = project.main_group.children.find { |g| g.respond_to?(:display_name) && g.display_name == EXT_NAME })
grp.remove_from_project
end
# ── Copy our sources into the app project so paths inside the .xcodeproj are stable ──────────────────
FileUtils.mkdir_p(EXT_DIR)
%w[ShareViewController.swift Info.plist ShareExtension.entitlements].each do |f|
FileUtils.cp(File.join(SRC_DIR, f), File.join(EXT_DIR, f))
end
# The App Group entitlement for the MAIN app. MERGE, don't overwrite: the push-notifications plugin may
# already have written App/App.entitlements (aps-environment), and clobbering it would break push. We add
# the app-group array into whatever is there (or create the file if it's absent).
APP_GROUP = 'group.com.bizgaze.connect'
app_ent_path = File.join(APP_DIR, 'App', 'App.entitlements')
app_ent = File.exist?(app_ent_path) ? (Xcodeproj::Plist.read_from_path(app_ent_path) || {}) : {}
groups = app_ent['com.apple.security.application-groups'] || []
groups << APP_GROUP unless groups.include?(APP_GROUP)
app_ent['com.apple.security.application-groups'] = groups
Xcodeproj::Plist.write_to_path(app_ent, app_ent_path)
puts "App entitlements: app-group ensured (kept #{(app_ent.keys - ['com.apple.security.application-groups']).join(', ')})"
# ── Create the extension target ──────────────────────────────────────────────────────────────────────
# deployment_target can be nil when it's only set at the project level — fall back so we never create a
# target with an empty minimum-OS (which Xcode then flags).
deployment = app.deployment_target || project.build_configurations.first&.build_settings&.[]('IPHONEOS_DEPLOYMENT_TARGET') || '15.0'
ext = project.new_target(
:app_extension, EXT_NAME, :ios,
deployment, project.products_group, :swift
)
# Source file + resources
group = project.main_group.new_group(EXT_NAME, "#{EXT_NAME}")
swift_ref = group.new_reference(File.join(EXT_DIR, 'ShareViewController.swift'))
ext.add_file_references([swift_ref])
# Build settings for every configuration (Debug/Release)
ext.build_configurations.each do |cfg|
s = cfg.build_settings
s['PRODUCT_BUNDLE_IDENTIFIER'] = EXT_BUNDLE
s['PRODUCT_NAME'] = '$(TARGET_NAME)'
s['INFOPLIST_FILE'] = "#{EXT_NAME}/Info.plist"
s['CODE_SIGN_ENTITLEMENTS'] = "#{EXT_NAME}/ShareExtension.entitlements"
s['IPHONEOS_DEPLOYMENT_TARGET'] = deployment
s['SWIFT_VERSION'] = '5.0'
s['TARGETED_DEVICE_FAMILY'] = '1,2'
s['GENERATE_INFOPLIST_FILE'] = 'NO'
s['SKIP_INSTALL'] = 'YES'
s['CODE_SIGN_STYLE'] = 'Manual'
s['MARKETING_VERSION'] = '1.0'
s['CURRENT_PROJECT_VERSION'] = ENV.fetch('BUILD_NUMBER', '1')
s['LD_RUNPATH_SEARCH_PATHS'] = '$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks'
end
# ── App Group entitlement on the MAIN app target too ─────────────────────────────────────────────────
app.build_configurations.each do |cfg|
cfg.build_settings['CODE_SIGN_ENTITLEMENTS'] = 'App/App.entitlements'
end
# ── Embed the extension into the app + depend on it ──────────────────────────────────────────────────
app.add_dependency(ext)
embed = app.build_phases.find { |p| p.respond_to?(:symbol_dst_subfolder_spec) && p.symbol_dst_subfolder_spec == :plug_ins }
embed ||= begin
phase = app.new_copy_files_build_phase('Embed App Extensions')
phase.symbol_dst_subfolder_spec = :plug_ins
phase
end
appex = ext.product_reference
build_file = embed.add_file_reference(appex)
build_file.settings = { 'ATTRIBUTES' => ['RemoveHeadersOnCopy'] }
# ── Bundle the custom notification sound (notif.wav) into the App target ─────────────────────────────
# ios-patch.sh copied it to App/App/notif.wav. Add it as a resource so it ships in the bundle root where
# APNs can find it (the server sends sound:'notif.wav'). Tolerant: never fail the build over the sound.
begin
snd_path = File.join(APP_DIR, 'App', 'notif.wav')
if File.exist?(snd_path)
grp = project.main_group.find_subpath('App', false) || project.main_group
already = app.resources_build_phase.files.any? { |bf| bf.file_ref && bf.file_ref.respond_to?(:display_name) && bf.file_ref.display_name == 'notif.wav' }
unless already
snd_ref = grp.new_reference(snd_path)
app.resources_build_phase.add_file_reference(snd_ref)
end
puts "Notification sound bundled into App resources: notif.wav"
else
puts " (notif.wav not in project — sound not bundled)"
end
rescue => e
puts " (notif.wav bundling skipped: #{e.message})"
end
project.save
puts "Share Extension injected: #{EXT_NAME} (#{EXT_BUNDLE}) embedded in #{APP_TARGET}"
+43
View File
@@ -0,0 +1,43 @@
// Inject the runtime permissions the web UI needs into the Capacitor-generated AndroidManifest.xml.
// Run on Codemagic from the Android workflow:
// node mobile/scripts/android-patch.js mobile/android/app/src/main/AndroidManifest.xml
//
// WHY: mobile/android/ is gitignored (regenerated in CI by `cap add android`, same as iOS ios/). The
// freshly generated manifest only declares INTERNET, so without this the WebRTC calls in the web UI can't
// get camera/mic and Android 13+ never prompts for notifications. This adds the same permissions listed in
// mobile/resources/android-permissions.xml. (When the native-call Android plugin lands, it will contribute
// its own manifest entries via Capacitor manifest-merging; this only covers the app-level WebView perms.)
//
// TOLERANT: exits 0 and no-ops if anything is off, so it can NEVER fail the build. Idempotent (keyed on
// the bzcAndroidPerms marker), so re-runs never duplicate the block.
const fs = require('fs');
const p = process.argv[2];
if (!p || !fs.existsSync(p)) { console.log(' (AndroidManifest.xml not found — permission patch skipped)'); process.exit(0); }
try {
let s = fs.readFileSync(p, 'utf8');
if (s.includes('bzcAndroidPerms') || s.includes('android.permission.RECORD_AUDIO')) {
console.log(' Android permissions already present'); process.exit(0);
}
const block = [
'',
' <!-- bzcAndroidPerms: permissions the Biz Connect web UI needs (see mobile/resources/android-permissions.xml) -->',
' <!-- Push notifications: Android 13 (API 33)+ shows a runtime prompt -->',
' <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />',
' <!-- Voice / video calls + camera, used by the WebRTC features in the web UI -->',
' <uses-permission android:name="android.permission.CAMERA" />',
' <uses-permission android:name="android.permission.RECORD_AUDIO" />',
' <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />',
' <!-- Camera is optional hardware (tablets without one can still install) -->',
' <uses-feature android:name="android.hardware.camera" android:required="false" />',
'',
].join('\n');
const orig = s;
// Insert directly before the closing </manifest> tag.
s = s.replace(/<\/manifest>\s*$/, block + '</manifest>\n');
if (s === orig) { console.log(' could not find </manifest> — permission patch skipped'); process.exit(0); }
fs.writeFileSync(p, s);
console.log(' Android permissions injected into ' + p);
} catch (e) {
console.log(' Android permission patch skipped:', e.message);
}
process.exit(0);
+38
View File
@@ -0,0 +1,38 @@
// Patch the freshly-generated Capacitor iOS AppDelegate so calls DEFAULT to the loudspeaker at launch
// (iOS uses the quiet earpiece otherwise). Run on Codemagic (macOS) from ios-patch.sh:
// node mobile/scripts/inject-audio.js mobile/ios/App/App/AppDelegate.swift
// TOLERANT: exits 0 and no-ops if the template doesn't match, so it can NEVER fail the build.
// NOTE: the earpiece<->speaker TOGGLE is provided by the local Capacitor plugin package mobile/plugins/
// audio-route (registered by cap sync, like @capacitor/share). This file only sets the launch default.
const fs = require('fs');
const p = process.argv[2];
if (!p || !fs.existsSync(p)) { console.log(' (AppDelegate.swift not found — audio patch skipped)'); process.exit(0); }
try {
let s = fs.readFileSync(p, 'utf8');
if (s.includes('bzcAudioLaunch')) { console.log(' audio launch baseline already patched'); process.exit(0); }
const orig = s;
if (!s.includes('import AVFoundation')) {
if (s.includes('import Capacitor')) s = s.replace('import Capacitor', 'import Capacitor\nimport AVFoundation');
else if (s.includes('import UIKit')) s = s.replace('import UIKit', 'import UIKit\nimport AVFoundation');
}
// NOTE: NO .defaultToSpeaker here. The earpiece<->speaker toggle plugin (mobile/plugins/audio-route) drives
// the output port explicitly and needs .voiceChat's receiver default; .defaultToSpeaker would invert that and
// make earpiece unreachable. This is only a launch-time baseline — WebKit re-pins the session per call anyway.
const launch = [
' // bzcAudioLaunch: baseline voice-call audio session (earpiece-capable; the AudioRoute plugin and',
' // the JS meet UI force the speaker per call). Keep in sync with mobile/plugins/audio-route load().',
' do {',
' let audioSession = AVAudioSession.sharedInstance()',
' try audioSession.setCategory(.playAndRecord, mode: .voiceChat, options: [.allowBluetooth, .allowBluetoothA2DP])',
' try audioSession.setActive(true)',
' } catch { }',
'',
].join('\n');
const m = s.match(/func\s+application\([^)]*didFinishLaunchingWithOptions[^)]*\)\s*->\s*Bool\s*\{[^\n]*\n/);
if (m) { const idx = m.index + m[0].length; s = s.slice(0, idx) + launch + s.slice(idx); }
if (s !== orig && s.includes('bzcAudioLaunch')) { fs.writeFileSync(p, s); console.log(' AVAudioSession launch baseline injected'); }
else { console.log(' (AppDelegate pattern not matched — audio patch skipped)'); }
} catch (e) {
console.log(' (audio patch error, skipped: ' + (e && e.message) + ')');
}
process.exit(0);
+50
View File
@@ -0,0 +1,50 @@
// Inject the APNs registration-forwarding methods into the Capacitor iOS AppDelegate.
// Run on Codemagic (macOS) from ios-patch.sh:
// node mobile/scripts/inject-push.js mobile/ios/App/App/AppDelegate.swift
//
// WHY: Capacitor 7's default AppDelegate.swift template does NOT implement
// application(_:didRegisterForRemoteNotificationsWithDeviceToken:) / ...didFailToRegister...
// so when @capacitor/push-notifications calls registerForRemoteNotifications(), iOS DOES obtain the
// APNs token but the AppDelegate never posts .capacitorDidRegisterForRemoteNotifications — so the plugin
// never delivers the token to JS. register() "succeeds", yet NEITHER the `registration` nor the
// `registrationError` event ever fires (proven via server-side push telemetry: register-called logged,
// no token, no error). These two methods forward the token / error to Capacitor. The plugin listens for
// the notifications defined in @capacitor/ios CAPNotifications.swift; `import Capacitor` (already in the
// AppDelegate) exposes the Notification.Name values.
//
// TOLERANT: exits 0 and no-ops if anything is off, so it can NEVER fail the build. Idempotent (keyed on
// the bzcPushForward marker), so re-runs never duplicate the methods.
const fs = require('fs');
const p = process.argv[2];
if (!p || !fs.existsSync(p)) { console.log(' (AppDelegate.swift not found — push forwarding patch skipped)'); process.exit(0); }
try {
let s = fs.readFileSync(p, 'utf8');
if (s.includes('bzcPushForward') || s.includes('capacitorDidRegisterForRemoteNotifications')) {
console.log(' push forwarding already patched'); process.exit(0);
}
const methods = [
'',
' // bzcPushForward: forward APNs device-token registration to Capacitor. The Capacitor 7 AppDelegate',
' // template omits these, so @capacitor/push-notifications never receives the token without them.',
' func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {',
' NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: deviceToken)',
' }',
'',
' func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {',
' NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)',
' }',
'',
].join('\n');
// Insert the methods just before the final closing brace of the file (which closes the AppDelegate class).
const orig = s;
s = s.replace(/\}\s*$/, methods + '}\n');
if (s !== orig && s.includes('bzcPushForward')) {
fs.writeFileSync(p, s);
console.log(' APNs registration forwarding methods injected into AppDelegate');
} else {
console.log(' (AppDelegate closing brace not matched — push forwarding patch skipped)');
}
} catch (e) {
console.log(' (push forwarding patch error, skipped: ' + (e && e.message) + ')');
}
process.exit(0);
+144
View File
@@ -0,0 +1,144 @@
#!/usr/bin/env bash
# Patch the freshly-generated Capacitor iOS project (mobile/ios/App) for App Store submission.
# Runs on the Codemagic macOS instance after `npx cap add ios`. Idempotent — safe to re-run.
set -euo pipefail
PLIST="mobile/ios/App/App/Info.plist"
PB=/usr/libexec/PlistBuddy
set_str() { # set_str <key> <value> — add the key if missing, else overwrite
"$PB" -c "Add :$1 string $2" "$PLIST" 2>/dev/null || "$PB" -c "Set :$1 $2" "$PLIST"
}
echo "Patching $PLIST"
# ── Privacy usage strings (Apple REJECTS the build if a used capability has no purpose string) ──
set_str NSCameraUsageDescription "Biz Connect uses the camera for video calls and to share photos and your screen."
set_str NSMicrophoneUsageDescription "Biz Connect uses the microphone for voice and video calls."
set_str NSPhotoLibraryUsageDescription "Biz Connect needs photo access so you can send images in chat."
set_str NSPhotoLibraryAddUsageDescription "Biz Connect saves images and recordings you download to your photos."
set_str NSSpeechRecognitionUsageDescription "Biz Connect uses speech recognition to create live meeting transcripts from your microphone."
# Human-readable display name on the home screen.
set_str CFBundleDisplayName "Biz Connect"
# CFBundleVersion (build number) MUST be unique AND higher than every previous App Store Connect upload,
# or publishing fails with "The bundle version must be higher than the previously uploaded version".
# Capacitor ships "1" by default, so every build collided. Use Codemagic's monotonically-increasing
# BUILD_NUMBER (this is build index 6+, already > the "1" that's on TestFlight). Fall back to an epoch
# timestamp if it's somehow unset, which is also strictly increasing.
BUILD_NO="${BUILD_NUMBER:-$(date +%s)}"
echo "Setting CFBundleVersion = $BUILD_NO"
set_str CFBundleVersion "$BUILD_NO"
# ── Make the app's Documents folder visible in the Files app ───────────────────────────────────────
# Downloads are saved to Documents/{Images,Videos,Files}. Without these two keys that folder is private
# and the user has no way to reach what they saved. With them, Files shows
# Files → Browse → On My iPhone → Biz Connect → Images / Videos / Files
# UIFileSharingEnabled exposes the folder; LSSupportsOpeningDocumentsInPlace lets other apps open those
# files in place rather than silently working on a copy.
set_bool() { "$PB" -c "Add :$1 bool $2" "$PLIST" 2>/dev/null || "$PB" -c "Set :$1 $2" "$PLIST"; }
set_bool UIFileSharingEnabled true
set_bool LSSupportsOpeningDocumentsInPlace true
# ── Keep CALL AUDIO alive when the app is BACKGROUNDED (minimised / screen locked) ──────────────────
# Without the 'audio' background mode, iOS suspends the WebView a few seconds after it backgrounds, which
# freezes the WebRTC mic + audio pipeline — so participants can't hear each other once the app is minimised
# or the phone locks. Declaring background audio keeps the audio session (and the app) running so a voice
# call continues in the background. (Video RENDERING still pauses while backgrounded — unavoidable in a
# WebView — but audio keeps flowing, which is what matters for a call.) Idempotent: rebuild the array each run.
# 'audio' keeps the call audio session alive when backgrounded; 'voip' is REQUIRED for PushKit to deliver
# VoIP pushes (CallKit incoming-call wake). Both are legitimate for a calling app and accepted by review
# because the app uses CallKit.
"$PB" -c "Delete :UIBackgroundModes" "$PLIST" 2>/dev/null || true
"$PB" -c "Add :UIBackgroundModes array" "$PLIST"
"$PB" -c "Add :UIBackgroundModes:0 string audio" "$PLIST"
"$PB" -c "Add :UIBackgroundModes:1 string voip" "$PLIST"
echo "UIBackgroundModes: audio, voip (call audio + CallKit VoIP wake)"
# ── Custom URL scheme so the Share Extension can bounce the user back into the app ──────────────────
# The extension stages the shared files into the App Group, then opens bizconnect://share; the app reads
# the staged files and shows "Send to…". Registering the scheme is what makes that openURL succeed.
if ! "$PB" -c "Print :CFBundleURLTypes" "$PLIST" >/dev/null 2>&1; then
"$PB" -c "Add :CFBundleURLTypes array" "$PLIST"
"$PB" -c "Add :CFBundleURLTypes:0 dict" "$PLIST"
"$PB" -c "Add :CFBundleURLTypes:0:CFBundleURLName string com.bizgaze.connect" "$PLIST"
"$PB" -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "$PLIST"
"$PB" -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string bizconnect" "$PLIST"
fi
# ── Push Notifications entitlement (aps-environment) ────────────────────────────────────────────────
# The @capacitor/push-notifications plugin does NOT add the Push Notifications capability to the generated
# Xcode project — in Xcode that's a manual "Signing & Capabilities → + Push Notifications" click, which
# never happens on a fresh CI checkout. Without the aps-environment entitlement, PushNotifications.register()
# fails on device ("no valid 'aps-environment' entitlement string found") and NO APNs token is ever
# obtained, so device_tokens stays empty and the server has nothing to push to. Create the entitlements
# file with aps-environment HERE; add-share-extension.rb (runs after this) MERGES the App Group into the
# same file, preserving this key. REQUIRES: the App ID com.bizgaze.connect must have the Push Notifications
# capability enabled in the Apple Developer portal, so the fetched provisioning profile carries
# aps-environment — otherwise the archive fails code-signing. "production" is correct for App Store +
# TestFlight (pair it with APNS_PRODUCTION=1 on the server).
ENT="mobile/ios/App/App/App.entitlements"
if [ ! -f "$ENT" ]; then
cat > "$ENT" <<'PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
PLIST
fi
"$PB" -c "Add :aps-environment string production" "$ENT" 2>/dev/null || "$PB" -c "Set :aps-environment production" "$ENT"
echo "Entitlements: aps-environment=production ensured in $ENT"
# ── Screen sharing from iOS (ReplayKit broadcast extension + LiveKit) ───────────────────────────────
# LiveKit's BroadcastManager finds the broadcast upload extension + the shared App Group via these two keys
# (BroadcastBundleInfo reads RTCScreenSharingExtension / RTCAppGroupIdentifier). They match the extension
# added by add-broadcast-extension.rb (bundle id <app>.broadcast) and the App Group used by the share
# extension. Set explicitly so there's no reliance on the default-derivation.
set_str RTCScreenSharingExtension "com.bizgaze.connect.broadcast"
set_str RTCAppGroupIdentifier "group.com.bizgaze.connect"
# We use only standard encryption (HTTPS/TLS), which is exempt — declaring this up front stops App Store
# Connect from asking the "export compliance" question on every single build/TestFlight upload.
"$PB" -c "Add :ITSAppUsesNonExemptEncryption bool false" "$PLIST" 2>/dev/null \
|| "$PB" -c "Set :ITSAppUsesNonExemptEncryption false" "$PLIST"
# Allow the webview to load our HTTPS origin (we do NOT enable arbitrary cleartext).
"$PB" -c "Delete :NSAppTransportSecurity" "$PLIST" 2>/dev/null || true
# ── Default in-call audio to the LOUDSPEAKER (AVAudioSession) ──────────────────────────────────────
# Without this, iOS routes WebRTC call audio to the quiet EARPIECE. A Node helper (Node 20 is already set
# up for this build) injects an AVAudioSession category into the generated AppDelegate so calls default to
# the speaker (headphones/Bluetooth still win when connected). The helper is tolerant and exits 0 even if
# the template differs, so it NEVER fails the build. First-pass fix — if WebRTC re-grabs the session
# mid-call on device, we follow up with a plugin that re-asserts .overrideOutputAudioPort(.speaker).
# ── Bundle the custom notification sound so chat/call pushes have an explicit tone ──────────────────
# APNs plays the sound named in the push payload (the server sends sound:'notif.wav'). The file must be a
# resource in the app bundle ROOT; copy it in here — add-share-extension.rb then adds it to the App
# target's "Copy Bundle Resources". iOS accepts a PCM .wav (<30s) for a notification sound.
SND_SRC="mobile/ios-assets/notif.wav"
SND_DST="mobile/ios/App/App/notif.wav"
if [ -f "$SND_SRC" ]; then cp "$SND_SRC" "$SND_DST" && echo "Copied notification sound -> $SND_DST"; else echo " (notif.wav source missing — sound not bundled)"; fi
AD="mobile/ios/App/App/AppDelegate.swift"
if [ -f "$AD" ]; then
echo "Patching AppDelegate audio session"
node "$(dirname "$0")/inject-audio.js" "$AD" || echo " (AVAudioSession patch skipped — non-fatal)"
# Capacitor 7's AppDelegate template omits the APNs registration callbacks, so the push-notifications
# plugin never receives the device token (register() fires no event at all). Inject the forwarding methods.
echo "Patching AppDelegate APNs registration forwarding"
node "$(dirname "$0")/inject-push.js" "$AD" || echo " (push forwarding patch skipped — non-fatal)"
fi
# ── LiveKit under SPM (Capacitor 8) ─────────────────────────────────────────────────────────────────
# LiveKit is now a proper Swift Package Manager dependency declared in the native-call plugin's Package.swift
# (github.com/livekit/client-sdk-swift, exact 2.15.3) — SPM resolves it + its WebRTC/UniFFI/SwiftProtobuf
# sub-packages at build time. So there is NO Podfile to patch here anymore (the old CocoaPods git-tag pin
# hack is gone).
echo "Info.plist patched:"
"$PB" -c "Print :NSCameraUsageDescription" "$PLIST"
"$PB" -c "Print :NSMicrophoneUsageDescription" "$PLIST"
"$PB" -c "Print :NSSpeechRecognitionUsageDescription" "$PLIST"
+25
View File
@@ -0,0 +1,25 @@
<!doctype html>
<!-- Capacitor requires a webDir with an index. At runtime the app loads the live Connect UI
via server.url in capacitor.config.json, so this is only a launch splash / offline
fallback. To ship fully-bundled (offline-launch) later, copy ../server/public here and
drop server.url. -->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Biz Connect</title>
<style>
html,body{height:100%;margin:0;background:#0f1830;color:#fff;font-family:system-ui,Segoe UI,Roboto,sans-serif;}
.wrap{height:100%;display:grid;place-items:center;text-align:center;padding:2rem;}
h1{font-size:1.4rem;margin:.4rem 0;} p{opacity:.7;font-size:.9rem;}
</style>
</head>
<body>
<div class="wrap">
<div>
<h1>Biz <span style="color:#f5b301">Connect</span></h1>
<p>Connecting…</p>
</div>
</div>
</body>
</html>
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/env bash
#
# publish-desktop.sh — publish a desktop installer FROM YOUR LAPTOP (Git Bash).
# It uploads the three electron-builder artifacts to the server and drops them into
# the app container's DOWNLOADS_DIR (/data/downloads), which powers both the site's
# "Download for Windows" button and the auto-update feed for installed apps.
#
# Uploaded artifacts (from desktop/dist/):
# - Biz Connect Setup <ver>.exe the installer
# - Biz Connect Setup <ver>.exe.blockmap differential-update map
# - latest.yml update manifest (the ONLY file overwritten)
#
# It does NOT delete older versions — keeping old .exe/.blockmap lets installed apps
# pull deltas. Only latest.yml is replaced (there must be exactly one, newest wins).
#
# Usage:
# ./publish-desktop.sh # publish the version in desktop/package.json
# ./publish-desktop.sh 0.1.4 # publish a specific version
#
# Password (in priority order), same as redeploy.sh:
# 1. $DEPLOY_PASS environment variable
# 2. a gitignored `deploy.secret` file next to this script (one line = the pw)
# 3. hidden prompt
set -euo pipefail
HOST=118.95.33.89
PORT=61
USER=root
CONTAINER=bizgaze-support
DEST=/data/downloads
# Pinned server host key (SHA256). -batch won't prompt to cache an unknown key, so
# we pin it here (same value as redeploy.sh). Override with $DEPLOY_HOSTKEY if the
# server is rebuilt.
HOSTKEY="${DEPLOY_HOSTKEY:-SHA256:hxfv/hH5aplnM4wOsl+jLjWaXwEeceZ4Uz932/5IoCE}"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DIST="$DIR/desktop/dist"
# Locate plink + pscp (PuTTY).
PLINK="$(command -v plink 2>/dev/null || true)"; [ -n "$PLINK" ] || PLINK="/c/Program Files/PuTTY/plink"
PSCP="$(command -v pscp 2>/dev/null || true)"; [ -n "$PSCP" ] || PSCP="/c/Program Files/PuTTY/pscp"
[ -x "$PLINK" ] || { echo "ERROR: plink not found (install PuTTY or add to PATH)"; exit 1; }
[ -x "$PSCP" ] || { echo "ERROR: pscp not found (install PuTTY or add to PATH)"; exit 1; }
# Resolve the version: explicit arg, else desktop/package.json.
VER="${1:-}"
if [ -z "$VER" ]; then
VER="$(grep -oE '"version"[[:space:]]*:[[:space:]]*"[^"]+"' "$DIR/desktop/package.json" | head -1 | sed -E 's/.*"([^"]+)"$/\1/')"
fi
[ -n "$VER" ] || { echo "ERROR: could not determine version (pass it as an argument)"; exit 1; }
EXE="$DIST/Biz Connect Setup $VER.exe"
MAP="$DIST/Biz Connect Setup $VER.exe.blockmap"
YML="$DIST/latest.yml"
for f in "$EXE" "$MAP" "$YML"; do
[ -f "$f" ] || { echo "ERROR: missing artifact: $f"; echo " build it first: cd desktop && npm run dist"; exit 1; }
done
# Sanity: latest.yml should reference this version, or installed apps won't update to it.
if ! grep -qE "^version:[[:space:]]*$VER([^0-9]|$)" "$YML"; then
echo "WARNING: $YML does not declare version $VER — is dist/ from an older build?"
fi
# Resolve password (same precedence as redeploy.sh).
PW="${DEPLOY_PASS:-}"
if [ -z "$PW" ] && [ -f "$DIR/deploy.secret" ]; then
PW="$(tr -d '\r\n' < "$DIR/deploy.secret")"
fi
if [ -z "$PW" ]; then
read -rsp "Server password for $USER@$HOST: " PW; echo
fi
STAGE="/tmp/bizc-desktop-$VER"
echo "==> Publishing Biz Connect $VER to $USER@$HOST:$CONTAINER:$DEST"
# 1. Stage a clean temp dir on the server.
"$PLINK" -ssh -batch -hostkey "$HOSTKEY" -P "$PORT" -pw "$PW" "$USER@$HOST" "rm -rf '$STAGE' && mkdir -p '$STAGE'"
# 2. Upload the three artifacts into it.
echo "--> uploading installer, blockmap, manifest …"
"$PSCP" -P "$PORT" -pw "$PW" -hostkey "$HOSTKEY" "$EXE" "$MAP" "$YML" "$USER@$HOST:$STAGE/"
# 3. Copy them into the container's DOWNLOADS_DIR (volume-path-independent), then clean up.
# \$f stays literal so the REMOTE shell iterates/quotes the space-containing names.
REMOTE_CMD="set -e; for f in '$STAGE'/*; do docker cp \"\$f\" $CONTAINER:$DEST/; done; echo '--- $DEST now holds ---'; docker exec $CONTAINER ls -la $DEST; rm -rf '$STAGE'"
echo "--> installing into container …"
"$PLINK" -ssh -batch -hostkey "$HOSTKEY" -P "$PORT" -pw "$PW" "$USER@$HOST" "$REMOTE_CMD"
# 4. Verify the public feed actually serves this version (GET, not HEAD — the route is GET-only).
echo "==> Verifying public feed …"
if command -v curl >/dev/null 2>&1; then
echo -n " latest.yml -> "; curl -s "https://remote.bizgaze.com/downloads/latest.yml" | grep -E '^version:' || echo "??"
code="$(curl -s -r 0-1 -o /dev/null -w '%{http_code}' -L "https://remote.bizgaze.com/download/windows")"
echo " /download/windows -> HTTP $code (expect 200 or 206)"
else
echo " (curl not found — skip; check https://remote.bizgaze.com/downloads/latest.yml manually)"
fi
echo "==> Done. Installed 0.x apps will auto-update to $VER on next launch (or within 6h)."
+5 -1
View File
@@ -18,6 +18,10 @@ HOST=118.95.33.89
PORT=61
USER=root
APPDIR=/opt/bizgaze-support
# Pinned server host key (SHA256). plink -batch won't prompt to cache an
# unknown key, so we pin it here. Verify against the fingerprint plink shows
# on first connect. Override with $DEPLOY_HOSTKEY if the server is rebuilt.
HOSTKEY="${DEPLOY_HOSTKEY:-SHA256:hxfv/hH5aplnM4wOsl+jLjWaXwEeceZ4Uz932/5IoCE}"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -36,4 +40,4 @@ if [ -z "$PW" ]; then
fi
echo "==> Triggering deploy on $USER@$HOST ($APPDIR) …"
exec "$PLINK" -ssh -batch -P "$PORT" -pw "$PW" "$USER@$HOST" "cd $APPDIR && bash deploy.sh $*"
exec "$PLINK" -ssh -batch -hostkey "$HOSTKEY" -P "$PORT" -pw "$PW" "$USER@$HOST" "cd $APPDIR && bash deploy.sh $*"
+190 -48
View File
@@ -2,23 +2,26 @@
// ends (with a duration line in the chat) when the last participant's mesh room empties.
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const R = require('./repos');
const A = require('./auth');
const CHAT = require('./chat');
const PUSH = require('./push'); // native push (APNs/FCM/WebPush) so a CLOSED app is notified of calls
const LK = require('./livekit'); // mint the callee's LiveKit join token for the native VoIP call payload
const { TRANS_DIR } = require('./config');
const { meetingRooms, groupCalls, roomToGroupCall, dmCalls, roomToDmCall, roomHost, transcriptBuffers, transcriptSubs } = require('./presence');
const now = () => Date.now();
const pairKey = (a, b) => [a, b].sort().join('|');
// Resolve a room's meeting context (group / scheduled meeting / title) for labelling recordings.
function meetingContext(room) {
async function meetingContext(room) {
const ctx = { groupId: null, meetingId: null, title: 'Meeting' };
try {
const sched = R.scheduledMeetings.byCode(room);
const sched = await R.scheduledMeetings.byCode(room);
if (sched) { ctx.meetingId = sched.id; ctx.groupId = sched.group_id || null; ctx.title = sched.title || 'Meeting'; }
} catch (_) {}
if (!ctx.groupId) { const gid = roomToGroupCall.get(room); if (gid) ctx.groupId = gid; }
if (ctx.groupId && ctx.title === 'Meeting') { try { const g = R.conversations.byId(ctx.groupId); if (g) ctx.title = g.name || 'Group'; } catch (_) {} }
if (ctx.groupId && ctx.title === 'Meeting') { try { const g = await R.conversations.byId(ctx.groupId); if (g) ctx.title = g.name || 'Group'; } catch (_) {} }
if (!ctx.groupId && !ctx.meetingId && roomToDmCall.has(room)) ctx.title = 'Direct Call';
return ctx;
}
@@ -26,118 +29,221 @@ function meetingContext(room) {
// Save the FULL shared conversation transcript as a PRIVATE copy for each subscriber. onlyUserId
// finalizes just that subscriber (on their leave / opt-out); omit to flush all remaining (room end).
// Must run BEFORE endCallByRoom (which clears the room→meeting maps meetingContext relies on).
function finalizeTranscript(room, onlyUserId) {
async function finalizeTranscript(room, onlyUserId) {
const subs = transcriptSubs.get(room); if (!subs || !subs.size) { if (!onlyUserId) { transcriptBuffers.delete(room); transcriptSubs.delete(room); } return; }
const buf = transcriptBuffers.get(room) || [];
const ids = onlyUserId ? (subs.has(onlyUserId) ? [onlyUserId] : []) : [...subs];
// CLAIM the subscriber(s) SYNCHRONOUSLY (before any await). Two concurrent finalize calls for the SAME uid —
// e.g. the same user's two devices both leaving at once (#12 multi-device) — would otherwise both pass the
// membership check during the awaits below and write the transcript TWICE (the "transcript shows two times"
// bug). subs.delete() returns true only for the first caller, so the loser claims nothing and writes nothing.
const candidates = onlyUserId ? (subs.has(onlyUserId) ? [onlyUserId] : []) : [...subs];
const ids = candidates.filter((uid) => subs.delete(uid));
if (ids.length && buf.length) {
const ctx = meetingContext(room);
const ctx = await meetingContext(room);
const lines = buf.map((s) => { const ts = new Date(s.t); const hh = String(ts.getHours()).padStart(2, '0'), mm = String(ts.getMinutes()).padStart(2, '0'); return '[' + hh + ':' + mm + '] ' + s.speaker + ': ' + s.text; });
const body = ctx.title + ' — transcript\n' + new Date(buf[0].t).toLocaleString() + '\n\n' + lines.join('\n') + '\n';
for (const uid of ids) {
let user = null; try { user = R.users.byId(uid); } catch (_) {}
if (!user) { subs.delete(uid); continue; }
let user = null; try { user = await R.users.byId(uid); } catch (_) {}
if (!user) continue;
const id = A.id(); const file = 'm_' + id + '.txt';
try { fs.writeFileSync(path.join(TRANS_DIR, file), body); } catch (e) { continue; }
// groupId null → private to its creator (see canSeeRec / /mrec auth).
R.recordings.create({ id, teamId: user.team_id, room, groupId: null, meetingId: ctx.meetingId, title: ctx.title, kind: 'transcript', file, mime: 'text/plain', size: null, durationMs: null, createdBy: uid, createdByName: user.name || user.email });
subs.delete(uid);
await R.recordings.create({ id, teamId: user.team_id, room, groupId: null, meetingId: ctx.meetingId, title: ctx.title, kind: 'transcript', file, mime: 'text/plain', size: null, durationMs: null, createdBy: uid, createdByName: user.name || user.email });
}
}
} else { ids.forEach((uid) => subs.delete(uid)); }
if (!subs.size) { transcriptBuffers.delete(room); transcriptSubs.delete(room); } // last subscriber done
}
function fmtDur(ms) { const s = Math.max(0, Math.round(ms / 1000)); const m = Math.floor(s / 60); return m ? (m + 'm ' + (s % 60) + 's') : (s + 's'); }
function broadcast(group, evt) { try { for (const mid of R.conversations.members(group)) CHAT.pushToUser(mid, evt); } catch (_) {} }
async function broadcast(group, evt) { try { for (const mid of await R.conversations.members(group)) CHAT.pushToUser(mid, evt); } catch (_) {} }
// Post a centered activity line into the group (system sender → no ping on clients).
function postSystem(group, teamId, text) {
async function postSystem(group, teamId, text) {
const id = A.id();
R.messages.send({ id, teamId, senderId: '__system__', recipientId: '', body: text, conversationId: group });
const m = R.messages.byId(id);
await R.messages.send({ id, teamId, senderId: '__system__', recipientId: '', body: text, conversationId: group });
const m = await R.messages.byId(id);
broadcast(group, { type: 'chat-message', message: { id: m.id, from: '__system__', conversation_id: group, body: m.body, created_at: m.created_at, system: true } });
}
function startGroupCall(group, teamId, user) {
async function startGroupCall(group, teamId, user) {
const existing = groupCalls.get(group);
if (existing) return { room: existing.room, active: true, already: true };
if (existing) return { room: existing.room, uuid: existing.uuid, active: true, already: true };
let room; do { room = A.numericCode(6); } while (meetingRooms.has(room));
meetingRooms.set(room, new Map());
const call = { room, startedAt: now(), startedBy: user.id, startedByName: user.name || user.email };
const call = { room, uuid: crypto.randomUUID(), startedAt: now(), startedBy: user.id, startedByName: user.name || user.email, left: new Set() };
// Log the call as a meeting so it appears under Past meetings (history) with the group name.
try { const hid = A.id(); R.scheduledMeetings.create({ id: hid, teamId, groupId: group, roomCode: room, title: 'Group call', description: null, scheduledAt: now(), createdBy: user.id }); call.historyId = hid; call.teamId = teamId; } catch (_) {}
try { const hid = A.id(); await R.scheduledMeetings.create({ id: hid, teamId, groupId: group, roomCode: room, title: 'Group call', description: null, scheduledAt: now(), createdBy: user.id }); call.historyId = hid; call.teamId = teamId; } catch (_) {}
groupCalls.set(group, call); roomToGroupCall.set(room, group); roomHost.set(room, user.id); // creator = host
postSystem(group, teamId, '📞 ' + call.startedByName + ' started a group call');
let gName = 'Group'; try { const g = R.conversations.byId(group); if (g) gName = g.name || 'Group'; } catch (_) {}
broadcast(group, { type: 'group-call', group, active: true, room, by: user.id, startedByName: call.startedByName, groupName: gName });
return { room, active: true };
postSystem(group, teamId, '📞 ' + call.startedByName + ' started a group call').catch(() => {});
let gName = 'Group'; try { const g = await R.conversations.byId(group); if (g) gName = g.name || 'Group'; } catch (_) {}
broadcast(group, { type: 'group-call', group, active: true, room, uuid: call.uuid, by: user.id, startedByName: call.startedByName, groupName: gName });
// Notify the OTHER members so a closed app is alerted to the group call — VoIP/CallKit if available,
// else a banner. broadcast() above only reaches connected sockets. Best-effort; never throws.
try { for (const mid of await R.conversations.members(group)) { if (mid !== user.id) PUSH.sendCallNotification(mid, { callUUID: call.uuid, room, kind: 'group', groupId: group, groupName: gName, callerId: user.id, callerName: call.startedByName, title: gName, body: '📞 ' + call.startedByName + ' started a group call', hasVideo: true, livekitUrl: LK.LIVEKIT_URL, livekitToken: LK.livekitToken(mid, null, room) }); } } catch (_) {}
return { room, uuid: call.uuid, active: true };
}
// Called from signaling when a mesh room empties — ends the group call if this room was one.
function endGroupCallByRoom(room) {
async function endGroupCallByRoom(room) {
const group = roomToGroupCall.get(room);
if (!group) return;
const call = groupCalls.get(group);
roomToGroupCall.delete(room); groupCalls.delete(group); roomHost.delete(room);
if (call) {
let teamId = call.teamId; try { const g = R.conversations.byId(group); if (g) { teamId = g.team_id; postSystem(group, g.team_id, '📞 Group call ended · ' + fmtDur(now() - call.startedAt)); } } catch (_) {}
if (call.historyId && teamId) { try { R.scheduledMeetings.end(call.historyId, teamId); } catch (_) {} } // mark the history row past
broadcast(group, { type: 'group-call', group, active: false, room });
let teamId = call.teamId; try { const g = await R.conversations.byId(group); if (g) { teamId = g.team_id; postSystem(group, g.team_id, '📞 Group call ended · ' + fmtDur(now() - call.startedAt)).catch(() => {}); } } catch (_) {}
if (call.historyId && teamId) { try { await R.scheduledMeetings.end(call.historyId, teamId); } catch (_) {} } // mark the history row past
broadcast(group, { type: 'group-call', group, active: false, room, uuid: call.uuid });
// Stop any CallKit ring on members' killed/backgrounded devices.
try { for (const mid of await R.conversations.members(group)) { if (mid !== call.startedBy) PUSH.sendCallCancel(mid, call.uuid); } } catch (_) {} // not the starter — a cancel to them re-rings their own phone
}
}
// 1:1 (DM) call. Notifies both parties (state + a chat line) so the callee sees "Join".
function startDmCall(me, otherId, teamId) {
async function startDmCall(me, otherId, teamId) {
const key = pairKey(me.id, otherId);
const existing = dmCalls.get(key);
if (existing) return { room: existing.room, active: true, already: true };
if (existing) return { room: existing.room, uuid: existing.uuid, active: true, already: true };
let room; do { room = A.numericCode(6); } while (meetingRooms.has(room));
meetingRooms.set(room, new Map());
const byName = me.name || me.email;
const call = { room, startedAt: now(), startedBy: me.id, startedByName: byName, users: [me.id, otherId], teamId };
const call = { room, uuid: crypto.randomUUID(), startedAt: now(), startedBy: me.id, startedByName: byName, users: [me.id, otherId], teamId, answered: false, left: new Set() };
// Log to history (both participants) so the call shows under Past meetings with its transcript.
try { const hid = A.id(); R.scheduledMeetings.create({ id: hid, teamId, groupId: null, roomCode: room, title: 'Direct Call', description: null, scheduledAt: now(), createdBy: me.id, participants: [me.id, otherId] }); call.historyId = hid; } catch (_) {}
try { const hid = A.id(); await R.scheduledMeetings.create({ id: hid, teamId, groupId: null, roomCode: room, title: 'Direct Call', description: null, scheduledAt: now(), createdBy: me.id, participants: [me.id, otherId] }); call.historyId = hid; } catch (_) {}
dmCalls.set(key, call); roomToDmCall.set(room, key); roomHost.set(room, me.id); // caller = host
// #9 (unanswered): if the callee never joins within the ring window, auto-end and mark it missed —
// so the caller isn't stuck "ringing" forever.
call.ringTimer = setTimeout(() => {
if (call.answered) return;
const peers = meetingRooms.get(room);
if (peers) { for (const [, p] of peers) { if (p.ws && p.ws.readyState === 1) { try { p.ws.send(JSON.stringify({ type: 'meeting-ended', reason: 'unanswered' })); } catch (_) {} p.ws._meetingRoom = null; } } meetingRooms.delete(room); }
endDmCallByRoom(room);
}, 40000);
// A viewer-relative activity line: the caller sees "You started a call", the callee sees the name.
const mid = A.id();
R.messages.send({ id: mid, teamId, senderId: me.id, recipientId: otherId, body: '📞 Started a call', msgType: 'call-start' });
const m = R.messages.byId(mid); const dto = { id: m.id, from: me.id, to: otherId, conversation_id: null, body: m.body, created_at: m.created_at, system: true, evt: 'call-start', byName };
await R.messages.send({ id: mid, teamId, senderId: me.id, recipientId: otherId, body: '📞 Started a call', msgType: 'call-start' });
const m = await R.messages.byId(mid); const dto = { id: m.id, from: me.id, to: otherId, conversation_id: null, body: m.body, created_at: m.created_at, system: true, evt: 'call-start', byName };
try { CHAT.pushToUser(otherId, { type: 'chat-message', message: dto }); } catch (_) {}
try { CHAT.pushToUser(me.id, { type: 'chat-message', message: dto }); } catch (_) {}
try { CHAT.pushToUser(otherId, { type: 'dm-call', active: true, room, with: me.id, by: me.id, byName }); } catch (_) {}
try { CHAT.pushToUser(me.id, { type: 'dm-call', active: true, room, with: otherId, by: me.id, byName }); } catch (_) {}
return { room, active: true };
try { CHAT.pushToUser(otherId, { type: 'dm-call', active: true, room, uuid: call.uuid, with: me.id, by: me.id, byName }); } catch (_) {}
try { CHAT.pushToUser(me.id, { type: 'dm-call', active: true, room, uuid: call.uuid, with: otherId, by: me.id, byName }); } catch (_) {}
// Notify the callee so a CLOSED app still rings — VoIP/CallKit if the device registered a VoIP token,
// else a banner (the CHAT.pushToUser events above only reach a connected socket). Best-effort. On
// reconnect the callee's app also re-shows the invite (replayActiveCalls), so answering works either way.
try { PUSH.sendCallNotification(otherId, { callUUID: call.uuid, room, kind: 'dm', callerId: me.id, callerName: byName, title: byName, body: '📞 Incoming call', hasVideo: false, livekitUrl: LK.LIVEKIT_URL, livekitToken: LK.livekitToken(otherId, null, room) }); } catch (_) {}
return { room, uuid: call.uuid, active: true };
}
function endDmCallByRoom(room, silent) {
async function endDmCallByRoom(room, silent) {
const key = roomToDmCall.get(room); if (!key) return;
const call = dmCalls.get(key);
roomToDmCall.delete(room); dmCalls.delete(key); roomHost.delete(room);
if (!call) return;
if (call.historyId && call.teamId) { try { R.scheduledMeetings.end(call.historyId, call.teamId); } catch (_) {} } // mark history past
// "Call ended · duration" activity line in the DM (shown to both) — skipped on decline.
if (call.ringTimer) { try { clearTimeout(call.ringTimer); } catch (_) {} }
if (call.historyId && call.teamId) { try { await R.scheduledMeetings.end(call.historyId, call.teamId); } catch (_) {} } // mark history past
// A native side that ends the call (POST /api/calls/end) may have a dropped WebSocket, so the OTHER party
// can be left sitting in the mesh meeting "still in the call". Close their window. Idempotent: when this
// runs from the mesh emptying normally, the room is already gone → no-op (so it never double-ends).
const stuck = meetingRooms.get(room);
if (stuck) { for (const [, p] of stuck) { if (p.ws && p.ws.readyState === 1) { try { p.ws.send(JSON.stringify({ type: 'meeting-ended' })); } catch (_) {} p.ws._meetingRoom = null; } } meetingRooms.delete(room); }
// Activity line: a duration ONLY if the call was answered; otherwise "Missed call" (#7/#9).
if (!silent) try {
const mid = A.id(); const body = '📞 Call ended · ' + fmtDur(now() - call.startedAt);
R.messages.send({ id: mid, teamId: call.teamId, senderId: call.startedBy, recipientId: call.users.find((u) => u !== call.startedBy) || '', body, msgType: 'call-end' });
const m = R.messages.byId(mid); const dto = { id: m.id, from: call.startedBy, to: m.recipient_id, conversation_id: null, body, created_at: m.created_at, system: true, evt: 'call-end' };
const mid = A.id(); const body = call.answered ? ('📞 Call ended · ' + fmtDur(now() - (call.answeredAt || call.startedAt))) : '📞 Missed call';
await R.messages.send({ id: mid, teamId: call.teamId, senderId: call.startedBy, recipientId: call.users.find((u) => u !== call.startedBy) || '', body, msgType: 'call-end' });
const m = await R.messages.byId(mid); const dto = { id: m.id, from: call.startedBy, to: m.recipient_id, conversation_id: null, body, created_at: m.created_at, system: true, evt: 'call-end' };
call.users.forEach((uid) => { try { CHAT.pushToUser(uid, { type: 'chat-message', message: dto }); } catch (_) {} });
} catch (_) {}
call.users.forEach((uid, i) => { try { CHAT.pushToUser(uid, { type: 'dm-call', active: false, with: call.users[1 - i], room }); } catch (_) {} });
call.users.forEach((uid, i) => { try { CHAT.pushToUser(uid, { type: 'dm-call', active: false, uuid: call.uuid, with: call.users[1 - i], room }); } catch (_) {} });
// Stop the CallKit ring on a device that's still RINGING (unanswered) — a killed/asleep callee has no WS
// to receive the dm-call above. For an ANSWERED call both sides are awake (the WS event ends it), and a
// cancel push would re-ring the device that just hung up — so only cancel when it was NOT answered.
// Cancel the ring ONLY on the CALLEE's device(s) — never the caller (startedBy). The caller is placing the
// call, not ringing, so a cancel push to them made their OWN phone re-ring after they hung up an unanswered
// outgoing call (the plugin must reportNewIncomingCall for every VoIP push → a phantom ring on the caller).
if (!call.answered) { const callee = call.users.find((u) => u !== call.startedBy); if (callee) { try { PUSH.sendCallCancel(callee, call.uuid); } catch (_) {} } }
// Missed-call banner to the callee (a plain notification, like a phone's missed call) when the call ended
// UNANSWERED — timeout or the caller hung up before pickup. Skipped on decline (silent): they chose to.
if (!silent && !call.answered) {
const callee = call.users.find((u) => u !== call.startedBy);
if (callee) { try { PUSH.sendToUser(callee, { title: call.startedByName || 'Missed call', body: '📞 Missed call', kind: 'dm', id: call.startedBy, tag: 'missed:' + room, data: { kind: 'dm', id: call.startedBy } }); } catch (_) {} }
}
}
// Mark a 1:1 call answered when the callee (anyone other than the caller) joins its room, so the end
// message shows a real duration (from answer) and the unanswered timeout stands down.
function markDmAnswered(room, userId) {
const key = roomToDmCall.get(room); if (!key) return;
const call = dmCalls.get(key); if (!call) return;
if (userId && userId !== call.startedBy && !call.answered) {
call.answered = true; call.answeredAt = now();
if (call.ringTimer) { try { clearTimeout(call.ringTimer); } catch (_) {} call.ringTimer = null; }
// Native calls carry media over LiveKit, not our mesh — so the callee's OTHER devices never learn the
// call was picked up here and keep ringing forever (and dismissing that stale ring as a "decline" would
// tear down THIS live call). Tell them it was taken (dismiss the ring, no teardown), and flip the
// caller's UI from "ringing" to "connected".
try { CHAT.pushToUser(userId, { type: 'call-taken', room, uuid: call.uuid }); } catch (_) {}
try { CHAT.pushToUser(call.startedBy, { type: 'call-answered', room, uuid: call.uuid, by: userId }); } catch (_) {}
}
}
// When a user's chat socket (re)connects, re-send any call they're currently being rung into. The
// original dm-call / group-call events fire ONCE at call start, so an app that was closed then misses
// them. This makes the call PUSH actionable: tapping the banner opens the app, the socket connects, and
// the invite re-appears so they can answer (while the caller is still within the ring window). Sends only
// to the freshly-connected socket. Best-effort; never throws.
async function replayActiveCalls(userId, ws) {
if (!userId || !ws || ws.readyState !== 1) return;
try {
for (const [, call] of dmCalls) {
if (call.answered) continue;
if (call.users.includes(userId) && call.startedBy !== userId) {
// #New1: if this user already LEFT the call, don't ring them back in (noRing) — just refresh the "Join" state.
const noRing = !!(call.left && call.left.has(userId));
try { ws.send(JSON.stringify({ type: 'dm-call', active: true, room: call.room, uuid: call.uuid, with: call.startedBy, by: call.startedBy, byName: call.startedByName, noRing })); } catch (_) {}
}
}
for (const [group, call] of groupCalls) {
if (call.startedBy === userId) continue;
let member = false; try { member = await R.conversations.isMember(group, userId); } catch (_) {}
if (!member) continue;
let gName = 'Group'; try { const g = await R.conversations.byId(group); if (g) gName = g.name || 'Group'; } catch (_) {}
const noRing = !!(call.left && call.left.has(userId)); // #New1: left already → refresh Join, don't re-ring
try { ws.send(JSON.stringify({ type: 'group-call', group, active: true, room: call.room, uuid: call.uuid, by: call.startedBy, startedByName: call.startedByName, groupName: gName, noRing })); } catch (_) {}
}
} catch (_) {}
}
// #New1: a participant who EXPLICITLY leaves an active (still-running) call must not be auto-rung back into
// it. We remember who left per call; replayActiveCalls (on their next socket reconnect) then sends the call
// state with noRing:true so their client refreshes the passive "Join" affordance without ringing / popping
// CallKit again. Before this, every reconnect (constant on mobile) re-rang the leaver until the call ended.
function callForRoom(room) {
const gid = roomToGroupCall.get(room); if (gid) { const c = groupCalls.get(gid); if (c) return c; }
const key = roomToDmCall.get(room); if (key) { const c = dmCalls.get(key); if (c) return c; }
return null;
}
function markLeft(room, userId) { if (!userId) return; const c = callForRoom(room); if (c) { if (!c.left) c.left = new Set(); c.left.add(userId); } }
function clearLeft(room, ids) { const c = callForRoom(room); if (c && c.left) { for (const id of (ids || [])) c.left.delete(id); } } // an explicit re-invite should ring again
// Called from signaling when any mesh room empties.
function endCallByRoom(room) { endGroupCallByRoom(room); endDmCallByRoom(room); }
async function endCallByRoom(room) { await endGroupCallByRoom(room); await endDmCallByRoom(room); }
// Callee declines a 1:1 call: post "Call declined" into the DM, drop the waiting caller, end it.
function declineDmCall(room, byUser) {
async function declineDmCall(room, byUser) {
const key = roomToDmCall.get(room); if (!key) return { ok: false };
const call = dmCalls.get(key); if (!call) return { ok: false };
// Already ANSWERED (e.g. a native CallKit pickup on this user's other device, which bypasses our mesh so
// the check below can't see it): a "decline" here is just the stale ring on a second device — dismiss it,
// do NOT tear down the live call.
if (call.answered && byUser.id !== call.startedBy) return { ok: true, alreadyAnswered: true };
// #8: if this user has ALREADY accepted on another device (they're in the room), this is just the
// ringing invite on a second device — dismiss it silently, do NOT tear down the active call.
const inRoom = meetingRooms.get(room);
if (inRoom) { for (const [, p] of inRoom) { if (p.ws && p.ws._meetingUserId === byUser.id) return { ok: true, alreadyJoined: true }; } }
const callerId = call.users.find((id) => id !== byUser.id) || call.startedBy;
try {
const mid = A.id();
R.messages.send({ id: mid, teamId: byUser.team_id, senderId: byUser.id, recipientId: callerId, body: '📞 Call declined', msgType: 'call-end' });
const mm = R.messages.byId(mid); const dto = { id: mm.id, from: byUser.id, to: callerId, conversation_id: null, body: mm.body, created_at: mm.created_at, system: true, evt: 'call-end' };
await R.messages.send({ id: mid, teamId: byUser.team_id, senderId: byUser.id, recipientId: callerId, body: '📞 Call declined', msgType: 'call-end' });
const mm = await R.messages.byId(mid); const dto = { id: mm.id, from: byUser.id, to: callerId, conversation_id: null, body: mm.body, created_at: mm.created_at, system: true, evt: 'call-end' };
CHAT.pushToUser(callerId, { type: 'chat-message', message: dto });
CHAT.pushToUser(byUser.id, { type: 'chat-message', message: dto });
} catch (_) {}
@@ -148,4 +254,40 @@ function declineDmCall(room, byUser) {
return { ok: true };
}
module.exports = { startGroupCall, startDmCall, endGroupCallByRoom, endDmCallByRoom, endCallByRoom, declineDmCall, finalizeTranscript, meetingContext, fmtDur, pairKey };
// #15: adding a 3rd person to a 1:1 (DM) call turns it into a real, PERSISTENT group call. Two wins:
// (1) the call now survives anyone leaving (a group call only ends when the room empties), and
// (2) an added person who drops can rejoin — they're a group member, so the group's active-call banner
// (replayActiveCalls / group-call) reappears for them.
// The SAME room/uuid/startedAt are kept, so live media + the transcript continue uninterrupted; we just move
// the room's bookkeeping from dmCalls → groupCalls and create the backing group conversation. Returns the new
// group id, or null when `room` isn't a DM call (a group/ad-hoc call needs no promotion — caller invites as usual).
async function promoteDmToGroup(room, inviter, inviteeIds) {
const key = roomToDmCall.get(room); if (!key) return null;
const call = dmCalls.get(key); if (!call) return null;
const teamId = call.teamId || (inviter && inviter.team_id);
const memberIds = [...new Set([...(call.users || []), ...(inviteeIds || [])])].filter(Boolean);
if (memberIds.length < 3) return null; // nothing new actually added → stay a 1:1
// Friendly name from participant first-names (e.g. "Ravi, Sara, Alex"), capped so it doesn't run long.
const names = [];
for (const uid of memberIds) { let usr = null; try { usr = await R.users.byId(uid); } catch (_) {} if (usr) names.push(((usr.name || usr.email || '').trim().split(/\s+/)[0]) || usr.email || 'Someone'); }
const groupName = (names.slice(0, 4).join(', ') + (names.length > 4 ? ' +' + (names.length - 4) : '')) || 'Group call';
const owner = call.startedBy || (inviter && inviter.id);
const gid = A.id();
await R.conversations.create({ id: gid, teamId, name: groupName, createdBy: owner });
for (const uid of memberIds) { try { await R.conversations.addMember(gid, uid, uid === owner); } catch (_) {} }
// Migrate the LIVE call: DM → group (same room/uuid/history so media, transcript and Past-meetings all continue).
if (call.ringTimer) { try { clearTimeout(call.ringTimer); } catch (_) {} call.ringTimer = null; }
dmCalls.delete(key); roomToDmCall.delete(room);
groupCalls.set(gid, { room, uuid: call.uuid, startedAt: call.startedAt, startedBy: owner, startedByName: call.startedByName, teamId, historyId: call.historyId, left: new Set() });
roomToGroupCall.set(room, gid);
postSystem(gid, teamId, '📞 ' + (call.startedByName || 'Someone') + ' turned this into a group call').catch(() => {});
// Tell every member's client: refresh the sidebar (the new group appears) and mark the call active (banner
// + ring the people not already in the room). Those already in the call ignore the ring (same room).
for (const uid of memberIds) {
try { CHAT.pushToUser(uid, { type: 'group-update', group: gid }); } catch (_) {}
try { CHAT.pushToUser(uid, { type: 'group-call', group: gid, active: true, room, uuid: call.uuid, by: owner, startedByName: call.startedByName, groupName }); } catch (_) {}
}
return gid;
}
module.exports = { startGroupCall, startDmCall, endGroupCallByRoom, endDmCallByRoom, endCallByRoom, declineDmCall, markDmAnswered, replayActiveCalls, promoteDmToGroup, markLeft, clearLeft, finalizeTranscript, meetingContext, fmtDur, pairKey };
+69 -10
View File
@@ -1,19 +1,39 @@
// Chat presence + real-time delivery. A logged-in user opens a WebSocket and sends
// `chat-hello`; signaling.js registers the socket here. Messages are persisted over HTTP
// (routes.js) and pushed live to the recipient's sockets via pushToUser().
const { chatClients } = require('./presence');
// Chat presence + real-time delivery. A logged-in user opens a WebSocket and sends `chat-hello`;
// signaling.js registers the socket here. Messages are persisted over HTTP (routes.js) and pushed live to
// the recipient's sockets via pushToUser().
//
// MULTI-INSTANCE: local delivery (to sockets on THIS process) is unchanged. Every push is ALSO published
// via the swappable pubsub layer so, when >1 instance runs, a recipient connected to another instance
// still gets it. With the default in-memory pubsub (single instance) publish is a no-op, so this is
// behaviourally identical to before — no hot-path cost.
const { chatClients, meetingRooms } = require('./presence');
const pubsub = require('./pubsub');
let _repos = null; const repos = () => (_repos || (_repos = require('./repos'))); // lazy: avoid a require cycle
// Deliver an already-built or plain object to a user's sockets on THIS instance.
function deliverLocal(userId, obj) {
const s = chatClients.get(userId);
if (!s) return;
const data = typeof obj === 'string' ? obj : JSON.stringify(obj);
for (const ws of s) { if (ws.readyState === 1) { try { ws.send(data); } catch (_) {} } }
}
function register(userId, ws) {
if (!chatClients.has(userId)) chatClients.set(userId, new Set());
chatClients.get(userId).add(ws);
ws._chatUserId = userId;
repos().users.touchSeen(userId).catch(() => {}); // "last seen" (#2) — fire-and-forget UPDATE
}
function unregister(ws) {
const id = ws && ws._chatUserId;
if (!id) return;
const set = chatClients.get(id);
if (set) { set.delete(ws); if (!set.size) chatClients.delete(id); }
if (set) {
set.delete(ws);
// Their LAST socket went away → stamp when they were last here, so contacts can show "last seen …".
if (!set.size) { chatClients.delete(id); repos().users.touchSeen(id).catch(() => {}); }
}
}
function isOnline(userId) {
@@ -22,10 +42,49 @@ function isOnline(userId) {
}
function pushToUser(userId, obj) {
const s = chatClients.get(userId);
if (!s) return;
const data = JSON.stringify(obj);
for (const ws of s) { if (ws.readyState === 1) { try { ws.send(data); } catch (_) {} } }
deliverLocal(userId, obj); // sockets on this instance
pubsub.publish('u:' + userId, obj); // other instances (no-op on the memory backend)
}
module.exports = { register, unregister, isOnline, pushToUser };
// --- Live presence -------------------------------------------------------------------------
// A user's effective status (online / in-a-call / away / …) changes with no HTTP round-trip: they connect
// or disconnect a socket, or join/leave a call. Without pushing that change, OTHER users only see it after
// a full page reload — impossible in the desktop/mobile apps. So whenever it changes we broadcast the
// user's fresh status to everyone else's sockets, and the client updates that contact's dot/subtitle.
function isInCall(userId) {
for (const [, peers] of meetingRooms) { for (const [, p] of peers) { if (p.ws && p.ws._meetingUserId === userId) return true; } }
return false;
}
async function effectiveStatus(userId) {
if (isInCall(userId)) return 'incall'; // derived (overrides the stored status)
try { const u = await repos().users.byId(userId); return (u && u.status) || 'active'; } catch (_) { return 'active'; }
}
// Send a presence payload to every local socket EXCEPT the subject's own.
function deliverPresenceLocal(subjectId, payload) {
for (const [uid, set] of chatClients) {
if (uid === subjectId) continue;
for (const ws of set) { if (ws.readyState === 1) { try { ws.send(payload); } catch (_) {} } }
}
}
async function broadcastPresence(userId) {
if (!userId) return;
// Carry last_seen too, so a contact going offline immediately reads "Last seen just now" instead of a
// bare "Offline" until the next sidebar reload (#2).
const online = isOnline(userId);
let lastSeen = null;
try { const u = await repos().users.byId(userId); lastSeen = (u && u.last_seen) || null; } catch (_) {}
// #8: never broadcast a NULL last-seen for someone who's offline — touchSeen() is fire-and-forget on
// disconnect, so the DB write can lag this broadcast and the client would flap to a bare "Offline". They're
// leaving now, so "just now" is accurate.
if (!lastSeen && !online) lastSeen = Date.now();
const payload = JSON.stringify({ type: 'presence', userId, online, status: await effectiveStatus(userId), lastSeen });
deliverPresenceLocal(userId, payload); // this instance
pubsub.publish('presence', { userId, payload }); // other instances (no-op on memory)
}
// Cross-instance inbound: deliver events published by OTHER instances to our local sockets. On the memory
// backend these never fire; on redis they carry the fan-out. (Buffered until pubsub.init() connects.)
pubsub.subscribe('u:*', (channel, obj) => deliverLocal(channel.slice(2), obj));
pubsub.subscribe('presence', (channel, msg) => { if (msg && msg.payload) deliverPresenceLocal(msg.userId, msg.payload); });
module.exports = { register, unregister, isOnline, pushToUser, broadcastPresence };
+60 -4
View File
@@ -3,20 +3,76 @@ const fs = require('fs');
const path = require('path');
const PUBLIC_DIR = path.join(__dirname, 'public');
const REC_DIR = path.join(__dirname, 'recordings');
const TRANS_DIR = path.join(__dirname, 'transcripts');
const UPLOADS_DIR = path.join(__dirname, 'uploads');
// Uploaded chat files, recordings and transcripts MUST live on the persistent volume (like the DB
// and downloads). With the old in-image path, every deploy.sh rebuild wiped them — old images/files
// then 404 ("broken image") while their DB rows survive. Overridable so prod points them at /data.
const REC_DIR = process.env.REC_DIR || path.join(__dirname, 'recordings');
const TRANS_DIR = process.env.TRANS_DIR || path.join(__dirname, 'transcripts');
const UPLOADS_DIR = process.env.UPLOADS_DIR || path.join(__dirname, 'uploads');
// Desktop installers + auto-update feed (latest.yml). Override with DOWNLOADS_DIR to point at a
// mounted volume in production; IT drops the electron-builder dist/ output here.
const DOWNLOADS_DIR = process.env.DOWNLOADS_DIR || path.join(__dirname, 'downloads');
try { fs.mkdirSync(REC_DIR, { recursive: true }); } catch (e) {}
try { fs.mkdirSync(TRANS_DIR, { recursive: true }); } catch (e) {}
try { fs.mkdirSync(UPLOADS_DIR, { recursive: true }); } catch (e) {}
try { fs.mkdirSync(DOWNLOADS_DIR, { recursive: true }); } catch (e) {}
// LiveKit SFU (scales meetings past the ~5-peer mesh ceiling). Entirely optional and config-gated:
// when LIVEKIT_URL/API_KEY/API_SECRET are all set the client uses LiveKit for meeting media; when
// they're unset the app falls back to the built-in P2P mesh, unchanged. The API secret is used
// ONLY server-side to mint per-user join tokens — it never reaches the browser.
const LIVEKIT_URL = process.env.LIVEKIT_URL || ''; // wss://livekit.bizgaze.com
const LIVEKIT_API_KEY = process.env.LIVEKIT_API_KEY || '';
const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET || '';
const LIVEKIT_ENABLED = !!(LIVEKIT_URL && LIVEKIT_API_KEY && LIVEKIT_API_SECRET);
// SMTP for outbound email (meeting invites to external participants, #4). Entirely optional and
// config-gated: email is only sent when SMTP_HOST/USER/PASS are set. Credentials stay server-side.
// PUBLIC_BASE_URL is the origin used to build guest meeting links in emails (e.g. https://remote.bizgaze.com).
const SMTP_HOST = process.env.SMTP_HOST || '';
const SMTP_PORT = Number(process.env.SMTP_PORT || 587);
const SMTP_SECURE = String(process.env.SMTP_SECURE || '').toLowerCase() === 'true' || SMTP_PORT === 465; // TLS on connect (465) vs STARTTLS
const SMTP_USER = process.env.SMTP_USER || '';
const SMTP_PASS = process.env.SMTP_PASS || '';
const SMTP_FROM = process.env.SMTP_FROM || (SMTP_USER ? ('Biz Connect <' + SMTP_USER + '>') : '');
const SMTP_ENABLED = !!(SMTP_HOST && SMTP_USER && SMTP_PASS);
const PUBLIC_BASE_URL = (process.env.PUBLIC_BASE_URL || 'https://remote.bizgaze.com').replace(/\/+$/, '');
// GIPHY GIF search (#5). Key is read from the server env only and never sent to the browser — the client
// calls our /api/gifs proxy. GIF picker is hidden when this isn't configured.
const GIPHY_API_KEY = process.env.GIPHY_API_KEY || '';
// Native CallKit / PushKit VoIP calling (iOS). Config-gated so it can be flipped WITHOUT an app rebuild:
// OFF (default) → calls use the WebView flow (works today); ON → iOS rings via CallKit + a VoIP push.
// Only turn ON once native LiveKit media carries the call audio — a CallKit call reserves the mic, so the
// WebView's WebRTC can't capture it (mic dead). Set CALLKIT_ENABLED=1 in the server .env to enable.
const CALLKIT_ENABLED = process.env.CALLKIT_ENABLED === '1';
module.exports = {
PORT: process.env.PORT || 8090,
HTTPS_PORT: process.env.HTTPS_PORT || 8443,
LIVEKIT_URL,
LIVEKIT_API_KEY,
LIVEKIT_API_SECRET,
LIVEKIT_ENABLED,
SMTP_HOST,
SMTP_PORT,
SMTP_SECURE,
SMTP_USER,
SMTP_PASS,
SMTP_FROM,
SMTP_ENABLED,
PUBLIC_BASE_URL,
GIPHY_API_KEY,
CALLKIT_ENABLED,
PUBLIC_DIR,
REC_DIR,
TRANS_DIR,
UPLOADS_DIR,
SESSION_TTL: 1000 * 60 * 60 * 24, // 24h access-token / cookie lifetime
DOWNLOADS_DIR,
// Access-token / web-cookie lifetime. Long by design + SLID FORWARD on every /api/me (app load / focus /
// heartbeat), so an actively-used session never lapses — you only get logged out by choosing to log out.
// (Was 24h, which logged people out overnight.)
SESSION_TTL: 1000 * 60 * 60 * 24 * 90, // 90d
REFRESH_TTL: 1000 * 60 * 60 * 24 * 90, // 90d refresh-token lifetime (native clients)
};
-290
View File
@@ -1,290 +0,0 @@
// SQLite data layer + schema.
// Uses Node's built-in node:sqlite (no native compilation needed).
const { DatabaseSync } = require('node:sqlite');
const path = require('path');
const db = new DatabaseSync(process.env.DB_PATH || path.join(__dirname, 'data.db'));
// WAL is preferred but unsupported on some mounted/network filesystems; fall back quietly.
try { db.exec('PRAGMA journal_mode = WAL'); } catch { /* default rollback journal is fine */ }
db.exec('PRAGMA foreign_keys = ON');
db.exec(`
CREATE TABLE IF NOT EXISTS teams (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
created_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL REFERENCES teams(id),
email TEXT NOT NULL UNIQUE,
pw_hash TEXT NOT NULL,
pw_salt TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'technician',
mfa_secret TEXT,
mfa_enabled INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS sessions_auth (
token TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id),
mfa_passed INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS machines (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL REFERENCES teams(id),
name TEXT NOT NULL,
enroll_token TEXT NOT NULL UNIQUE,
unattended INTEGER NOT NULL DEFAULT 0,
last_seen INTEGER,
created_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS audit_log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
team_id TEXT NOT NULL,
user_id TEXT,
user_email TEXT,
machine_id TEXT,
machine_name TEXT,
action TEXT NOT NULL,
detail TEXT,
at INTEGER NOT NULL
);
`);
// Migration: optional display name for agents (shown to customers on consent)
try { db.exec('ALTER TABLE users ADD COLUMN name TEXT'); } catch (e) { /* already exists */ }
// Migration: agent active flag (deactivate without deleting)
try { db.exec('ALTER TABLE users ADD COLUMN active INTEGER NOT NULL DEFAULT 1'); } catch (e) { /* exists */ }
// Session report: one row per support session with duration
db.exec(`
CREATE TABLE IF NOT EXISTS sessions_log (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
agent_email TEXT,
agent_name TEXT,
ticket TEXT,
started_at INTEGER NOT NULL,
ended_at INTEGER
);
`);
// Migration: stored recording filename for a session (null if not recorded)
try { db.exec('ALTER TABLE sessions_log ADD COLUMN recording TEXT'); } catch (e) { /* exists */ }
try { db.exec('ALTER TABLE sessions_log ADD COLUMN transcript TEXT'); } catch (e) { /* exists */ }
// Refresh tokens for native (desktop/mobile) clients: long-lived, rotated on use,
// stored as a SHA-256 hash so a DB leak doesn't expose usable tokens.
db.exec(`
CREATE TABLE IF NOT EXISTS refresh_tokens (
token_hash TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
revoked INTEGER NOT NULL DEFAULT 0
);
`);
// API keys for third-party / system integrations (machine-to-machine, no human login).
// Scoped per tenant; the key is stored as a SHA-256 hash (plaintext shown once at creation).
db.exec(`
CREATE TABLE IF NOT EXISTS api_keys (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
name TEXT,
key_hash TEXT NOT NULL UNIQUE,
scopes TEXT NOT NULL DEFAULT '',
created_by TEXT,
created_at INTEGER NOT NULL,
last_used_at INTEGER,
revoked INTEGER NOT NULL DEFAULT 0
);
`);
// Outbound webhook subscriptions: per-tenant endpoints that receive signed event
// callbacks (session.started / session.ended). Each has its own signing secret.
db.exec(`
CREATE TABLE IF NOT EXISTS webhooks (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
url TEXT NOT NULL,
secret TEXT NOT NULL,
events TEXT NOT NULL DEFAULT '',
active INTEGER NOT NULL DEFAULT 1,
created_by TEXT,
created_at INTEGER NOT NULL,
last_status INTEGER,
last_error TEXT,
last_at INTEGER
);
`);
// Persistent 1:1 chat between users in the same team.
db.exec(`
CREATE TABLE IF NOT EXISTS messages (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
sender_id TEXT NOT NULL,
recipient_id TEXT NOT NULL,
body TEXT NOT NULL,
created_at INTEGER NOT NULL,
read_at INTEGER
);
CREATE INDEX IF NOT EXISTS idx_messages_pair ON messages(team_id, sender_id, recipient_id, created_at);
CREATE INDEX IF NOT EXISTS idx_messages_unread ON messages(team_id, recipient_id, sender_id, read_at);
`);
// Migration: a message can quote/reply to another message.
try { db.exec('ALTER TABLE messages ADD COLUMN reply_to TEXT'); } catch (e) { /* exists */ }
// Emoji reactions on messages (one row per user+message+emoji; toggling adds/removes).
db.exec(`
CREATE TABLE IF NOT EXISTS message_reactions (
message_id TEXT NOT NULL,
user_id TEXT NOT NULL,
emoji TEXT NOT NULL,
created_at INTEGER NOT NULL,
PRIMARY KEY (message_id, user_id, emoji)
);
`);
// File attachments for chat messages (file bytes stored on disk at uploads/<id>).
db.exec(`
CREATE TABLE IF NOT EXISTS attachments (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
uploader_id TEXT NOT NULL,
name TEXT NOT NULL,
mime TEXT,
size INTEGER,
created_at INTEGER NOT NULL
);
`);
try { db.exec('ALTER TABLE messages ADD COLUMN attachment_id TEXT'); } catch (e) { /* exists */ }
// Group conversations + membership. (1:1 DMs keep using sender_id/recipient_id directly;
// group messages set conversation_id instead, with recipient_id left blank.)
db.exec(`
CREATE TABLE IF NOT EXISTS conversations (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
type TEXT NOT NULL DEFAULT 'group',
name TEXT,
created_by TEXT,
created_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS conversation_members (
conversation_id TEXT NOT NULL,
user_id TEXT NOT NULL,
last_read_at INTEGER NOT NULL DEFAULT 0,
joined_at INTEGER NOT NULL,
PRIMARY KEY (conversation_id, user_id)
);
`);
try { db.exec('ALTER TABLE messages ADD COLUMN conversation_id TEXT'); } catch (e) { /* exists */ }
try { db.exec('CREATE INDEX IF NOT EXISTS idx_messages_conv ON messages(conversation_id, created_at)'); } catch (e) {}
// Group admins: 1 = this member is an admin (multiple admins allowed). Creator seeded as admin.
try { db.exec('ALTER TABLE conversation_members ADD COLUMN admin INTEGER NOT NULL DEFAULT 0'); } catch (e) { /* exists */ }
try { db.exec('UPDATE conversation_members SET admin=1 WHERE user_id IN (SELECT created_by FROM conversations WHERE conversations.id=conversation_members.conversation_id) AND admin=0'); } catch (e) {}
// Avatars: a user's profile picture (BizGaze photo URL) and a group's uploaded image
// (an attachment id, served via /files/<id> with group-membership auth).
try { db.exec('ALTER TABLE users ADD COLUMN avatar_url TEXT'); } catch (e) { /* exists */ }
try { db.exec('ALTER TABLE conversations ADD COLUMN avatar_id TEXT'); } catch (e) { /* exists */ }
// @mentions on a (group) message: JSON array of mentioned user ids, and/or the literal
// "everyone" for @everyone/@all. Used to highlight and notify mentioned members.
try { db.exec('ALTER TABLE messages ADD COLUMN mentions TEXT'); } catch (e) { /* exists */ }
// Delivered receipt for DMs (double tick): set when the recipient's client acknowledges.
try { db.exec('ALTER TABLE messages ADD COLUMN delivered_at INTEGER'); } catch (e) { /* exists */ }
// Group setting: when 1, only the creator can add/remove members.
try { db.exec('ALTER TABLE conversations ADD COLUMN admin_only INTEGER NOT NULL DEFAULT 0'); } catch (e) { /* exists */ }
// Polls live within a group conversation, attached to a message (the poll's question is
// the message body). options is a JSON array of option strings; votes are one row each.
try { db.exec('ALTER TABLE messages ADD COLUMN poll_id TEXT'); } catch (e) { /* exists */ }
// Activity/event lines (e.g. 'call-start','call-end') render as centered system messages.
try { db.exec('ALTER TABLE messages ADD COLUMN msg_type TEXT'); } catch (e) { /* exists */ }
db.exec(`
CREATE TABLE IF NOT EXISTS polls (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
conversation_id TEXT NOT NULL,
message_id TEXT,
question TEXT NOT NULL,
options TEXT NOT NULL,
multi INTEGER NOT NULL DEFAULT 0,
closed INTEGER NOT NULL DEFAULT 0,
created_by TEXT NOT NULL,
created_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS poll_votes (
poll_id TEXT NOT NULL,
user_id TEXT NOT NULL,
option_idx INTEGER NOT NULL,
created_at INTEGER NOT NULL,
PRIMARY KEY (poll_id, user_id, option_idx)
);
`);
// Scheduled meetings/calls. Each carries a stable room_code so a scheduled call can be
// joined later (the live mesh room is created on first join). group_id is optional — a
// scheduled meeting may target a specific group conversation or be standalone.
db.exec(`
CREATE TABLE IF NOT EXISTS scheduled_meetings (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
group_id TEXT,
room_code TEXT NOT NULL,
title TEXT NOT NULL,
description TEXT,
scheduled_at INTEGER NOT NULL,
created_by TEXT NOT NULL,
created_at INTEGER NOT NULL,
ended_at INTEGER
);
CREATE INDEX IF NOT EXISTS idx_sched_team ON scheduled_meetings(team_id, scheduled_at);
CREATE INDEX IF NOT EXISTS idx_sched_code ON scheduled_meetings(room_code);
`);
// Invited participants (JSON array of user ids) + a one-shot "10-min reminder sent" flag.
try { db.exec('ALTER TABLE scheduled_meetings ADD COLUMN participants TEXT'); } catch (e) { /* exists */ }
try { db.exec('ALTER TABLE scheduled_meetings ADD COLUMN reminded INTEGER NOT NULL DEFAULT 0'); } catch (e) { /* exists */ }
// Cancelled meetings are kept (shown as "Cancelled"), not deleted.
try { db.exec('ALTER TABLE scheduled_meetings ADD COLUMN cancelled INTEGER NOT NULL DEFAULT 0'); } catch (e) { /* exists */ }
try { db.exec('ALTER TABLE scheduled_meetings ADD COLUMN duration_mins INTEGER'); } catch (e) { /* exists */ }
// Weekly recurrence: JSON array of weekdays (0=Sun..6=Sat), or null for a one-off.
try { db.exec('ALTER TABLE scheduled_meetings ADD COLUMN recurrence TEXT'); } catch (e) { /* exists */ }
// Meeting recordings & transcripts. Video bytes live in recordings/m_<id>.webm, transcript text
// in transcripts/m_<id>.txt. Tied to a room (and group/scheduled meeting when applicable) so they
// surface under "Past meetings". kind = 'video' | 'transcript'.
db.exec(`
CREATE TABLE IF NOT EXISTS recordings (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
room TEXT,
group_id TEXT,
meeting_id TEXT,
title TEXT,
kind TEXT NOT NULL,
file TEXT,
mime TEXT,
size INTEGER,
duration_ms INTEGER,
created_by TEXT,
created_by_name TEXT,
created_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_rec_team ON recordings(team_id, created_at);
CREATE INDEX IF NOT EXISTS idx_rec_room ON recordings(room);
`);
module.exports = db;
+59
View File
@@ -0,0 +1,59 @@
// PostgreSQL backend for the async DB adapter — the ONLY backend (SQLite retired 2026-08-12). Implements
// prepare(sql).{get,all,run}, exec(sql), tx(fn), init() so repos/app code stay engine-agnostic (the facade
// in dbx.js keeps the door open for future backends). Connection string from DATABASE_URL.
const { Pool, types } = require('pg');
const fs = require('fs');
const path = require('path');
// BIGINT (int8, OID 20) defaults to STRING in node-postgres to avoid precision loss. Every BIGINT here is
// an epoch-ms timestamp or a byte size — all far below Number.MAX_SAFE_INTEGER — so parse them as numbers
// to match the SQLite backend. Otherwise `expires_at < Date.now()` would compare a string to a number.
types.setTypeParser(20, (v) => (v === null ? null : parseInt(v, 10)));
const pool = new Pool({ connectionString: process.env.DATABASE_URL, max: 10 });
// Repos use '?' placeholders (SQLite style); Postgres wants $1,$2,… — replace positionally. Safe because
// no literal '?' appears inside any SQL string literal in this codebase.
function toPg(sql) { let i = 0; return sql.replace(/\?/g, () => '$' + (++i)); }
function prepare(sql) {
const q = toPg(sql);
return {
get: (...p) => pool.query(q, p).then((r) => r.rows[0]),
all: (...p) => pool.query(q, p).then((r) => r.rows),
run: (...p) => pool.query(q, p).then((r) => ({ changes: r.rowCount, lastInsertRowid: undefined })),
};
}
function exec(sql) { return pool.query(sql).then(() => {}); }
// Transaction on ONE pooled client (a pool would scatter BEGIN/COMMIT across connections). Same runner
// shape the sqlite backend's tx() exposes, so repos.mergeInto is identical on both engines.
async function tx(fn) {
const client = await pool.connect();
try {
await client.query('BEGIN');
const t = {
run: (sql, ...p) => client.query(toPg(sql), p).then((r) => ({ changes: r.rowCount })),
get: (sql, ...p) => client.query(toPg(sql), p).then((r) => r.rows[0]),
all: (sql, ...p) => client.query(toPg(sql), p).then((r) => r.rows),
};
const out = await fn(t);
await client.query('COMMIT');
return out;
} catch (e) {
try { await client.query('ROLLBACK'); } catch (_) {}
throw e;
} finally {
client.release();
}
}
// Apply the schema (all CREATE ... IF NOT EXISTS — idempotent). Multi-statement, no params, so it runs via
// the simple-query protocol in one call. MUST be awaited before serving (server.js boot).
async function init() {
const sql = fs.readFileSync(path.join(__dirname, 'schema.pg.sql'), 'utf8');
await pool.query(sql);
}
module.exports = { prepare, exec, tx, init, name: 'pg', _pool: pool };
+346
View File
@@ -0,0 +1,346 @@
-- PostgreSQL schema for Biz Connect — the target of the SQLite→Postgres migration.
--
-- Every column is defined up front here (unlike the SQLite db.js, which layers columns via ALTER TABLE
-- and hit a real ordering bug). Type mapping from the SQLite schema:
-- SQLite INTEGER epoch-ms timestamp -> BIGINT (ms since epoch; JS Number-safe)
-- SQLite INTEGER 0/1 boolean flag -> SMALLINT (kept numeric so app code still reads 0/1)
-- SQLite INTEGER byte size / duration-> BIGINT (files can exceed INT range)
-- SQLite INTEGER small count (peak) -> INTEGER
-- SQLite AUTOINCREMENT rowid -> BIGINT GENERATED ALWAYS AS IDENTITY
-- TEXT -> TEXT
-- Foreign keys mirror the three the SQLite schema enforced (users→teams, sessions_auth→users,
-- machines→teams). The data-migration script inserts in dependency order so these hold.
CREATE TABLE IF NOT EXISTS teams (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
created_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL REFERENCES teams(id),
email TEXT NOT NULL UNIQUE,
pw_hash TEXT NOT NULL,
pw_salt TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'technician',
mfa_secret TEXT,
mfa_enabled SMALLINT NOT NULL DEFAULT 0,
created_at BIGINT NOT NULL,
name TEXT,
active SMALLINT NOT NULL DEFAULT 1,
avatar_url TEXT,
status TEXT NOT NULL DEFAULT 'active',
bizgaze_user_id TEXT,
last_seen BIGINT
);
CREATE INDEX IF NOT EXISTS idx_users_bizgaze_user_id ON users(bizgaze_user_id);
CREATE TABLE IF NOT EXISTS sessions_auth (
token TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id),
mfa_passed SMALLINT NOT NULL DEFAULT 0,
created_at BIGINT NOT NULL,
expires_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS machines (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL REFERENCES teams(id),
name TEXT NOT NULL,
enroll_token TEXT NOT NULL UNIQUE,
unattended SMALLINT NOT NULL DEFAULT 0,
last_seen BIGINT,
created_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS audit_log (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
team_id TEXT NOT NULL,
user_id TEXT,
user_email TEXT,
machine_id TEXT,
machine_name TEXT,
action TEXT NOT NULL,
detail TEXT,
at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS sessions_log (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
agent_email TEXT,
agent_name TEXT,
ticket TEXT,
started_at BIGINT NOT NULL,
ended_at BIGINT,
recording TEXT,
transcript TEXT
);
CREATE TABLE IF NOT EXISTS refresh_tokens (
token_hash TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
created_at BIGINT NOT NULL,
expires_at BIGINT NOT NULL,
revoked SMALLINT NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS api_keys (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
name TEXT,
key_hash TEXT NOT NULL UNIQUE,
scopes TEXT NOT NULL DEFAULT '',
created_by TEXT,
created_at BIGINT NOT NULL,
last_used_at BIGINT,
revoked SMALLINT NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS webhooks (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
url TEXT NOT NULL,
secret TEXT NOT NULL,
events TEXT NOT NULL DEFAULT '',
active SMALLINT NOT NULL DEFAULT 1,
created_by TEXT,
created_at BIGINT NOT NULL,
last_status INTEGER,
last_error TEXT,
last_at BIGINT
);
CREATE TABLE IF NOT EXISTS messages (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
sender_id TEXT NOT NULL,
recipient_id TEXT NOT NULL,
body TEXT NOT NULL,
created_at BIGINT NOT NULL,
read_at BIGINT,
reply_to TEXT,
attachment_id TEXT,
conversation_id TEXT,
mentions TEXT,
delivered_at BIGINT,
poll_id TEXT,
msg_type TEXT,
deleted SMALLINT NOT NULL DEFAULT 0,
edited_at BIGINT,
fwd_from TEXT,
pinned_at BIGINT, -- #13 pin a message
pinned_by TEXT -- #13
);
CREATE INDEX IF NOT EXISTS idx_messages_pair ON messages(team_id, sender_id, recipient_id, created_at);
CREATE INDEX IF NOT EXISTS idx_messages_unread ON messages(team_id, recipient_id, sender_id, read_at);
CREATE INDEX IF NOT EXISTS idx_messages_conv ON messages(conversation_id, created_at);
-- New: attachment lookups drove the /files auth scan (see static.js authAttachment). Index it so the
-- per-Range playback auth is a keyed lookup, not a table scan (the auth cache stays as a second line).
CREATE INDEX IF NOT EXISTS idx_messages_attachment ON messages(attachment_id);
-- Columns/tables added AFTER the initial PG cutover. The CREATE TABLE above only applies to a FRESH
-- database (IF NOT EXISTS is a no-op once the table exists), so add these idempotently for the existing
-- production table too. Safe to run on every boot. (Unlike the up-front rule at the top of this file, a
-- post-cutover column MUST also be ALTER-ed in — otherwise it silently never lands on the live DB.)
ALTER TABLE messages ADD COLUMN IF NOT EXISTS pinned_at BIGINT; -- #13
ALTER TABLE messages ADD COLUMN IF NOT EXISTS pinned_by TEXT; -- #13
-- #18 "Delete for me": a per-user hide. The message row is untouched (everyone else still sees it); this
-- records that THIS user removed it from their own threads + sidebar.
CREATE TABLE IF NOT EXISTS message_hidden (
message_id TEXT NOT NULL,
user_id TEXT NOT NULL,
hidden_at BIGINT,
PRIMARY KEY (message_id, user_id)
);
CREATE TABLE IF NOT EXISTS message_reactions (
message_id TEXT NOT NULL,
user_id TEXT NOT NULL,
emoji TEXT NOT NULL,
created_at BIGINT NOT NULL,
PRIMARY KEY (message_id, user_id, emoji)
);
-- UGC moderation (App Store Review guideline 1.2): report a message + block a user.
-- Reports are workspace-internal — surfaced to the tenant's admins, who can delete the message / act.
CREATE TABLE IF NOT EXISTS message_reports (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
message_id TEXT NOT NULL,
reporter_id TEXT NOT NULL,
reported_id TEXT NOT NULL,
reason TEXT,
snippet TEXT,
created_at BIGINT NOT NULL,
status TEXT NOT NULL DEFAULT 'open'
);
CREATE INDEX IF NOT EXISTS idx_reports_team ON message_reports(team_id, created_at);
-- A one-directional block: blocker no longer receives the blocked user's messages or calls.
CREATE TABLE IF NOT EXISTS user_blocks (
blocker_id TEXT NOT NULL,
blocked_id TEXT NOT NULL,
team_id TEXT NOT NULL,
created_at BIGINT NOT NULL,
PRIMARY KEY (blocker_id, blocked_id)
);
CREATE INDEX IF NOT EXISTS idx_blocks_blocker ON user_blocks(blocker_id);
CREATE TABLE IF NOT EXISTS attachments (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
uploader_id TEXT NOT NULL,
name TEXT NOT NULL,
mime TEXT,
size BIGINT,
created_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS conversations (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
type TEXT NOT NULL DEFAULT 'group',
name TEXT,
created_by TEXT,
created_at BIGINT NOT NULL,
avatar_id TEXT,
admin_only SMALLINT NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS conversation_members (
conversation_id TEXT NOT NULL,
user_id TEXT NOT NULL,
last_read_at BIGINT NOT NULL DEFAULT 0,
joined_at BIGINT NOT NULL,
admin SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (conversation_id, user_id)
);
CREATE TABLE IF NOT EXISTS call_history (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
room TEXT NOT NULL,
group_id TEXT,
kind TEXT,
title TEXT,
peak INTEGER NOT NULL DEFAULT 0,
participants TEXT,
uids TEXT,
started_at BIGINT NOT NULL,
ended_at BIGINT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_call_history_team ON call_history(team_id, ended_at);
CREATE TABLE IF NOT EXISTS user_aliases (
old_id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
team_id TEXT,
created_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS polls (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
conversation_id TEXT NOT NULL,
message_id TEXT,
question TEXT NOT NULL,
options TEXT NOT NULL,
multi SMALLINT NOT NULL DEFAULT 0,
closed SMALLINT NOT NULL DEFAULT 0,
created_by TEXT NOT NULL,
created_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS poll_votes (
poll_id TEXT NOT NULL,
user_id TEXT NOT NULL,
option_idx INTEGER NOT NULL,
created_at BIGINT NOT NULL,
PRIMARY KEY (poll_id, user_id, option_idx)
);
CREATE TABLE IF NOT EXISTS scheduled_meetings (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
group_id TEXT,
room_code TEXT NOT NULL,
title TEXT NOT NULL,
description TEXT,
scheduled_at BIGINT NOT NULL,
created_by TEXT NOT NULL,
created_at BIGINT NOT NULL,
ended_at BIGINT,
participants TEXT,
reminded SMALLINT NOT NULL DEFAULT 0,
cancelled SMALLINT NOT NULL DEFAULT 0,
duration_mins INTEGER,
recurrence TEXT,
guest_emails TEXT,
lobby SMALLINT
);
CREATE INDEX IF NOT EXISTS idx_sched_team ON scheduled_meetings(team_id, scheduled_at);
CREATE INDEX IF NOT EXISTS idx_sched_code ON scheduled_meetings(room_code);
CREATE TABLE IF NOT EXISTS recordings (
id TEXT PRIMARY KEY,
team_id TEXT NOT NULL,
room TEXT,
group_id TEXT,
meeting_id TEXT,
title TEXT,
kind TEXT NOT NULL,
file TEXT,
mime TEXT,
size BIGINT,
duration_ms BIGINT,
created_by TEXT,
created_by_name TEXT,
created_at BIGINT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_rec_team ON recordings(team_id, created_at);
CREATE INDEX IF NOT EXISTS idx_rec_room ON recordings(room);
CREATE TABLE IF NOT EXISTS push_subscriptions (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
endpoint TEXT NOT NULL UNIQUE,
p256dh TEXT NOT NULL,
auth TEXT NOT NULL,
created_at BIGINT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_push_user ON push_subscriptions(user_id);
CREATE TABLE IF NOT EXISTS device_tokens (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
tenant_id TEXT,
platform TEXT NOT NULL,
token TEXT NOT NULL UNIQUE,
created_at BIGINT NOT NULL,
last_seen BIGINT
);
CREATE INDEX IF NOT EXISTS idx_devtok_user ON device_tokens(user_id);
CREATE TABLE IF NOT EXISTS app_installs (
id TEXT PRIMARY KEY,
install_id TEXT NOT NULL UNIQUE,
user_id TEXT,
user_email TEXT,
tenant_id TEXT,
platform TEXT,
app_version TEXT,
os TEXT,
first_seen BIGINT NOT NULL,
last_seen BIGINT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_installs_tenant ON app_installs(tenant_id);
CREATE INDEX IF NOT EXISTS idx_installs_user ON app_installs(user_id);
CREATE TABLE IF NOT EXISTS favorites (
user_id TEXT NOT NULL,
target TEXT NOT NULL,
created_at BIGINT NOT NULL,
PRIMARY KEY (user_id, target)
);

Some files were not shown because too many files have changed in this diff Show More