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.

4.0 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Audio tab (copy of windows/ui-audio.js): sound both ways, each its own stream: play the
// other computer's sound here, and send this computer's sound there (PulseAudio/PipeWire loopback,
// loopback.js). Screen sound lives in Share 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
  order: 70,
  title: I18n.t('Audio'),
  color: 'linear-gradient(#ff6482, #ff2d55)',
  desc: I18n.t('Hear one computer on the other.'),
  // 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.send || s.audio.receive) : ((s) => 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.receiving || s.audio.sending ? 'on' : ''),
  build(body) {
    const { api } = UI;
    const set = (partial) => api.setAudio(partial);
    const volume = UI.slider({ min: 0, max: 1, step: 0.05, format: (v) => Math.round(v * 100) + '%' }, (v) => set({ volume: v }));
    const mute = UI.switch((v) => set({ muteLocal: v }), { label: I18n.t('Mute {me} while sending') });
    const recvState = UI.row('', '', [], { literal: true });
    const sendState = UI.row('', '', [], { literal: true });
    const pair = UI.dirCards(
      { on: { get: (s) => s.audio.receive, set: (v) => set({ receive: v }) }, label: I18n.t('Play {name}’s sound on {me}'), rows: [
        UI.row(I18n.t('Volume'), '', [volume]),
        recvState,
      ] },
      { on: { get: (s) => s.audio.send, set: (v) => set({ send: v }) }, label: I18n.t('Share {me}’s sound with {name}'), rows: [
        UI.row(I18n.t('Mute {me} while sending'), '', [mute]),
        sendState,
      ] },
    );
    const phoneCard = UI.phoneAudioCard(); // a phone: its sound here over Bluetooth, its media controls
    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 airplay = UI.airplayPlaying ? UI.airplayPlaying() : null; // music an iPhone plays here (AirPlay)
    const mix = UI.soundMixer ? UI.soundMixer() : null; // computers: several, their speakers, a volume each (shared/ui-sound-mix.js)
    body.append(
      ...(airplay ? [airplay.el] : []),
      ...(mix ? [mix.el] : []),
      pair.el,
      ...(cap ? [cap.el] : []),
      ...(micCard ? [micCard.el] : []),
      phoneCard.el,
    );
    return (s) => {
      if (airplay) airplay.update(s);
      phoneCard.update(s);
      if (cap) cap.update(s);
      if (micCard) { micCard.update(s); }
      const a = s.audio;
      const connected = s.link.state === 'connected';
      // 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.el.hidden = !!mix;
      pair.update(s);
      volume.set(a.volume);
      mute.set(a.muteLocal); // the speakers quiet while sending, the capture goes on (loopback.js)
      recvState.hidden = !a.receive;
      const nm = UI.peer(s).name;
      const phone = UI.phoneSound && UI.phoneSound(s);
      recvState.label.textContent = phone != null ? phone : a.receiving ? I18n.t('Playing {device}', { device: nm }) : connected ? I18n.t('Turned off on {device}', { device: nm }) : I18n.t('Waiting for {device}', { device: nm });
      sendState.hidden = !a.send && !a.error;
      sendState.label.textContent = a.sending ? I18n.t('Playing on {device}', { device: nm }) : !connected ? I18n.t('Waiting for {device}', { device: nm }) : !a.macAccepts ? I18n.t('Turned off on {device}', { device: nm }) : I18n.t('Connecting…');
      sendState.setHint(I18n.t(a.error || ''));
    };
  },
});