Skip to content
Jirka Dell'Oro-Friedl edited this page Sep 19, 2022 · 2 revisions

FudgeClient is a browser script that handles the communication with FudgeServer and the other clients. Most of the script takes care of the setup of WebRTC connections with the other clients, mediated by FudgeServer acting as the signalling server. For ingame communication though, FudgeClient implements the functionality to dispatch Messages into the network and receive those.

When dispatching a message, FudgeClient adds the clients source id, the id of the room it is connected to and the timestamp to the message. Depending on the route and the idTarget of the message, the clients sends the message to the server via WebSocket or to one or more other clients via WebRTC.

When a message is received, FudgeClient examines the command and reacts to setup the network structure accordingly. If no command is specified, FudgeClient dispatches an event of the type FudgeNet.EVENT.MESSAGE_RECEIVED to itself with the message in the data field.

Starting a FudgeClient can be done simply by instantiating and connecting like this:

let client: FudgeNet.FudgeClient= new FudgeNet.FudgeClient();
client.connectToServer(<url>);

However, it's also possible to subclass FudgeServer to override and reuse it's methods.