USB forwarding #
Rubylight docs › Controllers · Clipboard, files and USB · DualSense haptics
A USB device plugged into the client, such as a flash drive, a USB gamepad or a dongle, can be attached to the host PC during a stream and used as if it were plugged into the PC. The client serves the device over USB/IP inside a TLS tunnel on the stream's HTTPS port, and usbip-win2 attaches it on the host. No USB/IP port is open to the network: the host relays the tunnel to the driver on 127.0.0.1. The protocol is specified in the native API and control messages.
Setup #
- On the host: install usbip-win2, either with the installer's optional Install USB audio and haptics support or from its own release. Turn on All settings → Sound & controls → USB devices → USB forwarding (
usb_forwarding, off by default). USB devices at once (usb_max_devices, 1 to 16, default 4) limits how many devices this PC takes from all clients at the same time. - For each client: open the device under Devices in the console and tick USB devices under its permissions. Taking the permission away disconnects a streaming device, which detaches its USB devices.
- On Nightjar for Windows or Linux: turn on Settings → Controls → USB → Forward USB devices. During a stream, USB devices on the Controller page of the Control Center lists the USB devices plugged in here (hubs left out), each with Attach or the reason it can't be forwarded.
- On Nightjar for Android: turn on Settings → Controls → USB → Forward USB devices. During a stream, USB devices is on the Controller page of the Control Center: picking a device asks Android for access and attaches it, and picking it again detaches it. Hubs and the controllers Nightjar's own USB drivers use are not listed.
Nightjar's USB devices page covers the client side.
The host forwards nothing while the setting is off, usbip-win2 is missing or the client lacks the permission; the client shows which of these applies.
What can be forwarded #
- Windows clients reach a device through the WinUSB driver. A device under another driver (USBSTOR for a flash drive, HidUsb for a gamepad, an interface of a composite device) is listed with that driver named and Attach disabled. Two ways to forward it:
- With usbipd-win installed, the device gets a Forward with usbipd-win button instead. Windows keeps its own driver: Nightjar shares the device with
usbipd bind(Windows asks for administrator rights), imports it from usbipd-win on127.0.0.1:3240only, checks that usbipd-win answered with the busid, vendor and product picked, and relays it to the PC. usbipd-win takes the device only while it is attached and gives it back to its driver when the attachment ends. A device you had shared with usbipd-win yourself stays shared; one Nightjar shared is unshared when the attachment ends (usbipd unbind --guid, a second administrator prompt). Nightjar writes each device it shares tousbipd-journal.jsonin its config folder before sharing it, and the share's ID as soon as usbipd-win lists it; if Nightjar stops before unsharing it (a crash, a cancelled prompt), its next start finds the shares that journal names without a prompt and asks once, in the launcher, whether to give them back (another administrator prompt). After Not now the start doesn't ask again; USB devices in the Control Center offers Give back to Windows instead. Only those shares are ever unshared. A share that is forced or that another computer has attached is never unshared, and one whose ID Nightjar never learnt (it stopped during the administrator prompt) is left as it is. Windows' administrator prompts belong to Nightjar's window, so they open in front of it, a fullscreen stream too; when usbipd-win runs without administrator rights (exit code 3), Nightjar says so instead of reporting a cancelled prompt. Nightjar runs usbipd-win only from its install folder under Program Files, refuses a device it can't tell from an identical one on the same port of another USB controller, and checks that usbipd-win's service answers before sharing anything. While a device is shared, usbipd-win's own firewall rule lets computers on your local subnets import it as well, so Nightjar shares it only for the attachment. - Without usbipd-win, install WinUSB for that device, for example with Zadig; Windows on the client can't use it while WinUSB has it. Device Manager's Update driver or
pnputilgives it its own driver back.
- With usbipd-win installed, the device gets a Forward with usbipd-win button instead. Windows keeps its own driver: Nightjar shares the device with
- Linux clients open a device through
libusbwhen they may (/dev/bus/usb, usually a udev rule). Nightjar detaches the kernel driver while the device is attached, and Linux takes it back afterwards. Whenlibusbis refused permission, Nightjar hands the device to Linux's own USB/IP server instead (theusbip-hostpath below, one password prompt); without that server, the message asks for a udev rule. When you cancel that prompt for a device on the Automatic list, the automatic attach doesn't ask again during the stream: Attach, or ticking Automatic again, asks once more. - Linux clients forward devices with isochronous endpoints (USB audio, webcams) through the kernel's own USB/IP server when
usbip-hostis available: on Attach, Nightjar's helper (/usr/lib/nightjar/nightjar-usb-helper, run through pkexec, so Linux asks for an administrator password) binds the device tousbip-hostand hands it one end of a TCP connection Nightjar makes on 127.0.0.1 (asusbipddoes after an import), and Nightjar relays the tunnel to the other end. Nousbipdruns: nothing listens for USB/IP, and the loopback listener that makes the connection takes that one connection and closes. The device goes back to its own driver when the attachment ends or Nightjar quits or crashes; a udev rule (90-nightjar-usb.rules) clears the port when a forwarded device is unplugged. This needs the distribution's usbip tools (usbip; on Ubuntulinux-tools-generic), theusbip_hostmodule and pkexec. The .deb and .rpm install the helper, its polkit policy and the rule; the AppImage installs them on the first such Attach. Whenusbip-hostis unavailable (for example in the Flatpak or without the module/helper), Linux falls back automatically tolibusbfor isochronous devices. - Windows and macOS clients forward devices with isochronous endpoints too: Windows uses its inbox WinUSB driver (no extra driver beyond installing WinUSB for that device), and macOS uses
libusb. - A forwarded controller is not read twice. On Windows, macOS and Linux, a controller Nightjar is forwarding stops being one of the stream's gamepads while it is attached, so the PC doesn't get its input both over USB and as a Nightjar gamepad, and comes back as a gamepad as soon as the attachment ends (detach, unplug, the stream ending or the connection dropping). On Linux the controller is matched by its USB port; elsewhere only when it is the one controller of that model plugged in and was connected before the forwarding started, so another controller of the same model that connects meanwhile stays a gamepad.
On the host #
The console's Devices page shows a USB devices panel once a device has the permission or something is attached: each client's devices with their ID (vid:pid), bus ID and state (waiting for the device, connecting, attached on a port, detaching, detach failed). Detach unplugs one; Detach again retries a failed detach.
An attachment ends when the client detaches it, the console detaches it, the stream ends, either side closes the tunnel or the client disconnects.
Troubleshooting #
- "Falscher Parameter" or "The parameter is incorrect" from
usbip detach: when the tunnel closes first, usbip-win2 unplugs the device on its own, and a laterusbip.exe detach --port <n>fails with Windows' error in the display language. The host then asksusbip.exe port <n>; its answerrequested port(s) not found(the same in every language) means the device is gone, and the detach counts as done. The host log saysusbip.exe detach failed for a port the driver already unplugged. Any other answer keeps the failure, and the console shows Detach failed with the reason. - A device left attached after a crash:
usbip.exe portlists the host's ports, andusbip.exe detach --port <n>unplugs one.