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

PropertyTypeDescription
socketgeckos.io socketThe underlying WebRTC socket
pingnumberCurrent round-trip latency in milliseconds
connectedbooleanWhether 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', () => { /* ... */ })