├── .github
└── workflows
│ ├── codeql-analysis.yml
│ ├── main.yml
│ └── size.yml
├── .gitignore
├── LICENSE
├── README.md
├── errors
└── no-provider.md
├── example
├── .npmignore
├── index.html
├── index.tsx
├── package.json
├── server.js
├── tsconfig.json
└── yarn.lock
├── misc
└── logo.png
├── package.json
├── src
├── RoomServiceProvider.tsx
├── contextForClient.tsx
├── errors.tsx
├── index.tsx
├── useList.tsx
├── useMap.tsx
├── usePresence.tsx
└── useRoom.tsx
├── tsconfig.json
└── yarn.lock
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | # ******** NOTE ********
12 |
13 | name: "CodeQL"
14 |
15 | on:
16 | push:
17 | branches: [ master ]
18 | pull_request:
19 | # The branches below must be a subset of the branches above
20 | branches: [ master ]
21 | schedule:
22 | - cron: '20 20 * * 4'
23 |
24 | jobs:
25 | analyze:
26 | name: Analyze
27 | runs-on: ubuntu-latest
28 |
29 | strategy:
30 | fail-fast: false
31 | matrix:
32 | language: [ 'javascript' ]
33 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
34 | # Learn more...
35 | # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
36 |
37 | steps:
38 | - name: Checkout repository
39 | uses: actions/checkout@v2
40 |
41 | # Initializes the CodeQL tools for scanning.
42 | - name: Initialize CodeQL
43 | uses: github/codeql-action/init@v1
44 | with:
45 | languages: ${{ matrix.language }}
46 | # If you wish to specify custom queries, you can do so here or in a config file.
47 | # By default, queries listed here will override any specified in a config file.
48 | # Prefix the list here with "+" to use these queries and those in the config file.
49 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
50 |
51 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
52 | # If this step fails, then you should remove it and run the build manually (see below)
53 | - name: Autobuild
54 | uses: github/codeql-action/autobuild@v1
55 |
56 | # ℹ️ Command-line programs to run using the OS shell.
57 | # 📚 https://git.io/JvXDl
58 |
59 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
60 | # and modify them (or add more) to build your code if your project
61 | # uses a compiled language
62 |
63 | #- run: |
64 | # make bootstrap
65 | # make release
66 |
67 | - name: Perform CodeQL Analysis
68 | uses: github/codeql-action/analyze@v1
69 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on: [push]
3 | jobs:
4 | build:
5 | name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}
6 |
7 | runs-on: ${{ matrix.os }}
8 | strategy:
9 | matrix:
10 | node: ['10.x', '12.x', '14.x']
11 | os: [ubuntu-latest, windows-latest, macOS-latest]
12 |
13 | steps:
14 | - name: Checkout repo
15 | uses: actions/checkout@v2
16 |
17 | - name: Use Node ${{ matrix.node }}
18 | uses: actions/setup-node@v1
19 | with:
20 | node-version: ${{ matrix.node }}
21 |
22 | - name: Install deps and build (with cache)
23 | uses: bahmutov/npm-install@v1
24 |
25 | - name: Test
26 | run: yarn test --ci --coverage --maxWorkers=2
27 |
28 | - name: Build
29 | run: yarn build
30 |
--------------------------------------------------------------------------------
/.github/workflows/size.yml:
--------------------------------------------------------------------------------
1 | name: size
2 | on: [pull_request]
3 | jobs:
4 | size:
5 | runs-on: ubuntu-latest
6 | env:
7 | CI_JOB_NUMBER: 1
8 | steps:
9 | - uses: actions/checkout@v1
10 | - uses: andresz1/size-limit-action@v1
11 | with:
12 | github_token: ${{ secrets.GITHUB_TOKEN }}
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 | .DS_Store
3 | node_modules
4 | .cache
5 | dist
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Flaque
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | This is the official React client for [Room Service](https://www.roomservice.dev/). Check out the [Documentation](https://www.roomservice.dev/docs/react-getting-started) for help getting started. Also join our official [Room Service Discord](https://discord.com/invite/VdPpp7Mx9u)!
10 |
11 | ## Install
12 |
13 | ```
14 | yarn add @roomservice/react
15 | ```
16 |
17 | ## Usage
18 |
19 | See [the documentation](https://docs.roomservice.dev/docs/guides/react).
20 |
--------------------------------------------------------------------------------
/errors/no-provider.md:
--------------------------------------------------------------------------------
1 | # No Provider
2 |
3 | A hook is being used outside the RoomServiceProvider.
4 |
5 | ## Why you're getting this error
6 |
7 | You're using a Room Service hook such as `useMap`, `useList`, `usePresence` or `useRoom`, without
8 | a `RoomServiceProvider` setup higher up in your project.
9 |
10 | ### You may not have setup a ``
11 |
12 | Typically at the beginning of your project, in an `App.js` file, or `/pages/xyz.js` file, you'll
13 | need to setup the provider:
14 |
15 | ```tsx
16 | import { RoomServiceProvider } from '@roosmervice/react';
17 |
18 | function App() {
19 | return (
20 |
21 | {/* ... */}
22 |
23 | );
24 | }
25 | ```
26 |
27 | ### You may be using a hook inside the same component as ``
28 |
29 | Like other React libraries that use [context](https://reactjs.org/docs/context.html) providers, Room Service's hooks
30 | will only work in the _children_ of your provider.
31 |
32 | This does **NOT** work:
33 |
34 | ```tsx
35 | import { RoomServiceProvider, useMap } from '@roosmervice/react';
36 |
37 | function App() {
38 | // BAD
39 | const [map, setMap] = useMap('myroom', 'mymap');
40 |
41 | return (
42 |
43 | {/* ... */}
44 |
45 | );
46 | }
47 | ```
48 |
49 | This **DOES** work:
50 |
51 | ```tsx
52 | function TheRestOfYourProject() {
53 | // The hook works here, because it's referring to a component
54 | // within the provider's tree.
55 | const [map, setMap] = useMap('myroom', 'mymap');
56 | if (!map) return null;
57 |
58 | return
{map.get('some-key')}
;
59 | }
60 |
61 | function App() {
62 | return (
63 |
64 |
65 |
66 | );
67 | }
68 | ```
69 |
70 | ### You may be using a hook outside of the provider's tree
71 |
72 | You may have your provider setup not on the top level of your project, but farther
73 | down within the project. If you are, be sure that your hooks are used within the tree
74 | of the provider, and not adjacent to it.
75 |
76 | For example, this won't work:
77 |
78 | ```tsx
79 | import { RoomServiceProvider } from '@roosmervice/react';
80 |
81 | function Adjacent() {
82 | // BAD: This won't work!
83 | const [map, setMap] = useMap("myroom", "mymap")
84 |
85 | if (!map) return null;
86 | return