Skip to content

All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.

3.8 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Audio tab: sound on its own, both ways, independent of the screen.
'use strict';

UI.tab({
  id: 'audio',
  wifiOnly: true, // over Bluetooth it can't work and doesn't move the session onto Wi-Fi: says so, with Connect with Wi-Fi Direct
  group: 'More',
  order: 70,
  title: I18n.t('Audio'),
  desc: I18n.t('Hear one computer on the other.'),
  color: 'linear-gradient(#ff6482, #ff2d55)',
  // Multi-device: on opens the page with no device ticked; off turns sound off with all (shared/ui-sound-mix.js).
  master: {
    get: (s) => (UI.soundMaster ? UI.soundMaster.get(s, (s) => !!(s.audio && (s.audio.send || s.audio.receive))) : ((s) => !!(s.audio && (s.audio.send || s.audio.receive)))(s)),
    set: (v) => (UI.soundMaster ? UI.soundMaster.set(v, UI.state, (x) => UI.api.setAudio({ send: x, receive: x })) : UI.api.setAudio({ send: v, receive: v })),
  },
  badge: (s) => (s.audio && (s.audio.send || s.audio.receive) ? 'on' : ''),
  build(body) {
    const { api } = UI;
    const sendSw = UI.switch((v) => api.setAudio({ send: v }), { label: I18n.t('Send sound') });
    const mute = UI.switch((v) => api.setAudio({ muteLocal: v }), { label: I18n.t('Mute while sending') });
    const recvSw = UI.switch((v) => api.setAudio({ receive: v }), { label: I18n.t('Play sound here') });
    const muteRow = UI.row(I18n.t('Mute {me} while sending'), '', [mute]);
    const vol = UI.slider({ min: 0, max: 1, step: 0.05, format: (v) => `${Math.round(v * 100)}%` }, (v) => api.setAudio({ volume: v }));
    const sendRow = UI.row(I18n.t('Share {me}’s sound with {name}'), '', [sendSw], { literalHint: true });
    const recvRow = UI.row(I18n.t('Play {name}’s sound on {me}'), '', [recvSw], { literalHint: true });
    const phoneCard = UI.phoneAudioCard(); // a phone: its media controls on Overview
    const mix = UI.soundMixer ? UI.soundMixer() : null; // computers: several, their speakers, a volume each (shared/ui-sound-mix.js)
    const micCard = UI.micCard ? UI.micCard() : null; // Microphone, each way (shared/ui-mic.js)
    const cap = UI.audioCaptureCard ? UI.audioCaptureCard({ mute: false }) : null; // engine and mute (shared/ui-web.js)
    const pair = UI.pair(
      UI.dir('m2w', [sendRow, muteRow]),
      UI.dir('w2m', [recvRow, UI.row(I18n.t('Volume'), '', [vol])]),
    );
    body.append(
      ...(mix ? [mix.el] : []),
      pair,
      ...(cap ? [cap.el] : []),
      ...(micCard ? [micCard.el] : []),
      phoneCard.el,
    );
    const live = (x) => x && x.status === 'live';
    return (s) => {
      const a = s.audio;
      if (!a) return;
      // A computer: the mixer; a phone: its sound here and ours there, as before.
      if (mix) mix.update(s); // computers, phones and TVs alike (shared/ui-sound-mix.js)
      pair.hidden = !!mix;
      phoneCard.update(s);
      if (micCard) { micCard.update(s); }
      sendSw.set(a.send);
      mute.set(a.muteLocal);
      if (cap) cap.update(s);
      // Mute works only with the helper's capture (Capture engine).
      muteRow.hidden = !!(s.web && s.web.audio && s.web.audio.engine !== 'helper');
      recvSw.set(a.receive);
      vol.set(a.volume);
      const pc = UI.peer(s).name;
      sendRow.setHint(!a.send || !s.client ? ''
        : a.screenCarries ? I18n.t('Playing with the screen')
          : !a.peerAccepts ? I18n.t('Turned off on {device}', { device: pc })
            : a.error ? I18n.t('Can’t capture sound: {error}', { error: a.error })
              : live(a.sending) ? I18n.t('Playing on {device}', { device: pc }) : I18n.t('Connecting…'));
      const phone = UI.phoneSound && UI.phoneSound(s);
      recvRow.setHint(!a.receive ? '' : phone != null ? phone : !s.client ? '' : live(a.receiving) ? I18n.t('Playing {device}', { device: pc }) : I18n.t('Waiting for {device}', { device: pc }));
    };
  },
});