You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

simple-room

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-room

## Server


Version published
Weekly downloads
232
increased by22.75%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

How use it ?

Server

  1. Create just a class :
class Page {

}
  1. 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())
  1. 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
        }
    }
}

FAQs

Package last updated on 15 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc