Networking
NetworkManager
Client-side WebRTC connection with ping monitoring.
NetworkManager handles the client-side WebRTC connection to the server via geckos.io.
Getting the instance
NetworkManager is a singleton:
import { NetworkManager } from '@mavonengine/core'
const network = NetworkManager.getInstance()
Properties
| Property | Type | Description |
|---|---|---|
socket | geckos.io socket | The underlying WebRTC socket |
ping | number | Current round-trip latency in milliseconds |
connected | boolean | Whether the client is connected to the server |
Sending commands to the server
Use the socket to send commands:
network.socket.emit('command', {
type: 'move',
direction: { x: 1, y: 0, z: 0 },
})
Receiving state from the server
network.socket.on('state', (data) => {
// Apply server state to local entities
})
Connection events
NetworkManager extends EventEmitter:
network.on('connected', () => { /* ... */ })
network.on('disconnected', () => { /* ... */ })