WebRTC Bridge
Play a game on one Mac with a controller plugged into another Mac.
Think of it as a long cable over your network. The bridge copies controller input from the first Mac to the second. WebRTC is the technology video calls use to send data straight from one computer to another. The game sees a virtual gamepad. Rumble from the game goes back to the first Mac, where the bridge prints it. The controller does not rumble.
Use it when the game Mac is in another room. Both Macs need OJD and the same network. Build ojd-webrtc-bridge, create a token with ojd access, and run the bridge on each Mac.
sequenceDiagram
participant C as Controller
participant P as Player Mac (bridge, role player)
participant H as Host Mac (bridge, role host)
participant G as Game
C->>P: button presses
P->>H: input over WebRTC
H->>G: virtual gamepad
G-->>H: rumble command
H-->>P: rumble command
Note over P: prints it, controller stays still
The bridge is a separate program, ojd-webrtc-bridge, that you build and run in Terminal on both Macs. The app, the service, and ojd have no WebRTC code. The bridge can do only what you allow with ojd access.
You need two Macs that can reach each other on one network, with OpenJoystickDriver on both.
Warning
Each Mac runs the bridge with a token, which works like a password. Keep it private. Anyone with a token has its access.
Choose the Roles
Each Mac runs one bridge with one role.
| Role | Run it on | Token scope | What it does |
|---|---|---|---|
player |
The Mac with the controller | Read |
Sends one controller’s input to the other Mac. Prints each rumble command it gets back. |
host |
The Mac that runs the game | Control |
Shows the input as a virtual gamepad. Sends the game’s rumble back. |
Build the Bridge
- In Terminal, go to the
Tools/WebRTCBridgefolder of the source tree. - Run
swift build -c release. The first build downloads about 70 MB. - The program is
.build/release/ojd-webrtc-bridge.
Connect Two Macs
The bridges find each other through two lines of text, an offer and an answer, like swapping phone numbers. Copy each line to the other Mac yourself over a channel you trust, such as a message to yourself. Anyone with both lines can try to join.
sequenceDiagram
participant P as Player Mac
participant You
participant H as Host Mac
P->>You: prints the offer line
You->>H: paste the offer
H->>You: prints the answer line
You->>P: paste the answer
P-->H: link opens
- On each Mac, turn on the endpoint:
ojd access enable. - On the player Mac, create a token that lets the bridge read your controller:
ojd access grant --token bridge --scope read. The command prints the token once. Keep it. - On the host Mac, create a token that lets the bridge drive a virtual gamepad:
ojd access grant --token bridge --scope control. Keep it. - On the player Mac, start the bridge:
OJD_TOKEN=TOKEN ojd-webrtc-bridge --role player. ReplaceTOKENwith the player token. The bridge prints its offer as one line. - Copy the offer to the host Mac. Start the bridge there:
OJD_TOKEN=TOKEN ojd-webrtc-bridge --role host. ReplaceTOKENwith the host token. Paste the offer and press Return. The bridge prints its answer as one line. - Copy the answer to the player Mac, paste it, and press Return.
When the link opens, each bridge connects to the local endpoint socket of its Mac. The virtual gamepad appears on the host Mac. Stop each bridge with Control-C.
Use the Command Options
Output of ojd-webrtc-bridge --help:
usage: ojd-webrtc-bridge --role host|player [--signal offer|answer] [--socket PATH]
[--token-name NAME] [--controller ID] [--persona Generic|SDLCompatible]
[--ice-server URL]...
Set OJD_TOKEN to the token that `ojd access grant --token NAME` printed.
The offer and the answer are one line each: the bridge prints its own on stdout and reads the
peer's from stdin. The player offers by default and the host answers.
--role host|player: Required.--signal offer|answer: Choose which bridge offers. The player offers and the host answers by default.--socket PATH: Path of the endpoint socket. Without it, the bridge runsojd --json access status.--token-name NAME: Token name. The default isbridge.--controller ID: Controller ID fromojd controller list, forplayer. Without it, the player uses the first controller the endpoint reports.--persona Generic|SDLCompatible: Virtual gamepad kind forhost.Genericis the Generic HID gamepad.SDLCompatibleis for Steam and SDL games. The default isGeneric.--ice-server URL: Add a STUN or TURN server. Repeat it for more. Without it, the bridge uses local addresses, enough for one network.
OJD_TOKEN must hold the token, or the bridge refuses to start.
If the Bridge Does Not Work
E1002: the token is wrong or lacks the scope of the role. Create it again with the right--scope, as in Connect Two Macs. See Error Codes.- Socket not found: run
ojd access statusand pass the path with--socket. - Macs do not connect: check that both are on one network, or give each bridge a STUN server with
--ice-server.