Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot-preview[bot]
34aca18699
Bump typescript from 3.9.5 to 4.1.2
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.9.5 to 4.1.2.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v3.9.5...v4.1.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-20 09:45:43 +00:00
17 changed files with 601 additions and 1015 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,20 +0,0 @@
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,7 +71,6 @@ typings/
# dotenv environment variables file
.env
.env.test
.env.production
# parcel-bundler cache (https://parceljs.org/)
.cache

1
.prettierrc Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -1,27 +1,3 @@
# Example of excalidraw collaboration server
# collab-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
```
Excalidraw collaboration server

View File

@ -1,39 +1,72 @@
{
"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",
"name": "excalidraw-room",
"version": "1.0.0",
"description": "Excalidraw collaboration server",
"main": "index.js",
"scripts": {
"build": "tsc",
"fix:code": "yarn test:code --fix",
"fix:other": "yarn prettier --write",
"fix": "yarn fix:other && yarn fix:code",
"prettier": "prettier . --ignore-path=.gitignore",
"fix": "yarn prettier --write",
"lint": "yarn prettier --list-different",
"prettier": "prettier \"**/*.{ts,md,json,yaml,yml}\"",
"start": "node dist/index.js",
"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"
"test": "yarn lint"
},
"version": "1.0.0"
"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"
}
}
}

View File

@ -1,14 +0,0 @@
{
"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"]
}

View File

@ -1,15 +0,0 @@
{
"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"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -1,27 +1,14 @@
import debug from "debug";
import express from "express";
import http from "http";
import { Server as SocketIO } from "socket.io";
import http, { ServerResponse } from "http";
import socketIO from "socket.io";
import debug from "debug";
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 || (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 port = process.env.PORT || 80; // default port to listen
const server = http.createServer(app);
@ -29,76 +16,66 @@ server.listen(port, () => {
serverDebug(`listening on port: ${port}`);
});
try {
const io = new SocketIO(server, {
transports: ["websocket", "polling"],
cors: {
allowedHeaders: ["Content-Type", "Authorization"],
origin: process.env.CORS_ORIGIN || "*",
credentials: true,
},
allowEIO3: true,
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)
);
});
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(
"server-broadcast",
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
socketDebug(`${socket.id} sends update to ${roomID}`);
socket.broadcast.to(roomID).emit("client-broadcast", encryptedData, iv);
}
);
io.in(roomID).emit(
"room-user-change",
sockets.map((socket) => socket.id),
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
);
});
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),
);
}
if (clients.length > 0) {
socket.broadcast.to(roomID).emit("room-user-change", clients);
}
});
socket.on("disconnect", () => {
socket.removeAllListeners();
socket.disconnect();
});
}
});
} catch (error) {
console.error(error);
}
socket.on("disconnect", () => {
socket.removeAllListeners();
});
});

1261
yarn.lock

File diff suppressed because it is too large Load Diff