Repository navigation
WebRTC Bridge
Use ojd-webrtc-bridge to play a game on one Mac with a controller that is connected to another Mac.
Note: This page applies to OpenJoystickDriver 0.6.0-alpha.1 and later. Version 0.5.0-beta.4 and earlier do not have all of the features on this page.
The bridge is a separate program. It sends the input of one controller over a WebRTC data channel to a virtual gamepad on the other Mac, and sends rumble back. The app, the service, and ojd do not include WebRTC code. The bridge gets only the access that you give it with ojd access.
For the message formats, the sockets, and the limits, see the WebRTC bridge reference.
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 the input of one controller to the other Mac. It prints each rumble command that comes back. It does not make the controller rumble. |
host |
The Mac that runs the game | control |
Shows the input as a virtual gamepad, and sends the rumble of the game back. |
The bridge is not part of the app. Build it from the source tree:
- Open Terminal and 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-bridgein that folder.
You carry two lines of text between the Macs yourself, by any channel that you trust. Anyone who has both lines can try to join the data channel.
- On each Mac, turn on the endpoint:
ojd access enable. - On the player Mac, create a token:
ojd access grant --token bridge --scope read. Keep the token that the command prints. It prints the token once. - On the host Mac, create a token:
ojd access grant --token bridge --scope control. Keep the token. - On the player Mac, start the bridge:
OJD_TOKEN=TOKEN ojd-webrtc-bridge --role player. ReplaceTOKENwith the token of the player Mac. 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 token of the host Mac. 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 data channel opens, each bridge connects to the endpoint of its Mac. The virtual gamepad appears on the host Mac. Stop each bridge with Control-C.
This is the 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: Choose the role. This option is required. -
--signal offer|answer: Choose which bridge makes the offer. The player offers and the host answers by default. -
--socket PATH: Give the path of the endpoint socket. Without it, the bridge runsojd --json access statusto find the path. -
--token-name NAME: Give the name of the token. The default isbridge. -
--controller ID: Give the controller for theplayerrole, as the ID fromojd controller list. Without it, the player uses the first controller that the endpoint reports. -
--persona Generic|SdlCompatible: Choose how the virtual gamepad of thehostrole appears. The default isGeneric. -
--ice-server URL: Add a STUN or TURN server. You can repeat this option. Without it, the bridge uses only local addresses, which is enough for two Macs on one network.
The environment variable OJD_TOKEN must hold the token. The bridge refuses to start without it.
-
The bridge prints an
E1002error. The token does not have the scope of the role, or it is wrong. Create the token again with the right--scope, as in Connect Two Macs. See Error codes. -
The bridge cannot find the socket. Run
ojd access statusand pass the path of the socket with--socket. -
The two Macs do not connect. Both Macs must be on the same network, or you must give each bridge a STUN server with
--ice-server.
- Home
- Start here
- Controllers
- Games
- Remapping
- Your Mac
- Command line
- Help
- Advanced