Bundle with esbuild, webpack, bun build, or another bundler.
Prepare the events object to be used with Echo-D.
Include the listenToHost and sendToHost methods from the transport layer.
Include the listenToControls method from the controller layer.
Need to be able to update the views when Echo-D is updated.
Delare an onUpdate function to be used by Echo-D when it is updated.
This will call the updateRender function to update the views, but it
should be throttled to 30 frames per second. So that it doesn’t occur too often.
Create an instance of Echo-D with the events object and the echoOptions object.
Listen to Host
Listen to host and handle incoming messages with Echo-D.
List to controls and send inputs to the host.
Seupt a handler to remove the actor when the window is closed or refreshed.
Create react three fiber Canvas in document root
Actor Controller
Setup event listener on the window to listen for keydown events.
Move the actor based on the keydown event. Then send the input to the host.
On Init
When the client is initialized, it should send a message to the host to get the
symbols, actors, entities, and components. Then it should spawn an actor for the client.
Client Transport Layer
Choose a network transport layer such as
BroadcastChannel, WebSocket, or WebRTC.
Import the onInit function for initializing the client.
Create a BroadcastChannel for the game clients and the game host.
Now setup a message handler for the bcGameClients.
This example only supports one host and multiple clients.
Handle messages by passing them to the Echo-D instance.
Automatically call the onInit function when the client begins listening.
Implement the sendToHost function to send messages to the host.
Or use WebSocket in a supported environment such as a web browser.
msgpack is also recommended for reducing the size of messages.
Especially when transporting over the network.
Create a websocket client, and ensure errors are handled.
Listen to the host and handle incoming messages with Echo-D using the WebSocket.
Call the onInit function when the client is initialized.
Implement the sendToHost function to send messages to the host.
Default Client Transport
Provide a way to import the sendToHost method from ./client/transport.js.
This will use the echoD store to create a list of render views, and update
them when the store is updated.
The renderViews object is used to store the react three fiber views,
and the renderObjects object is used to store the three objects.
The updateRender function is called after every update, and should be used
to update the render views.
Update Render Entity
The updateRenderEntity function is called for every entity in the echoD store,
and should be used to update the render views.
It will also emit a render event when the views are updated.
It uses React Fiber to render the views.
Client Components
The client components are used to render the 3D objects in the React Fiber tree.
Ball Component
Use <Ball /> to create a 3D ball in the React Fiber tree.
EchoD Component
Use <EchoD /> to embed 3D entities into React Fiber tree
Render Component
Use <Render /> to create a React Fiber tree with a 3D canvas amd embed 3D entities.