Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/web-sdk-react.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: web-sdk-react

on:
pull_request:
paths:
- 'web-sdk-react/**'
- '.github/workflows/web-sdk-react.yml'
push:
branches: [master]
paths:
- 'web-sdk-react/**'
- '.github/workflows/web-sdk-react.yml'
workflow_dispatch:
inputs:
target:
description: 'Where to deploy'
required: true
type: choice
options: [staging, production]
version:
description: 'Release version for production, e.g. 2.0.0'
required: false
type: string

defaults:
run:
working-directory: web-sdk-react

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 24
cache: yarn
cache-dependency-path: web-sdk-react/yarn.lock

- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn typecheck
- run: yarn build

image:
needs: check
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Resolve image tag
id: tag
env:
TARGET: ${{ inputs.target }}
VERSION: ${{ inputs.version }}
run: |
if [ "$TARGET" = "production" ]; then
echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' || { echo "version must look like 2.0.0"; exit 1; }
echo "value=$VERSION" >> "$GITHUB_OUTPUT"
else
echo "value=staging-${GITHUB_SHA::8}-$(date +%s)" >> "$GITHUB_OUTPUT"
fi

- uses: docker/setup-buildx-action@v3

- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- uses: docker/build-push-action@v6
with:
context: web-sdk-react
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sdk-demo:${{ steps.tag.outputs.value }}
cache-from: type=gha
cache-to: type=gha,mode=max
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# examples

