Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/decentraland-scenes/ws-example
A basic scene that uses a WebSockets server to sync changes between players.
https://github.com/decentraland-scenes/ws-example
decentraland
Last synced: 2 months ago
JSON representation
A basic scene that uses a WebSockets server to sync changes between players.
- Host: GitHub
- URL: https://github.com/decentraland-scenes/ws-example
- Owner: decentraland-scenes
- License: apache-2.0
- Created: 2020-07-16T18:18:06.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-28T20:44:47.000Z (over 2 years ago)
- Last Synced: 2024-05-02T17:52:59.635Z (5 months ago)
- Topics: decentraland
- Language: TypeScript
- Homepage:
- Size: 3.69 MB
- Stars: 1
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- Awesome-Repository - Color Switch - basic.png" width="200"> | A minimal scene where clicking on cubes changes their color. The broadcast server syncs these changes to all other players in the same realm. | (Examples / Multiplayer and APIs)
README
# ws-example
A basic scene that uses a WebSockets server to sync changes between players. When a player clicks on a cube, all players see it turn green. The scene checks the player's realm and only syncs between players that are in the same realm, to keep things consistent between players that can see each other.
![](screenshot/screenshot.png)
The scene relies on a [broadcast websockets server](https://github.com/decentraland-scenes/ws-broadcast) that broadcasts all messages that are sent to it to all players.
## Try it out
**Install the CLI**
Download and install the Decentraland CLI by running the following command:
```bash
npm i -g decentraland
```**Previewing the scene**
Download this example and navigate to the `scene` directory, then run:
```
$: dcl start
```Any dependencies are installed and then the CLI opens the scene in a new browser tab.
**Run the server**
By default, the scene relies on an already deployed server on that can be reached on `wss://64-225-45-232.nip.io/`
To instead run the server locally, on a separate command line window, navigate to the `server` directory and run the following command to install all the dependencies:
```
npm i
```Once the dependencies are installed, run the following command to start the server:
```
npm run start
```The server will then be listening on `localhost:8080`, you can redirect the scene to point to this address when connecting to the WS server.
```
socket = new WebSocket(
'wss://localhost:8080/broadcast/' + realm.displayName
)
```**Scene Usage**
Click on the cubes to see them change color. If you open multiple tabs to the same preview, you should see that all tabs respond to the changes that other players do too. These messages are travelling via WebSockets.
Learn more about how to build your own scenes in our [documentation](https://docs.decentraland.org/) site.
If something doesn’t work, please [file an issue](https://github.com/decentraland-scenes/Awesome-Repository/issues/new).
## Copyright info
This scene is protected with a standard Apache 2 licence. See the terms and conditions in the [LICENSE](/LICENSE) file.