3.0.0-rc • Published 2 years ago
@rpgjs/sync-server v3.0.0-rc
How use it ?
Server
- Create just a class :
class Page {
}
- Add this room in World:
import { World } from './world'
World.transport(io) // io is socket.io variable
const room = Word.addRoom('room_id', new Page())
- Send packets to client:
setInterval(() => {
World.send()
}, 20)
Client
With socket.io
<script src="sync-client.js"></script>
const socket = io()
socket.emit(':join', 'room_id')
World.listen(socket).value.subscribe((val: { data: any, partial: any }) => {
console.log(val)
})
Add Room Properties:
class Page {
$schema = {
title: String
}
title = ''
}
After adding the room, if you change the property, it will be transmitted to everyone.
const room = Word.addRoom('room_id', Page)
room.title = 'my app' // is send to users in room
Define Schema
Normal Schema
Typescript
@Schema({
title: String
})
export class Page {
title: string = ''
}
Javascript
export class Page {
$schema = {
title: String
}
title = ''
}
Array Properties
Typescript
@Schema({
list: [String]
})
export class Page {
title: string[] = ['yo']
}
Javascript
export class Page {
$schema = {
list: [String]
}
title = ['yo']
}
with collection :
Typescript
@Schema({
list: [{ id: Number, name: String }]
})
export class Page {
list: { id: Number, name: String }[] = []
constructor() {
this.list.push({
id: 1,
name: 'yo'
})
}
}
Javascript
export class Page {
$schema = {
list: [{ id: Number, name: String }]
}
list = []
constructor() {
this.list.push({
id: 1,
name: 'yo'
})
}
}
Object generic key
Typescript
@Schema({
list: [{ id: Number }]
})
export class Page {
list: any = {}
constructor() {
this.list['mykey'] = {
id: 1
}
}
}
Javascript
export class Page {
$schema = {
list: [{ id: Number }]
}
list = {}
constructor() {
this.list['mykey'] = {
id: 1
}
}
}
3.0.0-rc
2 years ago
3.0.0-beta.9
2 years ago
3.0.0-beta.9.1
2 years ago
3.0.0-beta.7
3 years ago
3.0.0-beta.6
3 years ago
3.0.0-beta.8
3 years ago
3.0.0-beta.5
3 years ago
3.0.0-beta.3
3 years ago
3.0.0-beta.4
3 years ago
3.0.0-beta.2
3 years ago
3.0.0-beta-1
3 years ago
3.0.0-beta
3 years ago
3.0.0-alpha.13
3 years ago
3.0.0-alpha.12
3 years ago
3.0.0-alpha.11
3 years ago
3.0.0-alpha.10
3 years ago
3.0.0-alpha.9
3 years ago
3.0.0-alpha.7
4 years ago
3.0.0-alpha.8
4 years ago
3.0.0-alpha.6
4 years ago
3.0.0-alpha.5
4 years ago
3.0.0-alpha.5.1
4 years ago
3.0.0-alpha.4.4
4 years ago
3.0.0-alpha.4.2
4 years ago
3.0.0-alpha.4.3
4 years ago
3.0.0-alpha.3
4 years ago
3.0.0-alpha.2
4 years ago
3.0.0-alpha.1
4 years ago
3.0.0-alpha
4 years ago