查看设备实时音视频
以查看设备实时音视频为例,可以跟随下面的文档走完一次完整对接流程:
- 启动设备端示例
- 生成连接 token
- 用客户端连接设备并播放音视频
前置准备
| 准备项 | 用在哪里 | 需要准备 |
|---|---|---|
| 应用级凭证 | 生成连接 token | AccessKeyId、SecretKeyId、AppId |
| 设备身份 | 启动设备端示例、生成连接 token | device_id、device_secret_key |
| 基础工具 | 拉取示例、安装 DevTools CLI | Git、Node.js / npm |
| 设备端运行环境 | 启动 C 设备端示例 | 一台 Linux x86_64 电脑;或一台 macOS / Windows 电脑并已安装 Docker Desktop / 其他可用 Docker Engine |
| 客户端运行环境 | 启动 Flutter Android 客户端示例 | 直接安装预编译 APK 时,Android 手机能安装应用即可;从源码运行时,需要 Flutter、Android SDK、ADB,并能通过 flutter devices 识别手机 |
1. 启动设备端示例
先拉取设备端示例:
bash
mkdir -p tirtc-demo
cd tirtc-demo
git clone https://github.com/tangeai/tirtc-example-device.git
cd tirtc-example-devicemacOS、Windows 或非 Linux x86_64 环境使用 Docker 路径:
bash
./script/prepare_in_docker.sh
./script/run_demo_in_docker.sh \
--device-id "your_device_id" \
--device-secret-key "your_device_secret_key"Linux x86_64 环境可以直接运行:
bash
./script/prepare.sh
./script/build.sh
./script/run_demo.sh \
--device-id "your_device_id" \
--device-secret-key "your_device_secret_key"如果使用的不是默认接入环境,需要加上 --endpoint "your_endpoint",比如:
bash
./script/prepare.sh
./script/build.sh
./script/run_demo.sh \
--endpoint "http://ep-test-tirtc.tange365.com" \
--device-id "your_device_id" \
--device-secret-key "your_device_secret_key"看到下面日志后,保持这个终端打开,等待客户端连接:
text
[demo] TiRTC started, waiting for client connections2. 生成连接 token
安装或更新 DevTools CLI:
bash
npm install -g tirtc-devtools-cli@latest配置用于签发 token 的应用级凭证:
bash
export TIRTC_ACCESS_KEY_ID="your_access_key_id"
export TIRTC_SECRET_KEY_ID="your_secret_key_id"
export TIRTC_APP_ID="your_app_id"为刚才启动的设备,生成一个连接 token。
由于当前场景是连接一个设备端,下面的 remote_id 取值为 device_id:
bash
tirtc-devtools-cli token issue remote_id比如:
bash
tirtc-devtools-cli token issue TIRTCDEVICE1如果使用的是非默认接入环境,需要指定endpoint 以及 openapi-endpoint:
bash
tirtc-devtools-cli token issue your_remote_id \
--endpoint "your_endpoint" \
--openapi-endpoint "your_openapi_endpoint"比如:
bash
tirtc-devtools-cli token issue your_remote_id \
--endpoint http://ep-test-tirtc.tange365.com \
--openapi-endpoint http://api-test-tirtc.tange365.comCLI 会输出 token、终端二维码和本地二维码 PNG 路径。
3. 启动客户端并扫码播放
选择一种方式启动 Android 客户端。
方式 A:安装预编译 APK
在 Android 手机上安装并打开:
方式 B:从源码运行
bash
cd tirtc-demo
git clone https://github.com/tangeai/tirtc-example-flutter.git
cd tirtc-example-flutter
flutter pub get
flutter devices
flutter run -d your_android_device_id将客户端运行起来之后:
- 点击右上角「扫一扫」
- 允许相机权限
- 扫描 CLI 输出的二维码,或扫描二维码 PNG
- 回到配置页后,确认
app_id、remote_id、token已填充 audio_stream_id和video_stream_id留空- 点击「进入播放页」
看到视频画面即表示 Demo 跑通。设备端终端会出现类似日志:
text
[demo] client connection accepted
[demo] first video frame sent
[demo] first audio packet sent