README
ΒΆ
yomo-presence-backend
The open-source presence server for @yomo/presencejs. It supports both WebSocket and WebTransport.
Environment Variables
Env | Description |
---|---|
MESH_ID | The identity of Mesh Node, example: US |
PRESENCE_ADDR | The hosting address of Presence Server, default: 0.0.0.0:4433 |
PRESENCE_TLS_CERT | The file path of TLS certificate for presence server, default: ./tls/lo.yomo.dev/fullchain.cer |
PRESENCE_TLS_KEY | The file path of TLS key for presence server, default: ./tls/lo.yomo.dev/key.pem |
PRESENCE_SENDER | The address of Presence-Sender Server, default: localhost:8080 |
PRESENCE_RECEIVER | The address of Presence-Receiver Server, default: localhost:9090 |
PRESENCE_AUTH_TYPE | The auth type in presence server, options: none/token, default: token |
PRESENCE_JWT_KEY | The JWT key to encrypt the token |
PRESENCE_APP_ID | The app_id of your presence-server |
PRESENCE_APP_SECRET | The app_secret of your presence-server |
YOMO_ENV | The environment of yomo, it's recommended to set production for production environment |
YOMO_TLS_CACERT_FILE | The CA cert issued by YoMo, it's required when YOMO_ENV=production |
YOMO_TLS_CERT_FILE | The TLS cert for yomo client, it's required when YOMO_ENV=production |
YOMO_TLS_KEY_FILE | The TLS key for yomo client, it's required when YOMO_ENV=production |
π Authentication & Authorization
The presence server requires the clients to provide a valid token
before establishing the connection by default.
1. Set the app_id
and app_secret
Use the env PRESENCE_APP_ID
and PRESENCE_APP_SECRET
to set the app_id
and app_secret
.
2. Server-side request to obtain a token
It is important the request the following API /api/v1/auth
on server-side to prevent the app_id
and app_secret
exposed on the frontend.
If you are deploying your frontend project on Vercel
, you could add a Serverless Function in the /api
directory to request the /api/v1/auth
API on server-side.
$ curl -X POST 'https://lo.yomo.dev:4433/api/v1/auth' \
-H 'Content-Type: application/json' \
-d '{
"app_id": "YOUR-APP-ID",
"app_secret": "YOUR-APP-SECRET"
}'
3. Use the token to establish the connection
The token
should be appended to the presence server
URL, f.e. https://lo.yomo.dev:4433?token=YOUR-TOKEN
π¨ Dev on local
If you just want to run the
presence server
on local, it's more convenient to start thepresence server
viadocker-compose -f ./deploy/docker/docker-compose.local.yml up -d
.
0. Prerequisites
1. Install YoMo CLI
$ curl -fsSL "https://bina.egoist.sh/yomorun/cli?name=yomo" | sh
2. Start YoMo Zipper
$ yomo serve -c ./example/single-node/workflow.yaml
2022-01-13 16:44:28.015 [yomo:zipper] Listening SIGTERM/SIGINT...
2022-01-13 16:44:28.027 [core:server] β
[YoMoZipper] Listening on: [::]:9000, QUIC: [v1 draft-29], AUTH: [None]
3. Start Presence Server
(default) token
auth
export PRESENCE_ADDR=0.0.0.0:4433
export PRESENCE_TLS_CERT=./tls/lo.yomo.dev/fullchain.cer
export PRESENCE_TLS_KEY=./tls/lo.yomo.dev/key.pem
export PRESENCE_SENDER=localhost:9000
export PRESENCE_RECEIVER=localhost:9000
export PRESENCE_AUTH_TYPE=token
export PRESENCE_JWT_KEY=YOUR-JWT-KEY
export PRESENCE_APP_ID=YOUR-APP-ID
export PRESENCE_APP_SECRET=YOUR-APP-SECRET
$ go run ./cmd/main.go
2022/01/13 16:45:08 Starting Presence Server 0.0.0.0:4433...
------------Receiver init------------ zipper=localhost:9000
2022/01/13 16:45:08 [core:client] has connected to yomo-source (localhost:9000)
[source] β
Connect to YoMo-Zipper
2022/01/13 16:45:08 [core:client] has connected to PresenceHandler (localhost:9000)
Local test server addresses
- WebTransport: https://lo.yomo.dev:4433
- WebSocket: wss://lo.yomo.dev:4433
π Deployment
The following steps are based on Ubuntu for instance.
Prerequisites
Generate the TLS certificates for Presence Sender
, Presence Receiver
and Presence Server
in production environment.
See this link for details.
1. Install Docker-Compose
See Docker Docs for details.
2. Upload docker-compose.yml
Upload the ./deploy/docker/docker-compose.yml
to your server and replace the environment variables
to your acutal contents.
presence-receiver
- YOMO_ENV: optional, the environment of yomo, it's recommended to set
production
for production environment - YOMO_TLS_CACERT_FILE: optional, the CA cert issued by YoMo, it's required when
YOMO_ENV=production
- YOMO_TLS_CERT_FILE: optional, the TLS cert for yomo server, it's required when
YOMO_ENV=production
- YOMO_TLS_KEY_FILE: optional, the TLS key for yomo server, it's required when ``YOMO_ENV=production`
presence-sender
- PRESENCE_MESH_URL: you have to upload the Mesh config file to your webserver (or S3), see deploy/dev.json for example.
- YOMO_ENV: optional, the environment of yomo, it's recommended to set
production
for production environment - YOMO_TLS_CACERT_FILE: optional, the CA cert issued by YoMo, it's required when
YOMO_ENV=production
- YOMO_TLS_CERT_FILE: optional, the TLS cert for yomo server, it's required when
YOMO_ENV=production
- YOMO_TLS_KEY_FILE: optional, the TLS key for yomo server, it's required when ``YOMO_ENV=production`
presence-server
- MESH_ID: the identity of your mesh node, f.e. US
- PRESENCE_ADDR: The hosting address of
Presence
Server, f.e. 0.0.0.0:4433 - PRESENCE_TLS_CERT: The file path of
TLS certificate
in container. - PRESENCE_TLS_KEY: The file path of
TLS key
in container. - PRESENCE_AUTH_TYPE:
- token: enable JWT token authorization (recommended)
- none: disable the authorization
- PRESENCE_JWT_KEY: optional, it's only required when
PRESENCE_AUTH_TYPE=token
- PRESENCE_APP_ID: optional, it's only required when
PRESENCE_AUTH_TYPE=token
- PRESENCE_APP_SECRET: optional, it's only required when
PRESENCE_AUTH_TYPE=token
- YOMO_ENV: optional, the environment of yomo, it's recommended to set
production
for production environment - YOMO_TLS_CACERT_FILE: optional, the CA cert issued by YoMo, it's required when
YOMO_ENV=production
- YOMO_TLS_CERT_FILE: optional, the TLS cert for yomo client, it's required when
YOMO_ENV=production
- YOMO_TLS_KEY_FILE: optional, the TLS key for yomo client, it's required when ``YOMO_ENV=production`
3. Start presence server
$ docker-compose up -d