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.
JavaScript androidapple-ecosystemconnectelectronfile-sharingintel-unison-alternativeiosios-windowskde-connect-alternativekvmlinuxmacbookmacosmouse-sharingphone-link-alternativeproductivityscreen-sharingsidecar-alternativesynergy-alternativewindows
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Which iPhone is which on a USB cable, for the whole mesh (shared/ios-links.js): an unlinked iPhone
// with the app answering on our cable is asked once while it stays plugged in; its answer links it,
// kept and sent to every device, which keeps it too and learns which computer has it on its cable;
// the newer link of a UDID wins; one app has one cable.
// Run with: node --test shared/test/ios-links.test.js
'use strict';
const assert = require('assert');
const { test } = require('node:test');
const P = require('../protocol.js');
const { IosLinks } = require('../ios-links.js');
const T = P.T;
const UDID = '00008030-000969E80ABB802E';
const PHONE = 'ed082165e4aa7048fba4daaac2953133';
// Two computers whose buses deliver to each other at once.
function pair() {
const nodes = {};
const make = (id, ask) => {
const handlers = new Map();
const peers = new Map();
const saved = [];
const bus = {
on: (t, fn) => handlers.set(t, fn),
onPeer: (ev, fn) => peers.set(ev, fn),
connectedIds: () => Object.keys(nodes).filter((x) => x !== id),
send: (to, m) => { const h = nodes[to].handlers.get(m.t); if (h) h(JSON.parse(JSON.stringify(m)), id); return true; },
};
const links = new IosLinks({ hub: { bus, device: { id } }, store: { get: () => ({}), set: (l) => saved.push(l) }, ask });
nodes[id] = { handlers, peers, links, saved };
return nodes[id];
};
return { make, nodes };
}
const tick = () => new Promise((r) => setImmediate(r));
test('an iPhone with the app on the cable is asked once, linked, and the mesh knows where it is', async () => {
const asked = [];
const { make } = pair();
const mac = make('mac', (udid) => { asked.push(udid); return Promise.resolve({ id: PHONE, name: 'iPhone' }); });
const win = make('win');
mac.links.local([{ udid: UDID, name: 'iPhone', control: true, app: false }]); // the app isn't answering yet: not asked
assert.deepStrictEqual(asked, []);
mac.links.local([{ udid: UDID, name: 'iPhone', control: true, app: true }]);
mac.links.local([{ udid: UDID, name: 'iPhone', control: true, app: true }]); // again: asked once
await tick();
assert.deepStrictEqual(asked, ['00008030000969E80ABB802E']);
assert.strictEqual(mac.links.phoneOf(UDID), PHONE);
assert.strictEqual(win.links.phoneOf(UDID), PHONE, 'sent to the others');
assert.ok(win.saved.length >= 1, 'kept there too');
assert.deepStrictEqual(win.links.where(PHONE), { at: 'mac', udid: '00008030000969E80ABB802E', control: true });
assert.deepStrictEqual(mac.links.where(PHONE), { at: 'mac', udid: '00008030000969E80ABB802E', control: true });
mac.links.local([]); // unplugged
assert.strictEqual(win.links.where(PHONE), null);
assert.strictEqual(win.links.phoneOf(UDID), PHONE, 'the link stays');
});
test('a "no" isn\'t asked again until it\'s plugged in again, or the app answers on it again', async () => {
const asked = [];
const { make } = pair();
const mac = make('mac', (u) => { asked.push(u); return Promise.resolve(null); });
const dev = [{ udid: UDID, name: 'iPhone', control: true, app: true }];
mac.links.local(dev);
await tick();
mac.links.local(dev);
assert.strictEqual(asked.length, 1);
mac.links.local([]);
mac.links.local(dev);
assert.strictEqual(asked.length, 2);
mac.links.local([{ ...dev[0], app: false }]); // the app quit (updated)
mac.links.local(dev); // and answers again
assert.strictEqual(asked.length, 3);
});
test('the newer link of a UDID wins, older news changes nothing; one app has one cable', () => {
const { make, nodes } = pair();
const mac = make('mac');
make('win');
mac.links.link(UDID, PHONE, 'iPhone');
const at = mac.links.links['00008030000969E80ABB802E'].at;
nodes.mac.handlers.get(T.IOS_LINKS)({ links: { [UDID]: { phone: 'aaaaaaaaaaaaaaaa', name: 'Old', at: at - 1000 } } }, 'win');
assert.strictEqual(mac.links.phoneOf(UDID), PHONE);
nodes.mac.handlers.get(T.IOS_LINKS)({ links: { [UDID]: { phone: 'bbbbbbbbbbbbbbbb', name: 'New', at: at + 1000 } } }, 'win');
assert.strictEqual(mac.links.phoneOf(UDID), 'bbbbbbbbbbbbbbbb');
mac.links.link('00008101-0000AAAA0000BBBB', 'bbbbbbbbbbbbbbbb', 'New'); // the same app on another iPhone
assert.strictEqual(mac.links.phoneOf(UDID), '');
assert.strictEqual(mac.links.udidOf('bbbbbbbbbbbbbbbb'), '000081010000AAAA0000BBBB');
});