[WebSDK Typescript](web-sdk-ts/README.md) - A simplest example
- [Web SDK + React](web-sdk-react/README.md) — a complete video-call app with a token backend, live at [sdk-demo.livedigital.space](https://sdk-demo.livedigital.space)
- [Web SDK + TypeScript](web-sdk-ts/README.md) — the simplest example
3 changes: 3 additions & 0 deletions web-sdk-react/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/node_modules
**/dist
.env
8 changes: 8 additions & 0 deletions web-sdk-react/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LIVEDIGITAL_PERSONAL_TOKEN=
LIVEDIGITAL_SPACE_ID=

# LIVEDIGITAL_API_URL=https://moodhood-api.livedigital.space/v1
# LIVEDIGITAL_SIGNALING_URL=
# LIVEDIGITAL_ANALYTICS_URL=
# LIVEDIGITAL_STATIC_URL=https://static.prod.livedigital.space
# PORT=3000
4 changes: 4 additions & 0 deletions web-sdk-react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.env
.idea
21 changes: 21 additions & 0 deletions web-sdk-react/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:24-alpine AS build
WORKDIR /app
COPY package.json yarn.lock ./
COPY client/package.json client/
COPY server/package.json server/
RUN yarn install --frozen-lockfile
COPY client client
RUN yarn workspace client build

FROM node:24-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY package.json yarn.lock ./
COPY client/package.json client/
COPY server/package.json server/
RUN yarn install --frozen-lockfile --production && yarn cache clean
COPY server/src server/src
COPY --from=build /app/client/dist client/dist
USER node
EXPOSE 3000
CMD ["node", "server/src/index.ts"]
87 changes: 87 additions & 0 deletions web-sdk-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# livedigital Web SDK — React example

[Русская версия](#русская-версия)

A reference video-call app built on [`@livedigital/client`](https://www.npmjs.com/package/@livedigital/client).
It runs live at [sdk-demo.livedigital.space](https://sdk-demo.livedigital.space).

- `server/` — a small Node.js backend. It keeps the Personal Token, creates rooms and issues a `signalingToken`
for every participant. The three livedigital API calls live in [`server/src/livedigital.ts`](server/src/livedigital.ts).
- `client/` — a React + Vite + TypeScript app structured with [Feature-Sliced Design](https://feature-sliced.design).

## Run locally

Requires Node.js 24+ and yarn.

1. [Create a Personal Token](https://docs.livedigital.space/docs/tutorials/auth/create_personal_token) and a
[space](https://docs.livedigital.space/docs/tutorials/spaces) for the demo rooms.
2. Configure and start:

```bash
cp .env.example .env # fill in LIVEDIGITAL_PERSONAL_TOKEN and LIVEDIGITAL_SPACE_ID
yarn install
yarn dev # client on http://localhost:5173, API on http://localhost:3000
```

The Personal Token is a management key: it must stay on the server and never reach the browser.

## Where to look

| What | Where |
| --- | --- |
| Room, participant and `signalingToken` on the backend | `server/src/livedigital.ts` |
| Single `Client` instance | `client/src/shared/sdk` |
| Join, state sync, reconnect, subscriptions | `client/src/entities/session` |
| Rendering participants and their tracks | `client/src/entities/peer` |
| Publishing camera and microphone | `client/src/features/local-media` |

## Production build

```bash
docker build -t sdk-demo .
docker run --env-file .env -p 3000:3000 sdk-demo
```

---

## Русская версия

Пример приложения для видеозвонков на [`@livedigital/client`](https://www.npmjs.com/package/@livedigital/client).
Работает на [sdk-demo.livedigital.space](https://sdk-demo.livedigital.space).

- `server/` — небольшой бэкенд на Node.js. Хранит Personal Token, создаёт комнаты и выпускает `signalingToken`
для каждого участника. Три вызова API livedigital лежат в [`server/src/livedigital.ts`](server/src/livedigital.ts).
- `client/` — приложение на React + Vite + TypeScript с архитектурой [Feature-Sliced Design](https://feature-sliced.design).

## Локальный запуск

Нужны Node.js 24+ и yarn.

1. [Создайте Personal Token](https://docs.livedigital.space/docs/tutorials/auth/create_personal_token) и
[пространство](https://docs.livedigital.space/docs/tutorials/spaces) для комнат демо.
2. Настройте и запустите:

```bash
cp .env.example .env # заполните LIVEDIGITAL_PERSONAL_TOKEN и LIVEDIGITAL_SPACE_ID
yarn install
yarn dev # клиент на http://localhost:5173, API на http://localhost:3000
```

Personal Token — управляющий ключ: он живёт только на сервере и не должен попадать в браузер.

## Где что смотреть

| Что | Где |
| --- | --- |
| Комната, участник и `signalingToken` на бэкенде | `server/src/livedigital.ts` |
| Единственный экземпляр `Client` | `client/src/shared/sdk` |
| Вход, синхронизация состояния, реконнект, подписки | `client/src/entities/session` |
| Отрисовка участников и их треков | `client/src/entities/peer` |
| Публикация камеры и микрофона | `client/src/features/local-media` |

## Сборка для продакшена

```bash
docker build -t sdk-demo .
docker run --env-file .env -p 3000:3000 sdk-demo
```
7 changes: 7 additions & 0 deletions web-sdk-react/client/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import reactHooks from 'eslint-plugin-react-hooks';
import tseslint from 'typescript-eslint';

export default tseslint.config(
...tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
);
13 changes: 13 additions & 0 deletions web-sdk-react/client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>livedigital SDK demo</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/app/index.tsx"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions web-sdk-react/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc --noEmit && vite build",
"typecheck": "tsc --noEmit",
"lint": "eslint src",
"lint:fsd": "steiger src"
},
"dependencies": {
"@livedigital/client": "3.63.2",
"events": "^3.3.0",
"i18next": "^27.2.2",
"react": "^19.3.1",
"react-dom": "^19.3.1",
"react-i18next": "^18.0.3",
"react-router": "^7.18.6",
"zustand": "^5.1.0"
},
"devDependencies": {
"@feature-sliced/steiger-plugin": "^0.8.2",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^6.3.0",
"eslint": "^10.15.0",
"eslint-plugin-react-hooks": "^7.1.1",
"steiger": "^0.10.0",
"typescript": "^5.9.0",
"typescript-eslint": "^8.73.0",
"vite": "^8.3.8"
}
}
1 change: 1 addition & 0 deletions web-sdk-react/client/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions web-sdk-react/client/src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BrowserRouter, Navigate, Route, Routes } from 'react-router';
import { HomePage } from '@/pages/home';
import { RoomPage } from '@/pages/room';

export function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/r/:alias" element={<RoomPage />} />
<Route path="*" element={<Navigate to="/" replace />} />
</Routes>
</BrowserRouter>
);
}
18 changes: 18 additions & 0 deletions web-sdk-react/client/src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { bindSessionEvents } from '@/entities/session';
import { demoApi } from '@/shared/api';
import { initI18n } from '@/shared/i18n';
import { createSdkClient } from '@/shared/sdk';
import { App } from './App';
import './styles/index.css';

const [sdkConfig] = await Promise.all([demoApi.getSdkConfig(), initI18n()]);

bindSessionEvents(createSdkClient({ ...sdkConfig, logLevel: 4 }));

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
);
Loading
Loading