Developer
DeveloperClient
enables inspection and debugging RoomClient
through message logs. It listens for developer.log
messages from the server and emits them locally as RoomLogEvent
objects.
Overview
DeveloperClient
– A high-level client that listens fordeveloper.log
events and provides methods to watch, unwatch, and send developer logs.
API Methods
Below is an example of how you might use the DeveloperClient
in your code:
DeveloperClient
A client that listens for developer.log
events and provides methods to enable, disable, and log custom developer messages.
room: RoomClient
An instance ofRoomClient
, which handles the underlying communication with the server.
log(type: string, data: Record<string, any>)
Sends a developer.log
message to the server with the specified type and data. This can be used to track custom logs, diagnostics, or other developer-related messages in your application.
-
Parameters:
type
– A string identifying the log level or category, such as"info"
,"warn"
, or"debug"
.data
– A JSON-serializable object containing additional details for the log entry.
-
Description
Encodes thetype
anddata
into a message, then sends it to the server. This message is typically consumed by developers or other backend listeners for debugging or monitoring purposes.
enable()
Watches developer messages on the server, effectively enabling the reception of developer.log
events.
- Description
Sends adeveloper.watch
message to the server to start receivingdeveloper.log
events. If the server is configured to honor these watch requests, it will begin sending any future developer logs to this client.
disable()
Unwatches developer messages on the server, stopping the reception of developer.log
events.
- Description
Sends adeveloper.unwatch
message to the server to stop receivingdeveloper.log
events. Further developer logs from the server will be ignored untilenable()
is called again.
Additional Notes
- Event Emission
TheDeveloperClient
extends anEventEmitter<RoomLogEvent>
. It emits a"log"
event whenever adeveloper.log
message is received from the server. You can listen to these events as follows:
-
Integration with
RoomClient
Internally,DeveloperClient
uses the sameProtocol
instance attached toRoomClient
to send and receive developer-related messages. IfRoomClient
is disconnected, messages will not be delivered. -
Error Handling
If a request fails or the server returns an error, the underlyingRoomClient
may throw an exception (e.g.,RoomServerException
). Handle it accordingly in your code:
- Extensibility
You can extend or wrapDeveloperClient
to include additional developer-oriented features, such as profiling, advanced filtering, or forwarding logs to other services.
Was this page helpful?