Appearance
Multiplayer â
WebRTC â
Uva uses WebRTC for multiplayer data/audio and uWebSockets.js for sockets.
To start multiplayer in an instance use:
js
multiplayer.start('vrm_avatars') // can be any name
multiplayer.voiceChat.start()
multiplayer.avatars.start()Multiplayer Objects â
Syncronising and adding objects â
js
// add a multiplayer object, by default this will syncronise objects using their uuid
world.addMultiplayerObject(this)
// to specify a key for sycing set:
this.__multiplayerID = 'some unique key'
// This is useful for objects created at runtime as uuid's may not be identical
// This will syncronise an object's position, rotation, scale each frame
// By default this also called with grab events
this.update = () => {
multiplayer.setObject(object)
}Updating properties â
js
const keyValues = {
objectProperty: 'someValue',
otherProperty: { x: 0, y: 1, z: 3 },
}
// After calling this the property on all peers object will set to these values
multiplayer.objects.setProperties(object, keyValues)Calling object functions â
js
const functionProps = {
x: 10,
otherProperty: { x: 0, y: 1, z: 3 },
}
// After calling this the property on all peers object will set to these values
multiplayer.objects.callFunction(object, 'functionName', functionProps)Humans â
js
multiplayer.connections // an array of humans you are connected withjs
const human = multiplayer.connections[0]
human.username // 'string:id'human.id â
| Name | Type | Description |
|---|---|---|
| id | string | The unique identifier of the peer. |
human.username â
| Name | Type | Description |
|---|---|---|
| username | string | The username of the peer. |
human.receivingAudio â
| Name | Type | Description |
|---|---|---|
| receivingAudio | boolean | Indicates if the peer is currently receiving audio from us |
human.sendingAudio â
| Name | Type | Description |
|---|---|---|
| sendingAudio | boolean | Indicates if the peer is currently sending audio to us |
human.receivingStream â
| Name | Type | Description |
|---|---|---|
| receivingStream | MediaStream | null | The media stream being received from the peer, if any. |
human.sendingStream â
| Name | Type | Description |
|---|---|---|
| sendingStream | MediaStream | null | The media stream being sent to the peer, if any. |
human.onData â
| Name | Type | Description |
|---|---|---|
| onData | Array.<function()> | Callbacks to be executed when data is received from the peer. |
human.onBuffer â
| Name | Type | Description |
|---|---|---|
| onBuffer | Array.<function()> | Callbacks to be executed when a buffer is received from the peer. |
human.onDisconnect â
| Name | Type | Description |
|---|---|---|
| onDisconnect | Array.<function()> | Callbacks to be executed when the peer disconnects. |
human.onConnect â
| Name | Type | Description |
|---|---|---|
| onConnect | Array.<function()> | Callbacks to be executed when the peer successfully connects. |
human.startVoice() â
Starts sending voice data to the peer.
human.stopVoice() â
Stops sending voice data to the peer.
human.sendData(data) â
Sends JSON-serialized data to the peer, if connected.
| Param | Type | Description |
|---|---|---|
| data | any | The data to be sent. |
Events â
multiplayer.onConnect â
| Name | Type | Description |
|---|---|---|
| onConnect | Array.<function()> | An array of callback functions to be executed on connection. |
js
multiplayer.onConnect.push(evt => {
console.log('Now connected with: ', evt)
})multiplayer.onData â
| Name | Type | Description |
|---|---|---|
| onData | Array.<function()> | An array of callback functions to be executed on data receipt. |
js
multiplayer.onData.push(data => {})multiplayer.start(url) â
Starts the multiplayer session. Initializes the client with a given URL and sets the project space to the current editor's project ID.
| Param | Type | Description |
|---|---|---|
| url | string | The URL to start the multiplayer session with. |
multiplayer.stop() â
Stops the multiplayer session. Kills the client connection and marks the multiplayer as disabled.
multiplayer.sendData(data) â
Sends data to all connected connections.
| Param | Type | Description |
|---|---|---|
| data | any | The data to be sent to connections. |