---
title: Lipoic 課堂功能實作討論
image: https://raw.githubusercontent.com/Lipoic/Lipoic-Assets/main/logo/logo.png
lang: zh-tw
tags: 平台開發部,前端組,後端組
---
:::warning
尚未定案
:::
# Lipoic 課堂功能實作討論
#### 章節
- [技術](#技術)
- [API](#API)
- [課堂資料結構](#課堂資料結構)
- [建立課堂](#建立課堂)
- [加入課堂](#加入課堂)
- [結束課堂](#結束課堂)
- [舉手](#舉手)
- [使用者狀態](#使用者狀態)
## 技術
音視訊:WebRTC
文字:Socket.IO
WebRTC Rust 函式庫:https://github.com/webrtc-rs/webrtc
伺服器端範例 (rust):https://github.com/webrtc-rs/webrtc/tree/master/examples/examples/broadcast
SFU 伺服器端實作範例 (rust):https://github.com/webrtc-rs/examples/pull/15
Client 端範例 (js):https://jsfiddle.net/1jc4go7v/
## API
### 課堂資料結構
```json
{
"id": ObjectId, // 課堂 ID
"name": String, // 必填,但若跟教室功能串接會直接引用教室的名稱。
"description": String // 可選
"created_at": Int, // 課堂建立時的 UNIX 時間
"create_by": ObjectId, // 此課堂是由誰建立的 (ID)
"speakers": Vec<ObjectId>, // 講者 ID
"state": String, // draft/open/close enum
"permission": { // 可以加入此課堂的權限
"permission_type": String, // all (所有人) / classroom (在同個教室的人) / select (手動指定) enum
"allows": Vec<ObjectId> // 若 type 為 select 時此欄位才有資料,手動指定的使用者 ID
}
// 額外串接功能
"classroom_id": ObjectId // 可選,用於跟教室串連,等該功能開發完成後再串接進來。
}
```
> [name=菘菘] 歡迎大家提供關於此 API 的建議
Payload 實際上是要用 form data,但 highlight 好像不支援,所以暫時用 json 表示。
### 建立課堂
Path: `https://<host>/lesson`
Method: `POST`
Payload
```json
```
Response
```json
{
"id":
}
```
### 加入課堂
Path: `https://<host>/lesson/<id>/join`
Method: `POST`
Payload
```json
{
"client_local_description": <base64_description>
}
```
Response
```json
{
"server_local_description": <base64_description>
}
```
Client 可以再利用伺服器給的 description 去加入 WebRTC 拿影像跟音訊資料
### 結束課堂
### 舉手
Path: `https://<host>/lesson/<id>/user-state`
### 發送課堂訊息
### 收回課堂訊息
## 使用者狀態
用於儲存課堂進行中使用者的狀態,像是舉手之類的。
目前有四種實作方式
- WebRTC (client-client)
- Webhook (server-client)
- Rest API (server-client)
透過資料庫儲存狀態
- Socket.IO (server-client)
存在記憶體 or 資料庫
---
<small>Copyright © 2022 Lipoic. All rights reserved.</small>
{%hackmd @lumynou5/dark-theme %}
<!-- the theme made by Luminous-Coder -->