# Multiplayer Sessions

Polygonjs allows you to edit scenes with collaborators in real time.

You'll get to see each other create nodes, connect them, change parameters, see the results, all this at the same time. it's a great way to collaborate and learn from one another.

<DocVideo src="docs/multiplayer/multiplayer_v01" alt="multiplayer session" />

# How Multiplayer works

Multiplayer mode in Polygonjs works the following way:

1. **Sam** starts the [local app](/install) on her computer.

2. If **Sam** starts the multiplayer session, Polygonjs displays a link she can share to anyone she would like to invite. She sends it **Jo**.

3. **Jo** clicks the link. This opens a page with Polygonjs editor.

4. **Sam** receives a request to join (similarly to zoom or google meet). She accepts the request.

5. **Jo** can now see the same 3D scene as **Sam**.

6. They can now both edit the scene at the same time. If one creates a node, deletes it or changes a parameter, both see the same result.

7. If they save the scene, it gets saved on **Sam**'s computer, as she is the one who started the [local app](/install).

# Starting Multiplayer Mode

Multiplayer mode works only with the [local app](/install), not the web editor. So make sure to install and run the [local app](/install) first.

Then from the top menu, open the multiplayer panel via `Windows -> Multiplayer`.

<DocImage src="docs/multiplayer/top_menu_multiplayer.jpg" alt="top menu" />

You'll then see a panel with instructions. Those are a shorter summary of what this page explains.

<DocImage src="docs/multiplayer/multiplayer_panel_instructions.jpg" alt="instructions" />

And the first instruction is to create an [ngrok](https://ngrok.com/) account, so let's see that in the next section:

## NGrok

Polygonjs currently relies on [ngrok](https://ngrok.com/) to allows other users to access someone's local app.

Even though the local app is run on `http://localhost:8091`, it is by default not accessible outside of the local network. So we need ngrok to allow sharing to the outside world.

Luckily, it's pretty simple, as all you need to do is:

1. Create an [ngrok](https://ngrok.com/) account.
2. Get the authtoken from [https://dashboard.ngrok.com/get-started/your-authtoken](https://dashboard.ngrok.com/get-started/your-authtoken).

<DocImage src="docs/multiplayer/tunnels/ngrok/authtoken_area_selected.jpg" alt="auth token" />

Then you need to add this authtoken to Polygonjs config. This is done via the [EditorConfig.ts](/docs/editor/config) file. You need to add the following line to it:

```
options.api.multiplayer.remote.ngrok.setAuthToken('YOUR-AUTH-TOKEN');
```

If you are using a version more recent than 1.2.68, this line would be present in EditorConfig.ts, just commented out. So you can simply remove the comment.

## Start a session

Now you can simply click on `Check it's all correct` (no need to reload the page):

<DocImage src="docs/multiplayer/multiplayer_panel_instructions_check.jpg" alt="check" />

And if all goes well, you will see the following:

<DocImage src="docs/multiplayer/multiplayer_panel_start.jpg" alt="start" />

You can click on `Start Multiplayer Session`, and you will then see:

<DocImage src="docs/multiplayer/multiplayer_panel_started.jpg" alt="started" />

This panel now displays the link that you can share with anyone you would like to join.

_Note_: there are times where the link doesn't display immediately. Refreshing the page and re-opening the multiplayer panel helps when this happens (and you can reload the page safely, you won't have to go through the above steps a second time)
