# simple-room

> ## Server

Latest version **3.1.3** (published 2024-01-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-room
pnpm add simple-room
yarn add simple-room
bun add simple-room
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.3 |
| Published | 2024-01-15 |
| First published | 2022-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 154.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Samuel Ronce |
| Maintainers | webcreative5 |

## Links

- npm: https://www.npmjs.com/package/simple-room
- npm.io page: https://npm.io/package/simple-room

## Dependencies (3)

- [rxjs](https://npm.io/package/rxjs.md) 7.8.1
- [msgpack-lite](https://npm.io/package/msgpack-lite.md) 0.1.26
- [@google-cloud/agones-sdk](https://npm.io/package/@google-cloud/agones-sdk.md) ^1.35.0

## Recent versions

- 3.1.3 (latest) — 2024-01-15
- 3.1.2 — 2024-01-12
- 3.1.1 — 2023-12-08
- 3.1.0 — 2023-12-08
- 3.0.6 — 2023-12-04
- 3.0.5 — 2023-12-03
- 3.0.4 — 2023-12-03
- 3.0.3 — 2023-12-02
- 3.0.2 — 2023-11-27
- 3.0.1 — 2023-11-27
- 3.0.0 — 2023-10-20
- 2.4.1 — 2023-08-22
- 2.4.0 — 2023-08-22
- 2.3.2 — 2023-07-25
- 2.3.1 — 2023-07-24
- … 12 more at https://npm.io/package/simple-room/versions

## README

# How use it ?

## Server

1. Create just a class :

```js
class Page {

}
```

2. Add this room in World:

```js
import { World } from './world'

World.transport(io) // io is socket.io variable
const room = Word.addRoom('room_id', new Page())
```

3. Send packets to client:

```ts
setInterval(() => {
    World.send()
}, 20)
```

## Client

With `socket.io`

```html
<script src="sync-client.js"></script>
```

```js
const socket = io()
socket.emit(':join', 'room_id')
World.listen(socket).value.subscribe((val: { data: any, partial: any }) => {
    console.log(val)
})
```

# Add Room Properties:

```js
class Page {
    $schema = {
        title: String
    }
    title = ''
}
```

After adding the room, if you change the property, it will be transmitted to everyone.


```js
const room = Word.addRoom('room_id', Page)
room.title = 'my app' // is send to users in room
```

# Define Schema

## Normal Schema

Typescript
```ts
@Schema({
    title: String
})
export class Page {
    title: string = ''
}
```

Javascript
```js
export class Page {
    $schema = {
        title: String
    }
    title = ''
}
```

## Array Properties

Typescript
```ts
@Schema({
     list: [String]
})
export class Page {
    title: string[] = ['yo']
}
```

Javascript
```js
export class Page {
    $schema = {
        list: [String]
    }
    title = ['yo']
}
```

## with collection :

Typescript
```ts
@Schema({
     list: [{ id: Number, name: String }]
})
export class Page {
    list: { id: Number, name: String }[] = []
    constructor() {
        this.list.push({
            id: 1,
            name: 'yo'
        })
    }
}
```

Javascript
```js
export class Page {
    $schema = {
        list: [{ id: Number, name: String }]
    }
    list = []
    
    constructor() {
        this.list.push({
            id: 1,
            name: 'yo'
        })
    }
}
```

## Object generic key

Typescript
```ts
@Schema({
     list: [{ id: Number }]
})
export class Page {
    list: any = {}
    constructor() {
        this.list['mykey'] = {
            id: 1
        }
    }
}
```

Javascript
```js
export class Page {
    $schema = {
        list: [{ id: Number }]
    } 
    list = {}
    
    constructor() {
        this.list['mykey'] = {
            id: 1
        }
    }
}
```

---
_Source: https://npm.io/package/simple-room · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
