Compare commits

..

52 Commits

Author SHA1 Message Date
Anthony M
49bf529ea1
fix NODE_ENV port priority (#356) 2023-05-26 19:52:26 +02:00
Milos Vetesnik
b6547a66d7
Maielo/upgrade socket io (#355)
* added cors to env dev

* updated socket.io

* tweaked pm2 configs

* tweaked readme

* slight refactor of index

* removed types for socket.io as it is part of main package

* clean up and setting default ports
2023-05-16 14:35:29 +02:00
Aakansha Doshi
c0bf0ba76c
fix: update port to 3002 to avoid conflict with excalidraw local setup (#305) 2022-01-11 18:39:40 +05:30
dwelle
c3ea2431cb fix lint 2021-10-28 16:27:21 +02:00
dwelle
89ff6477f7 update readme 2021-10-28 15:55:46 +02:00
dwelle
c07fcccc69 use yarn 2021-10-28 15:55:42 +02:00
dwelle
1db3508386 set NODE_ENV in dev and bump ts-node-dev 2021-10-28 15:41:23 +02:00
Maielo
0ce66b4d52 [dev] updated git ignore 2021-10-17 22:33:32 +02:00
Maielo
193cfcc412 [feat] added pm2 configs & .env for port 2021-10-17 22:31:14 +02:00
dependabot[bot]
8ab964590d
Bump typescript from 4.2.2 to 4.2.3 (#177)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.2.2 to 4.2.3.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.2.2...v4.2.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-12 15:28:03 +02:00
dependabot[bot]
a0232caac3
Bump @excalidraw/eslint-config from 1.0.0 to 1.0.1 (#178)
Bumps [@excalidraw/eslint-config](https://github.com/excalidraw/eslint-config) from 1.0.0 to 1.0.1.
- [Release notes](https://github.com/excalidraw/eslint-config/releases)
- [Commits](https://github.com/excalidraw/eslint-config/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-12 15:27:55 +02:00
Lipis
c0eeac3feb
feat: Add ESLint (#176) 2021-03-03 10:25:30 +02:00
dependabot[bot]
cbda52be05
Bump @excalidraw/prettier-config from 1.0.1 to 1.0.2 (#175)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-03 10:23:00 +02:00
Panayiotis Lipiridis
64f5aa5ac0 Lock 2021-02-27 12:50:05 +02:00
Panayiotis Lipiridis
637e0df159 Use @excalidraw/prettier-config 2021-02-25 14:01:49 +02:00
dependabot[bot]
e55bdd93d5
Bump @types/node from 14.14.28 to 14.14.31 (#171)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.28 to 14.14.31.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-02-25 13:59:07 +02:00
dependabot[bot]
f2bad1f8a8
Bump @types/node from 14.14.25 to 14.14.28 (#170)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.25 to 14.14.28.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-02-15 12:49:32 +02:00
dependabot[bot]
8a98340552
Bump typescript from 4.1.3 to 4.1.5 (#169)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.1.3 to 4.1.5.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.1.3...v4.1.5)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-02-15 12:49:24 +02:00
dependabot[bot]
a7c9c35a3c
Bump @types/node from 14.14.22 to 14.14.25 (#168)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.22 to 14.14.25.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-02-09 16:00:17 +02:00
Panayiotis Lipiridis
5b174809e6 const 2021-02-07 13:47:01 +02:00
Lipis
2d8d11e706
feat: Add ts-node-dev (#166) 2021-02-07 13:44:57 +02:00
Lipis
ed1862dab8
Add test images (#165) 2021-02-07 11:18:30 +02:00
Lipis
fc6f1f5228
Revert "Bump socket.io from 2.3.0 to 2.4.0" (#163)
This reverts commit adc27425d4519342063ac5f4154df954bea05d96.
2021-02-05 00:27:36 +02:00
dependabot[bot]
adc27425d4
Bump socket.io from 2.3.0 to 2.4.0 (#162)
Bumps [socket.io](https://github.com/socketio/socket.io) from 2.3.0 to 2.4.0.
- [Release notes](https://github.com/socketio/socket.io/releases)
- [Changelog](https://github.com/socketio/socket.io/blob/2.4.0/CHANGELOG.md)
- [Commits](https://github.com/socketio/socket.io/compare/2.3.0...2.4.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-02-04 23:29:05 +02:00
dependabot[bot]
ddd05855a2
Bump @types/node from 14.14.21 to 14.14.22 (#160)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.21 to 14.14.22.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-01-28 02:07:30 +02:00
Panayiotis Lipiridis
eadbf5e0a5 Update readme and prettier 2021-01-19 13:25:36 +02:00
Panayiotis Lipiridis
e4626960ad Test and build 2021-01-19 01:24:57 +02:00
Panayiotis Lipiridis
073c12197d Remove comments 2021-01-19 01:20:09 +02:00
Panayiotis Lipiridis
1a63db89f2 Clean up 2021-01-19 01:19:39 +02:00
Panayiotis Lipiridis
c1651aea2d lock 2021-01-19 00:33:23 +02:00
Lipis
a0d2a5b82a
GitHub actions and some cleanup (#158) 2021-01-19 00:31:56 +02:00
dependabot[bot]
c6b867d888
Bump typescript from 3.9.5 to 4.1.3 (#153)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.9.5 to 4.1.3.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v3.9.5...v4.1.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-01-18 22:43:11 +02:00
Lipis
f977554cb7
Revert "Bump @types/socket.io from 2.1.4 to 2.1.12" (#156)
This reverts commit 2c6829ec350cc51fad14b4d8f331299e270112c5.
2021-01-18 22:41:52 +02:00
dependabot[bot]
2c6829ec35
Bump @types/socket.io from 2.1.4 to 2.1.12 (#155)
Bumps [@types/socket.io](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/socket.io) from 2.1.4 to 2.1.12.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/socket.io)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-01-18 22:40:16 +02:00
dependabot[bot]
dc7be43a17
Bump eslint-plugin-prettier from 3.1.4 to 3.3.1 (#151)
Bumps [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) from 3.1.4 to 3.3.1.
- [Release notes](https://github.com/prettier/eslint-plugin-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-plugin-prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/eslint-plugin-prettier/compare/v3.1.4...v3.3.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-01-18 22:37:48 +02:00
dependabot[bot]
528be0daad
Bump @types/express from 4.17.6 to 4.17.11 (#154)
Bumps [@types/express](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/express) from 4.17.6 to 4.17.11.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/express)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-01-18 22:37:27 +02:00
Lipis
7c0077297a
Update dependabot.yml 2021-01-18 22:34:20 +02:00
Lipis
8735e79948
Create dependabot.yml 2021-01-18 22:33:00 +02:00
dependabot[bot]
6b120dfa9c
Bump lodash from 4.17.15 to 4.17.20 (#150)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.20.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.20)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-01-18 22:22:59 +02:00
dependabot-preview[bot]
c9893af409
Bump prettier from 2.0.5 to 2.2.1 (#139)
Bumps [prettier](https://github.com/prettier/prettier) from 2.0.5 to 2.2.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.0.5...2.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-01-18 22:22:25 +02:00
dependabot-preview[bot]
b341513c3e
Bump debug from 4.1.1 to 4.3.1 (#133)
Bumps [debug](https://github.com/visionmedia/debug) from 4.1.1 to 4.3.1.
- [Release notes](https://github.com/visionmedia/debug/releases)
- [Commits](https://github.com/visionmedia/debug/compare/4.1.1...4.3.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-01-18 22:22:16 +02:00
dependabot-preview[bot]
21377392e1
[Security] Bump lodash from 4.17.15 to 4.17.20 (#117)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.20. **This update includes security fixes.**
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.20)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-01-18 22:21:58 +02:00
dependabot-preview[bot]
95761911e3
Bump @types/node from 13.9.8 to 14.14.12 (#146)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 13.9.8 to 14.14.12.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-01-18 22:21:39 +02:00
dependabot-preview[bot]
fc9d626899
Bump eslint-config-prettier from 6.10.1 to 7.0.0 (#142)
Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 6.10.1 to 7.0.0.
- [Release notes](https://github.com/prettier/eslint-config-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/eslint-config-prettier/compare/v6.10.1...v7.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-01-18 22:21:30 +02:00
David Luzar
dda25d7920
Merge pull request #149 from excalidraw/fix_cors 2021-01-14 14:29:59 +01:00
dwelle
1cc554339d fix lint 2021-01-14 12:23:07 +01:00
dwelle
1de26f690b fallback to excalidraw.com if no origin header present 2021-01-14 12:22:52 +01:00
dwelle
c970c74a2b fix: ensure non-* CORS origin header is set if no req headers sent 2021-01-14 12:10:45 +01:00
David Luzar
cc4a6ce1b9
Merge pull request #148 from excalidraw/add_root 2020-12-28 12:38:27 +01:00
David Luzar
480c9ff00a
Update src/index.ts
Co-authored-by: Lipis <lipiridis@gmail.com>
2020-12-28 12:37:47 +01:00
David Luzar
dba4e6e137
Update src/index.ts 2020-12-28 12:37:32 +01:00
dwelle
2374d0956d add root route 2020-12-28 12:36:46 +01:00
17 changed files with 1016 additions and 602 deletions

2
.env.development Normal file
View File

@ -0,0 +1,2 @@
PORT=
CORS_ORIGIN=

3
.eslintrc.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "@excalidraw/eslint-config"
}

8
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
day: sunday
time: "01:00"

View File

@ -2,23 +2,17 @@ name: Lint
on:
push:
branches:
- master
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup Node.js 12.x
- name: Setup Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install and lint
run: |
yarn
yarn lint
node-version: 14.x
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Lint
run: yarn test:other

View File

@ -8,7 +8,6 @@ on:
jobs:
publish-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/build-push-action@v1

20
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,20 @@
name: Test & Build
on:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Test and Build
run: |
yarn test:code
yarn build

1
.gitignore vendored
View File

@ -71,6 +71,7 @@ typings/
# dotenv environment variables file
.env
.env.test
.env.production
# parcel-bundler cache (https://parceljs.org/)
.cache

View File

@ -1 +0,0 @@
{}

View File

@ -1,3 +1,27 @@
# collab-server
# Example of excalidraw collaboration server
Excalidraw collaboration server
Collaboration server for Excalidraw
If you need to use cluster mode with pm2. Checkout: https://socket.io/docs/v4/pm2/
If you are not familiar with pm2: https://pm2.keymetrics.io/docs/usage/quick-start/
# Development
- install
```sh
yarn
```
- run development server
```sh
yarn start:dev
```
# Start with pm2
```
pm2 start pm2.production.json
```

View File

@ -1,72 +1,39 @@
{
"name": "excalidraw-room",
"version": "1.0.0",
"description": "Excalidraw collaboration server",
"main": "index.js",
"dependencies": {
"@excalidraw/eslint-config": "1.0.1",
"@excalidraw/prettier-config": "1.0.2",
"@types/debug": "4.1.5",
"@types/express": "4.17.11",
"@types/node": "14.14.31",
"@typescript-eslint/eslint-plugin": "4.16.1",
"@typescript-eslint/parser": "4.16.1",
"cross-env": "^7.0.3",
"debug": "4.3.1",
"dotenv": "^10.0.0",
"eslint": "7.21.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-prettier": "3.3.1",
"express": "4.17.1",
"prettier": "2.2.1",
"socket.io": "^4.6.1",
"ts-node-dev": "^1.1.8",
"typescript": "4.2.3"
},
"license": "MIT",
"main": "dist/index.js",
"name": "excalidraw-portal",
"prettier": "@excalidraw/prettier-config",
"scripts": {
"build": "tsc",
"fix": "yarn prettier --write",
"lint": "yarn prettier --list-different",
"prettier": "prettier \"**/*.{ts,md,json,yaml,yml}\"",
"fix:code": "yarn test:code --fix",
"fix:other": "yarn prettier --write",
"fix": "yarn fix:other && yarn fix:code",
"prettier": "prettier . --ignore-path=.gitignore",
"start": "node dist/index.js",
"test": "yarn lint"
"start:dev": "cross-env NODE_ENV=development ts-node-dev --respawn --transpile-only src/index.ts",
"test:code": "eslint --ext .ts .",
"test:other": "yarn prettier --list-different",
"test": "yarn test:other && yarn test:code"
},
"repository": {
"type": "git",
"url": "git+https://github.com/excalidraw/excalidraw-room.git"
},
"keywords": [],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/excalidraw/excalidraw-room/issues"
},
"homepage": "https://github.com/excalidraw/excalidraw-room#readme",
"dependencies": {
"debug": "4.1.1",
"eslint": "7.3.1",
"eslint-config-prettier": "6.10.1",
"eslint-plugin-prettier": "3.1.4",
"express": "4.17.1",
"prettier": "2.0.5",
"socket.io": "2.3.0"
},
"devDependencies": {
"@types/socket.io": "2.1.4",
"@types/debug": "4.1.5",
"@types/express": "4.17.6",
"@types/node": "13.9.8",
"typescript": "4.1.2"
},
"eslintConfig": {
"extends": [
"prettier"
],
"plugins": [
"prettier"
],
"rules": {
"curly": "warn",
"no-console": [
"warn",
{
"allow": [
"warn",
"error",
"info"
]
}
],
"no-else-return": "warn",
"no-useless-return": "warn",
"prefer-const": [
"warn",
{
"destructuring": "all"
}
],
"prefer-template": "warn",
"prettier/prettier": "warn"
}
}
"version": "1.0.0"
}

14
pm2.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "excalidraw-collab-dev",
"script": "./dist/index.js",
"watch": ["src/"],
"ignore_watch": ["node_modules", "public"],
"autorestart": false,
"exec_mode": "fork_mode",
"instances": 1,
"env": {
"NODE_ENV": "development",
"TZ": "Europe/London"
},
"node_args": ["--inspect=127.0.0.1:9320"]
}

15
pm2.production.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "excalidraw-collab",
"script": "./dist/index.js",
"ignore_watch": ["node_modules", "public"],
"max_memory_restart": "4G",
"watch": false,
"wait_ready": true,
"log_date_format": "YYYY-MM-DD HH:mm Z",
"autorestart": true,
"exec_mode": "fork_mode",
"instances": 1,
"env": {
"NODE_ENV": "production"
}
}

BIN
public/test128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
public/test256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

BIN
public/test64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -1,14 +1,27 @@
import express from "express";
import http, { ServerResponse } from "http";
import socketIO from "socket.io";
import debug from "debug";
import express from "express";
import http from "http";
import { Server as SocketIO } from "socket.io";
const serverDebug = debug("server");
const ioDebug = debug("io");
const socketDebug = debug("socket");
require("dotenv").config(
process.env.NODE_ENV !== "development"
? { path: ".env.production" }
: { path: ".env.development" },
);
const app = express();
const port = process.env.PORT || 80; // default port to listen
const port =
process.env.PORT || (process.env.NODE_ENV !== "development" ? 80 : 3002); // default port to listen
app.use(express.static("public"));
app.get("/", (req, res) => {
res.send("Excalidraw collaboration server is up :)");
});
const server = http.createServer(app);
@ -16,66 +29,76 @@ server.listen(port, () => {
serverDebug(`listening on port: ${port}`);
});
const io = socketIO(server, {
handlePreflightRequest: function (req, res) {
var headers = {
"Access-Control-Allow-Headers": "Content-Type, Authorization",
"Access-Control-Allow-Origin": req.header ? req.header.origin : "*",
"Access-Control-Allow-Credentials": true,
};
res.writeHead(200, headers);
res.end();
},
});
io.on("connection", (socket) => {
ioDebug("connection established!");
io.to(`${socket.id}`).emit("init-room");
socket.on("join-room", (roomID) => {
socketDebug(`${socket.id} has joined ${roomID}`);
socket.join(roomID);
if (io.sockets.adapter.rooms[roomID].length <= 1) {
io.to(`${socket.id}`).emit("first-in-room");
} else {
socket.broadcast.to(roomID).emit("new-user", socket.id);
}
io.in(roomID).emit(
"room-user-change",
Object.keys(io.sockets.adapter.rooms[roomID].sockets)
);
try {
const io = new SocketIO(server, {
transports: ["websocket", "polling"],
cors: {
allowedHeaders: ["Content-Type", "Authorization"],
origin: process.env.CORS_ORIGIN || "*",
credentials: true,
},
allowEIO3: true,
});
socket.on(
"server-broadcast",
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
socketDebug(`${socket.id} sends update to ${roomID}`);
socket.broadcast.to(roomID).emit("client-broadcast", encryptedData, iv);
}
);
socket.on(
"server-volatile-broadcast",
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
socketDebug(`${socket.id} sends volatile update to ${roomID}`);
socket.volatile.broadcast
.to(roomID)
.emit("client-broadcast", encryptedData, iv);
}
);
socket.on("disconnecting", () => {
const rooms = io.sockets.adapter.rooms;
for (const roomID in socket.rooms) {
const clients = Object.keys(rooms[roomID].sockets).filter(
(id) => id !== socket.id
);
if (clients.length > 0) {
socket.broadcast.to(roomID).emit("room-user-change", clients);
io.on("connection", (socket) => {
ioDebug("connection established!");
io.to(`${socket.id}`).emit("init-room");
socket.on("join-room", async (roomID) => {
socketDebug(`${socket.id} has joined ${roomID}`);
await socket.join(roomID);
const sockets = await io.in(roomID).fetchSockets();
if (sockets.length <= 1) {
io.to(`${socket.id}`).emit("first-in-room");
} else {
socketDebug(`${socket.id} new-user emitted to room ${roomID}`);
socket.broadcast.to(roomID).emit("new-user", socket.id);
}
}
});
socket.on("disconnect", () => {
socket.removeAllListeners();
io.in(roomID).emit(
"room-user-change",
sockets.map((socket) => socket.id),
);
});
socket.on(
"server-broadcast",
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
socketDebug(`${socket.id} sends update to ${roomID}`);
socket.broadcast.to(roomID).emit("client-broadcast", encryptedData, iv);
},
);
socket.on(
"server-volatile-broadcast",
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
socketDebug(`${socket.id} sends volatile update to ${roomID}`);
socket.volatile.broadcast
.to(roomID)
.emit("client-broadcast", encryptedData, iv);
},
);
socket.on("disconnecting", async () => {
socketDebug(`${socket.id} has disconnected`);
for (const roomID in socket.rooms) {
const otherClients = (await io.in(roomID).fetchSockets()).filter(
(_socket) => _socket.id !== socket.id,
);
if (otherClients.length > 0) {
socket.broadcast.to(roomID).emit(
"room-user-change",
otherClients.map((socket) => socket.id),
);
}
}
});
socket.on("disconnect", () => {
socket.removeAllListeners();
socket.disconnect();
});
});
});
} catch (error) {
console.error(error);
}

1261
yarn.lock

File diff suppressed because it is too large Load Diff