Compare commits

...

10 commits

Author SHA1 Message Date
Kevin Jahns 3acefb8675 10.2.5 2023-03-16 15:28:26 +01:00
Kevin Jahns 12f829e1ce add fly conf 2023-03-16 15:27:49 +01:00
Kevin Jahns 818140c9e4 add new default server - fixes #43 2023-03-16 15:21:39 +01:00
Kevin Jahns 6460662715 10.2.4 2023-01-16 17:00:19 +01:00
Kevin Jahns 88baab219a fix typing issues 2023-01-16 16:59:47 +01:00
Kevin Jahns 4685d36f0c
Merge pull request #38 from exuanbo/fix-generated-type
fix: incorrect generated type of `WebrtcProvider` constructor
2023-01-16 16:49:32 +01:00
Kevin Jahns e3c1a742dd add exports.module field - yjs/yjs#438 2023-01-01 18:40:10 +01:00
exuanbo a60bad8f78
fix: incorrect generated type of WebrtcProvider constructor 2022-07-14 20:23:50 +01:00
Kevin Jahns f100613f41
Add y-webrtc serverless signaling server blog-post 2022-05-11 16:14:57 +02:00
Kevin Jahns f0b929827a 10.2.3 2022-04-24 15:02:41 +02:00
8 changed files with 921 additions and 458 deletions

4
.dockerignore Normal file
View file

@ -0,0 +1,4 @@
Dockerfile
.dockerignore
node_modules
.git

37
Dockerfile Normal file
View file

@ -0,0 +1,37 @@
FROM debian:bullseye as builder
ARG NODE_VERSION=19.7.0
RUN apt-get update; apt install -y curl
RUN curl https://get.volta.sh | bash
ENV VOLTA_HOME /root/.volta
ENV PATH /root/.volta/bin:$PATH
RUN volta install node@${NODE_VERSION}
#######################################################################
RUN mkdir /app
WORKDIR /app
# NPM will not install any package listed in "devDependencies" when NODE_ENV is set to "production",
# to install all modules: "npm install --production=false".
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description
ENV NODE_ENV production
COPY . .
RUN npm install
FROM debian:bullseye
LABEL fly_launch_runtime="nodejs"
COPY --from=builder /root/.volta /root/.volta
COPY --from=builder /app /app
WORKDIR /app
ENV NODE_ENV production
ENV PATH /root/.volta/bin:$PATH
ENV PORT 8080
CMD [ "npm", "run", "start" ]

View file

@ -43,6 +43,8 @@ Peers using the same signaling server will find each other. You can specify seve
const provider = new WebrtcProvider('your-room-name', ydoc, { signaling: ['wss://y-webrtc-ckynwnzncc.now.sh', 'ws://localhost:4444'] })
```
There is also an interesting article about setting up a scalable "serverless" signaling server by Ronny Roeller: https://medium.com/collaborne-engineering/serverless-yjs-72d0a84326a2
### Communication Restrictions
y-webrtc is restricted by the number of peers that the web browser can create. By default, every client is connected to every other client up until the maximum number of conns is reached. The clients will still sync if every client is connected at least indirectly to every other client. Theoretically, y-webrtc allows an unlimited number of users, but at some point it can't be guaranteed anymore that the clients sync any longer**. Because we don't want to be greedy,

View file

@ -4,7 +4,7 @@ import * as Y from 'yjs'
import { WebrtcProvider } from '../src/y-webrtc.js'
const ydoc = new Y.Doc()
const provider = new WebrtcProvider('webrtc-test', ydoc, { signaling: ['ws://localhost:4444'] })
const provider = new WebrtcProvider('webrtc-test', ydoc, { signaling: ['ws://localhost:8080'] })
const yarray = ydoc.getArray()
provider.on('synced', synced => {

37
fly.toml Normal file
View file

@ -0,0 +1,37 @@
# fly.toml file generated for y-webrtc-eu on 2023-03-16T15:02:47+01:00
app = "y-webrtc-eu"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
[experimental]
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

1272
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "y-webrtc",
"version": "10.2.2",
"version": "10.2.5",
"description": "WebRTC provider for Yjs",
"type": "module",
"main": "./dist/y-webrtc.cjs",
@ -13,6 +13,7 @@
"url": "https://github.com/sponsors/dmonad"
},
"exports": {
"module": "./src/y-webrtc.js",
"import": "./src/y-webrtc.js",
"require": "./dist/y-webrtc.cjs"
},
@ -70,7 +71,7 @@
"rollup-cli": "^1.0.9",
"rollup-plugin-terser": "^5.3.1",
"standard": "^14.3.4",
"typescript": "^3.9.10",
"typescript": "^4.4.4",
"yjs": "^13.5.20"
},
"peerDependenies": {

View file

@ -536,6 +536,16 @@ export class SignalingConn extends ws.WebsocketClient {
}
}
/**
* @typedef {Object} ProviderOptions
* @property {Array<string>} [signaling]
* @property {string} [password]
* @property {awarenessProtocol.Awareness} [awareness]
* @property {number} [maxConns]
* @property {boolean} [filterBcConns]
* @property {any} [peerOpts]
*/
/**
* @extends Observable<string>
*/
@ -543,19 +553,13 @@ export class WebrtcProvider extends Observable {
/**
* @param {string} roomName
* @param {Y.Doc} doc
* @param {Object} [opts]
* @param {Array<string>?} [opts.signaling]
* @param {string?} [opts.password]
* @param {awarenessProtocol.Awareness?} [opts.awareness]
* @param {number?} [opts.maxConns]
* @param {boolean?} [opts.filterBcConns]
* @param {any?} [opts.peerOpts]
* @param {ProviderOptions?} opts
*/
constructor (
roomName,
doc,
{
signaling = ['wss://signaling.yjs.dev', 'wss://y-webrtc-signaling-eu.herokuapp.com', 'wss://y-webrtc-signaling-us.herokuapp.com'],
signaling = ['wss://y-webrtc-eu.fly.dev'],
password = null,
awareness = new awarenessProtocol.Awareness(doc),
maxConns = 20 + math.floor(random.rand() * 15), // the random factor reduces the chance that n clients form a cluster