### Install dependencies and start the project Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vueVersion/README.md Run these commands in the project root to install dependencies and start the development servers. The start command launches both the Vite dev server (default http://localhost:8084) and a local Node token server (http://localhost:3001). ```bash $ npm install $ npm run start ``` -------------------------------- ### Run audio interaction example Source: https://github.com/aliyun/alirtcsample/blob/master/Python/server_sdk/example2/README_EN.md Starts the audio interaction example, which records voice via microphone and plays model audio through the speaker. Supports interrupting the model's output at any time; headphones are recommended to avoid self-interruption. ```bash python run_server_vad.py ``` -------------------------------- ### Run video interaction example Source: https://github.com/aliyun/alirtcsample/blob/master/Python/server_sdk/example2/README_EN.md Starts the video interaction example, which records voice and captures video via camera, playing model audio through the speaker. Initially, video capture is not active; only voice interaction works until the webcam is opened via the web frontend. ```bash python run_with_camera.py ``` -------------------------------- ### Install rules and commented Qt6 finalization Source: https://github.com/aliyun/alirtcsample/blob/master/Linux/C++/Samples/client/qtdemo/OneRTCQtDemo/CMakeLists.txt Installs the built executable to standard directories and includes commented-out Qt6 finalization code. ```cmake include(GNUInstallDirs) install(TARGETS OneRTCQtDemo BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) # if(QT_VERSION_MAJOR GREATER_EQUAL 6) # qt_finalize_executable(OneRTCQtDemo) # endif() ``` -------------------------------- ### Run non-server_vad mode example Source: https://github.com/aliyun/alirtcsample/blob/master/Python/server_sdk/example2/README_EN.md Simulates a mode without using server_vad, actively controlling when the model responds. Runs multiple conversation rounds, playing audio through the speaker and waiting for playback to finish before starting the next task. ```bash python run_without_server_vad.py ``` -------------------------------- ### 复制 config.json.example 为 config.json Source: https://github.com/aliyun/alirtcsample/blob/master/Android/FullFeatureDemo/src/main/assets/CONFIG_README.md 使用 cp 命令复制配置文件示例。 ```bash cp config.json.example config.json ``` -------------------------------- ### RTC Client Initialization and Event Handling Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html Initializes the RTC client, checks system requirements, creates local camera and microphone tracks, and sets up event listeners for user join, publish, unpublish, and connection state changes. Includes a request helper for fetching tokens from a business server. ```javascript /** * 请找到 generateAuthInfo方法,配置业务服务请求域名获取token,appId,userId等 */ var channelId; var userName; var subscribedMap = {}; var RtcEngine = DingRTC.default; var client; var cameraTrack = null; var micTrack = null; var screenTrack = null; try { client = RtcEngine.createClient(); } catch (error) { console.log(error); alert('请使用官网最新Web SDK文件'); } if (!RtcEngine.checkSystemRequirements()) { alert('当前环境不支持RTC通信,请检查URL协议是否为https或使用最新版Chrome浏览器'); } RtcEngine.createMicrophoneAndCameraTracks( { dimension: 'VD_640x480', frameRate: 15, }, {} ).then( ([videoTrack, audioTrack]) => { cameraTrack = videoTrack; micTrack = audioTrack; }, ); function request(api, params) { var res; // const APP_SERVER_DOMAIN = 'http://localhost:3001'; 请修改为真实使用的业务服务器域名 const url = `${APP_SERVER_DOMAIN}${api}?${Object.keys(params) .map((key) => `${key}=${params[key]}`) .join('&')}`; return new Promise((resolve, reject) => { fetch(url) .then((response) => { res = response; if (response.ok) { return response.json(); } else { return response.text(); } }) .then((data) => { if (res?.ok) { if (data.code && data.code !== 200) { reject(data); } else { resolve(data.data); } } else { reject(data); } }) .catch(reject); }); } // 从业务服务器获取生成的token function getAppToken(userId, appId, channelId) { // 请修改为真实的参数 const loginParam = { }; return request('login', loginParam); } /** * 显示提示信息,并打印 * @param {String} text 要显示的信息 * @param {String} type 信息类型(默认成功) * @param {Number} delay 延迟时间(默认2s) */ function showAlert(text, type, delay) { if (!text) return; var _type = type ? 'alert-' + type : 'alert-success'; var _delay = delay || 2000; $('.alert') .html(text) .addClass(_type) .show() .delay(_delay) .fadeOut('normal', () => { $('.alert').removeClass(_type); }); if (_type === 'warning') { console.warn(text); } else if (_type === 'danger') { console.error(text); } else { console.log(text); } } function initEvents() { /** * remote用户加入房间 user-joined * 更新在线用户列表 */ client.on('user-joined', (user) => { updateUserList(); showAlert(user.userName + '加入房间', 'success'); }); // 设备状态变化 client.on('user-info-updated', (uid, msg) => { showAlert(`uid: ${uid}: 设备状态变化 ${msg} `); }); /** * 远端用户推流推发布事件 user-published,仅处理视频流发布 * 音频合流订阅在入会时进行订阅后无须再处理个人的音频流发布 */ client.on('user-published', (user, mediaType, auxiliary) => { showAlert(`${user.userName} 发布 ${auxiliary ? 'screen' : mediaType}`, 'success'); if (mediaType === 'video') { client.subscribe(user.userId, 'video', auxiliary).then((track) => { subscribedMap[user.userId] = Object.assign(subscribedMap[user.userId] || {}, { [auxiliary ? 'screen' : 'camera']: true, }); const dom = getDisplayRemoteContainer(user.userId, auxiliary ? 'screen' : 'camera'); track.play(dom); }); } }); /** * 远端用户推流结束事件 user-unpublished,仅处理视频流发布 * 远端用户取消音频推流时会自动从房间音频合流内移除 * 视频推流列表删除该用户对应类型视频 * 移除用户视图 * 初始化订阅状态 */ client.on('user-unpublished', (user, mediaType, auxiliary) => { showAlert(`${user.userName} 取消发布 ${auxiliary ? 'screen' : mediaType}`, 'success'); if (mediaType === 'video') { removeDom(user.userId, auxiliary ? 'screen' : 'camera'); delete subscribedMap[user.userId][auxiliary ? 'screen' : 'camera']; } }); /** * 链接状态变化时回调,disconnected 时代表离会 */ client.on('connection-state-change', (current, prev, reason) => { console.log(`connection-state-change ${current} ${reason || ''}`); if (current === 'disconnected') { if (reason !== 'leave') { showAlert(reason, 'danger'); clearRoom(); } } }); /** * 检测到用户离开频道 * 更新用户列表 * 移除用户视图 */ client.on('user-left', (user) => { delete subscribedMap[userId]; updateUserList(); removeDom(user.userId); showAlert(user.userName + '离开房间', 'success'); }); } /** * 加入房间 * 触发:输入房间号、单击加入房间按钮 * 获取鉴权信息 * 更新页面信息 * 默认开启预览 * 加入房间 * 添加事件监听 * 本地默认自动推视频流(视频流 + 音频流) * 发布本地流 * 订阅已发布到会中的视频流和 房间音频合流 */ async function joinRoom() { //1. 获取频道鉴权令牌参数 为了防止被盗用建议该方法在服务端获取 var authInfo = await generateAuthInfo(channelId); $('.local-display-name .username b').text(userName); $('.local-display-name .channelid b').text(channelId); $('.local-display-name .streamstate b').text('当前未推流'); //2.本地摄像头预览 cameraTrack.play($('.local-video')[0]); //3. 加入房间 默认推音频视频流 client .join(authInfo) .then( () => { updateUserList(); showAlert('加入房间成功', 'success'); initEvents(); }, (error) => { showAlert('[加入房间失败]' + error.message, 'danger'); throw error; }, ) .then(() => { // 4. 发布本地流 client.publish([cameraTrack, micTrack]).then( (res) => { getPublishState('success'); $('#cameraOpen').attr('checked', !cameraTrack?.muted); $('#micOpen').attr('checked', !micTrack?.muted); $('.streamType').show(); $('.deviceState').show(); }, (error) => { getPublishState('danger'); showAlert('[推流失败]' + error.message, 'danger'); }, ); // 5.订阅已发布到房间的远端流, 其中mcu 代表 房间音频合流,订阅mcu音频流后无须再单独订阅个人音频 const subParams = [{ uid: 'mcu', mediaType: 'audio', auxiliary: false }]; for (const user of client.remoteUsers) { if (user.hasAuxiliary) { subParams.push({ ``` -------------------------------- ### 自动运行 Source: https://github.com/aliyun/alirtcsample/blob/master/Linux/C++/Samples/client/java/Readme.md 该模式与 C++ Demo 行为一致,自动运行直至推流文件读取结束。 ```APIDOC ## 自动运行(与C++ Demo行为一致) ### 执行 带参数运行脚本: ``` ./run_demo.sh 1 ``` ### 行为 将自动运行直至推流文件读取结束,与 C++ Demo 行为一致。 ``` -------------------------------- ### 项目结构目录树 Source: https://github.com/aliyun/alirtcsample/blob/master/MiniProgram/README.md 展示了项目的目录结构,包括 miniprogram 目录下的页面、SDK、服务封装等文件。 ```text miniprogram/ ├── pages/ │ └── join/ # 入会页面(首页) ├── packageA/ │ └── pages/ │ └── meeting/ # 会议页面(音视频通话) ├── jssdk/ │ └── dingrtc_miniapp_client.js # DingRTC 小程序 SDK ├── services/ │ └── usesdk.js # SDK 调用封装 ├── app.js ├── app.json └── app.wxss ``` -------------------------------- ### CMake build configuration for server_pull_demo Source: https://github.com/aliyun/alirtcsample/blob/master/Linux/C++/Samples/server_pull/CMakeLists.txt CMake configuration for building the server_pull_demo executable. It sets C++14, places outputs in bin/lib directories, and links against the DingRTC and ffmpeg libraries found in the SDK's x86_64 lib folder. Fails with a fatal error if either library is not found. ```cmake cmake_minimum_required(VERSION 3.5) project(ServerPullDemo VERSION 1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) add_executable(server_pull_demo linux_server_pull_demo.cpp ) include_directories(${PROJECT_SOURCE_DIR}/../../SDK/api) set(SDK_LIB_DIR ${PROJECT_SOURCE_DIR}/../../SDK/lib/x86_64) link_directories(${SDK_LIB_DIR}) find_library(DING_RTC_LIB NAMES DingRTC PATHS ${SDK_LIB_DIR} NO_DEFAULT_PATH) if (NOT DING_RTC_LIB) message(FATAL_ERROR "Cannot find libDingRTC.so in SDK/lib/x86_64") else() message(STATUS "Found libDingRTC at: ${DING_RTC_LIB}") endif() find_library(FFMPEG_LIB NAMES ffmpeg PATHS ${SDK_LIB_DIR} NO_DEFAULT_PATH) if (NOT FFMPEG_LIB) message(FATAL_ERROR "Cannot find libffmpeg.so in SDK/lib/x86_64") else() message(STATUS "Found libffmpeg at: ${FFMPEG_LIB}") endif() target_link_libraries(server_pull_demo PRIVATE ${DING_RTC_LIB} ${FFMPEG_LIB}) ``` -------------------------------- ### 安装 npm 依赖 Source: https://github.com/aliyun/alirtcsample/blob/master/MiniProgram/README.md 在 miniprogram 目录下安装 npm 依赖,用于后续构建 npm。 ```shell cd miniprogram npm install ``` -------------------------------- ### 命令控制运行 Source: https://github.com/aliyun/alirtcsample/blob/master/Linux/C++/Samples/client/java/Readme.md 该模式通过命令行交互控制 Demo,执行脚本后按提示输入数字命令即可操作。 ```APIDOC ## 命令控制运行(推荐) ### 执行 运行脚本: ``` ./run_demo.sh ``` ### 操作命令 进入命令行后,按数字输入对应命令: - 1 : join - 2 : leave - 4 : pub audio - 5 : unpub audio - 5 : pub video(注意:原文中该命令与 unpub audio 重复,实际以提示为准) - 6 : unpub video - 0 : exit ### 日志 命令运行模式下控制台不输出日志,本地日志保存在 `command_log.log`,每次运行会覆盖。 ``` -------------------------------- ### CMake project configuration and source list Source: https://github.com/aliyun/alirtcsample/blob/master/Linux/C++/Samples/client/qtdemo/OneRTCQtDemo/CMakeLists.txt Defines the CMake project, sets C++ standard, locates Qt and DingRTC SDK paths, and lists project source files. ```cmake cmake_minimum_required(VERSION 3.5) project(OneRTCQtDemo VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_SKIP_RPATH TRUE) set(DEPS_LIB_DIR ${CMAKE_BINARY_DIR}/lib) set(DINGRTC_SDK_PATH ${PROJECT_SOURCE_DIR}/../../../..) set(DINGRTC_SDK_INCLUDE_PATH ${DINGRTC_SDK_PATH}/api) set(DINGRTC_SDK_LIB_PATH ${DINGRTC_SDK_PATH}/lib/linux/${CMAKE_SYSTEM_PROCESSOR}/${CMAKE_BUILD_TYPE}) set(OWT_DEPS_LIB_PATH ${PROJECT_SOURCE_DIR}/../../../../thirdparty/owt-client-native/lib/linux/${CMAKE_SYSTEM_PROCESSOR}/${CMAKE_BUILD_TYPE}) set(COMMON_SOURCE_PATH ${PROJECT_SOURCE_DIR}/../../common) set(TLOG_SOURCE_PATH ${PROJECT_SOURCE_DIR}/../../tlog) file(GLOB COMMON_SOURCES ${COMMON_SOURCE_PATH}/*.cc ${COMMON_SOURCE_PATH}/*.h) file(GLOB TLOG_SOURCES ${TLOG_SOURCE_PATH}/*.cc ${TLOG_SOURCE_PATH}/*.h) set(OPENSSL_PATH /home/alidev/Qt/Tools/OpenSSLv3/src) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network) include_directories(${DINGRTC_SDK_INCLUDE_PATH} ${COMMON_SOURCE_PATH} ${TLOG_SOURCE_PATH}/..) # ${TINY_HTTP_PATH}/include # ${PROJECT_SOURCE_DIR}/../../../Common/ThirdParty/nlohmann) link_directories(${DEPS_LIB_DIR}) # ${TINY_HTTP_PATH}/lib/linux/${CMAKE_SYSTEM_PROCESSOR}/${CMAKE_BUILD_TYPE}) set(PROJECT_SOURCES main.cpp MainWindow.cpp MainWindow.h MainWindow.ui MeetingWindow.cpp MeetingWindow.h MeetingWindow.ui VideoSettingsWidget.cpp VideoSettingsWidget.h VideoSettingsWidget.ui AudioSettingsWidget.cpp AudioSettingsWidget.h AudioSettingsWidget.ui ExternalSourceWidget.cpp ExternalSourceWidget.h ExternalSourceWidget.ui AVFrameObserverWidget.cpp AVFrameObserverWidget.h AVFrameObserverWidget.ui GeneralSettingsWidget.cpp GeneralSettingsWidget.h GeneralSettingsWidget.ui AppSettings.cpp AppSettings.h Utils.cpp Utils.h RtcEngineObject.cpp RtcEngineObject.h HttpClient.cpp HttpClient.h CellWidget.cpp CellWidget.h SettingsWindow.cpp SettingsWindow.h DeviceInfo.h ) ``` -------------------------------- ### config.json 配置文件格式 Source: https://github.com/aliyun/alirtcsample/blob/master/Android/FullFeatureDemo/src/main/assets/CONFIG_README.md 展示 config.json 文件的 JSON 格式,包含 appServerConfig、aiAgentConfig、subtitleConfig 和 siAgentConfig 等配置项。 ```json { "appServerConfig": { "online": "oneline_server" }, "aiAgentConfig": { "defaultTemplateId": "your_template_id_here", "defaultTemplateIdOnline": "your_template_id_online_here", "rtcServiceName": "your_rtc_service_name_here", "asrVendor": "your_asr_vendor_here", "asrModel": "your_asr_model_here", "llmVendor": "your_llm_vendor_here", "llmModel": "your_llm_model_here", "llmTemperature": 0.7, "llmTopP": 0.8, "llmMaxToken": 500, "llmHistoryDepth": 10, "llmPrompt": "your_llm_prompt_here", "ttsVendor": "your_tts_vendor_here", "ttsModel": "your_tts_model_here", "ttsVoice": "your_tts_voice_here", "apiStart": "", "apiUpdate": "", "apiStop": "" }, "subtitleConfig": { "apiStart": "", "apiStop": "" } } ``` -------------------------------- ### createScreenVideoTrack Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html Creates a screen video track with specified configuration. The track is used for screen sharing and listens for the 'track-ended' event to handle user stopping the share. ```APIDOC ## createScreenVideoTrack ### Description Creates a screen video track with specified configuration. The track is used for screen sharing and listens for the 'track-ended' event to handle user stopping the share. ### Method RtcEngine.createScreenVideoTrack(config) ### Parameters - **config** (object) - Required - Configuration for the screen track. - **dimension** (string) - Required - The video dimension, e.g., 'VD_1280x720'. - **frameRate** (number) - Required - The frame rate, e.g., 15. ### Request Example ```javascript const [videoTrack] = await RtcEngine.createScreenVideoTrack({ dimension: 'VD_1280x720', frameRate: 15 }); ``` ### Response #### Success Response - **videoTrack** (object) - The created screen video track. #### Response Example ```javascript // The videoTrack is used for publishing and listening to 'track-ended'. ``` ``` -------------------------------- ### Generate self-signed certificate for HTTPS Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vueVersion/README.md Use this OpenSSL command to generate a self-signed certificate (key.pem and cert.pem) in the project root. Vite will automatically switch to HTTPS when these files are present, which is required for camera/microphone access when using a LAN IP on other devices. ```bash $ openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365 -subj "/CN=localhost" ``` -------------------------------- ### Configure AppID and AppKey in TokenGenerator.java Source: https://github.com/aliyun/alirtcsample/blob/master/Android/FullFeatureDemo/README.md Replace the placeholder values with your actual AppID and AppKey before running the project. This is required for authentication with the DingRTC service. ```java // TokenGenerator.java private static final String APP_ID = "your_app_id_here"; private static final String APP_KEY = "your_app_key_here"; ``` -------------------------------- ### 获取测试token Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html 生成测试 token,使用随机 userId 和 appId,仅用于开发测试,正式上线需使用服务端 AppServer。 ```JavaScript async function generateAuthInfo(channelId) { var appId = 'xxxxxx'; // 修改为自己的appid 该方案仅为开发测试使用,正式上线需要使用服务端的AppServer userId = 'xxxxx4xxxyxxx'.replace(/[xy]/g, (c) => { var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8; return v.toString(16); }); // 可以自定义 userName = 'web_' + userId.substr(0, 4); const { token } = await getAppToken(userId, appId, channelId); return { appId, uid: userId, token, userName, channel: channelId, }; } ``` -------------------------------- ### publish(track) Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html Publishes a media track (camera, screen, or audio) to the channel. The track is selected based on the user's configuration and the publish state is updated accordingly. ```APIDOC ## publish(track) ### Description Publishes a media track (camera, screen, or audio) to the channel. The track is selected based on the user's configuration and the publish state is updated accordingly. ### Method client.publish(track) ### Parameters - **track** (object) - Required - The media track to publish (cameraTrack, screenTrack, or micTrack). ### Request Example ```javascript client.publish(track).then(() => { getPublishState('success'); }); ``` ### Response #### Success Response - **Promise** - Resolves when the publish operation succeeds. #### Response Example ```javascript // No explicit response body; the promise resolves on success. ``` ``` -------------------------------- ### 根据推流状态设置当前推流UI Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html 根据本地推流状态更新 UI 中的复选框和显示文本。 ```JavaScript var getPublishState = (type) => { var streamstate = $('.streamstate b').text(); const isCameraPublished = client.localTracks.includes(cameraTrack); const isScreenPublished = client.localTracks.includes(screenTrack); const isMicPublished = client.localTracks.includes(micTrack); const streamStateBoxes = $('.publisher .streamType input'); const streamStates = []; if (isCameraPublished) { streamStates.push('视频流'); } $('#cameraPublish').attr('checked', isCameraPublished); if (isScreenPublished) { streamStates.push('共享流'); } $('#screenPublish').attr('checked', isScreenPublished); if (isMicPublished) { streamStates.push('音频流'); } $('#audioPublish').attr('checked', isMicPublished); const streamState = streamStates.join('+') } ``` -------------------------------- ### joinRoom Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html Joins a specified channel using the ARTC client. The channel ID is taken from the input field and the client joins with the local camera and microphone tracks. ```APIDOC ## joinRoom ### Description Joins a specified channel using the ARTC client. The channel ID is taken from the input field and the client joins with the local camera and microphone tracks. ### Method joinRoom() ### Parameters - **channelId** (string) - Required - The channel ID to join. ### Request Example ```javascript joinRoom(); ``` ### Response #### Success Response - **client** (object) - The ARTC client instance after joining. #### Response Example ```javascript // No explicit return value; the client is used for subsequent operations. ``` ``` -------------------------------- ### Linker flags and target definition Source: https://github.com/aliyun/alirtcsample/blob/master/Linux/C++/Samples/client/qtdemo/OneRTCQtDemo/CMakeLists.txt Sets linker flags, defines the executable target with sources, and selects the DingRTC library based on build type. ```cmake #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined -Wl,--disable-new-dtags") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath=\$ORIGIN/lib -Wl,--disable-new-dtags") # if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) # qt_add_executable(OneRTCQtDemo # MANUAL_FINALIZATION # ${PROJECT_SOURCES} # GridConfViewControls.ui # ) # # Define target properties for Android with Qt 6 as: # # set_property(TARGET OneRTCQtDemo APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # # ${CMAKE_CURRENT_SOURCE_DIR}/android) # # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation # else() # add_executable(OneRTCQtDemo # ${PROJECT_SOURCES} # ) # endif() add_executable(OneRTCQtDemo resources.qrc ${PROJECT_SOURCES} ${COMMON_SOURCES} ${TLOG_SOURCES} ) if (CMAKE_BUILD_TYPE MATCHES "Debug") set(DINGRTC DingRTCd) else() set(DINGRTC DingRTC) endif() #set(DINGRTC DingRTC) target_link_libraries(OneRTCQtDemo PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network ${DINGRTC} ffmpeg pthread) ``` -------------------------------- ### 订阅&取消订阅 Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html 切换订阅或取消订阅用户的视频流,并更新 DOM 和状态。 ```JavaScript function toggleSub(evt) { var v = evt.data; if (subscribedMap[v.userId][v.label]) { client.unsubscribe(v.userId, 'video', v.label === 'screen').then(() => { removeDom(v.userId, v.label); subscribedMap[v.userId][v.label] = false; console.log('取消订阅'); }); } else { client.subscribe(v.userId, 'video', v.label === 'screen').then((track) => { const dom = getDisplayRemoteContainer(v.userId, v.label); subscribedMap[v.userId][v.label] = true; track.play(dom); console.log('订阅成功'); }); } $('.menu').hide(); } ``` -------------------------------- ### Copy dependency libraries custom command Source: https://github.com/aliyun/alirtcsample/blob/master/Linux/C++/Samples/client/qtdemo/OneRTCQtDemo/CMakeLists.txt Adds a custom command to copy DingRTC and ffmpeg shared libraries to the build output directory before linking. ```cmake # copy dependency libraries before build add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DINGRTC_SDK_LIB_PATH}/lib${DINGRTC}.so ${DEPS_LIB_DIR}/lib${DINGRTC}.so COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OWT_DEPS_LIB_PATH}/libffmpeg.so ${DEPS_LIB_DIR}/libffmpeg.so COMMENT "Copying dependency libraries" ) add_custom_target(CopyDeps ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/dummy # Making sure the custom command runs ) add_dependencies(OneRTCQtDemo CopyDeps) ``` -------------------------------- ### 订阅远端用户视频流 Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html 根据用户是否有视频或辅助流,批量订阅远端用户的视频流。订阅成功后播放音频或视频,并更新订阅状态。 ```JavaScript if (user.hasVideo) { subParams.push({ uid: user.userId, mediaType: 'video', auxiliary: false }); } } const subTask = client.batchSubscribe(subParams).then((batchSubscribeResult) => { for (const { error, track, uid, auxiliary } of batchSubscribeResult) { if (error) { showAlert( `[订阅${uid} ${auxiliary ? 'screenShare' : 'camera'} 失败]` + error.message, 'danger', ); continue; } if (track.trackMediaType === 'audio') { const audioTrack = track; audioTrack.play(); } else { subscribedMap[uid] = Object.assign(subscribedMap[uid] || {}, { [auxiliary ? 'screen' : 'camera']: true, }); const dom = getDisplayRemoteContainer(uid, auxiliary ? 'screen' : 'camera'); track.play(dom); } } }); ``` -------------------------------- ### leave() Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html Leaves the current channel and cleans up local resources. This is called when the user clicks the leave button or when the page is unloaded. ```APIDOC ## leave() ### Description Leaves the current channel and cleans up local resources. This is called when the user clicks the leave button or when the page is unloaded. ### Method client.leave() ### Parameters None ### Request Example ```javascript client.leave(); ``` ### Response #### Success Response - **Promise** - Resolves when the leave operation completes. #### Response Example ```javascript // No explicit response body; the promise resolves on success. ``` ``` -------------------------------- ### 更新远端在线用户列表 Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html 清空并重新渲染远端用户列表,为每个用户绑定鼠标悬停事件以显示菜单。 ```JavaScript function updateUserList() { $('.user-ul').empty(); let userList = client.remoteUsers; let frg = document.createDocumentFragment(); userList.map((user) => { let html = $("
  • " + user.userName + "
  • "); $(html) .bind('mouseover', user.userId, showUserMenu) .bind('mouseleave', () => { $(event.currentTarget).find('.menu').hide(); }); frg.append(html[0]); }); $('.user-ul').append($(frg)); } ``` -------------------------------- ### 显示用户菜单 Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html 根据用户是否有视频或辅助流,显示订阅或取消订阅的菜单项。 ```JavaScript function showUserMenu(evt) { let userId = evt.data; if (!$(event.target).eq(0).hasClass('user-ul-li')) { return; } $('.menu').hide(); $(event.target).find('.menu').empty().show(); let userInfo = client.remoteUsers.find((item) => item.userId === userId); var html = ''; if (!userInfo.hasAuxiliary && !userInfo.hasVideo) { html = $('
  • 该用户未推流
  • '); $(event.target).find('.menu').append(html[0]); } else { var frg = document.createDocumentFragment(); if (userInfo.hasVideo) { let subState = subscribedMap[userId].camera ? '取消订阅' : '订阅'; html = $('
  • ' + '视频流' + ' ' + subState + '
  • '); $(html).find('span').off('click').on('click', { userId, label: 'camera' }, toggleSub); frg.append(html[0]); } if (userInfo.hasAuxiliary) { let subState = subscribedMap[userId].screen ? '取消订阅' : '订阅'; html = $('
  • ' + '共享流' + ' ' + subState + '
  • '); $(html).find('span').off('click').on('click', { userId, label: 'screen' }, toggleSub); frg.append(html[0]); } $(event.target).find('.menu').append($(frg)); } } ``` -------------------------------- ### 创建获取订阅的远端视频流的容器标签 Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html 创建或获取用于显示远端视频流的容器 DOM 元素,并设置显示名称。 ```JavaScript function getDisplayRemoteContainer(userId, label) { var label = label === 'camera' ? 'camera' : 'screen'; var id = userId + '_' + label; var videoWrapper = $('#' + id); var userInfo = client.remoteUsers.filter((item) => item.userId === userId); if (videoWrapper.length == 0) { videoWrapper = $( "
    ", ); $('.video-container').append(videoWrapper); } const displayName = userInfo[0].userName + '_' + label; videoWrapper.find('.display-name').text(displayName); return videoWrapper[0]; } ``` -------------------------------- ### 移除视频容器dom Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html 根据用户 ID 和标签移除对应的视频容器 DOM 元素。 ```JavaScript function removeDom(userId, label) { if (userId) { if (!label) { $('#' + userId + '_camera').remove(); $('#' + userId + '_screen').remove(); } else { label = label === 'camera' ? 'camera' : 'screen'; $('#' + userId + '_' + label).remove(); } } } ``` -------------------------------- ### macOS/iOS bundle identifier commented block Source: https://github.com/aliyun/alirtcsample/blob/master/Linux/C++/Samples/client/qtdemo/OneRTCQtDemo/CMakeLists.txt Commented-out CMake block for setting macOS/iOS bundle properties, including bundle identifier and versioning. ```cmake # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. # if(${QT_VERSION} VERSION_LESS 6.1.0) # set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.OneRTCQtDemo) # endif() # set_target_properties(OneRTCQtDemo PROPERTIES # ${BUNDLE_ID_OPTION} # MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} # MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} # MACOSX_BUNDLE TRUE # WIN32_EXECUTABLE TRUE # ) ``` -------------------------------- ### unpublish(track) Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html Unpublishes a media track from the channel. The track is removed from the channel and the publish state is updated. ```APIDOC ## unpublish(track) ### Description Unpublishes a media track from the channel. The track is removed from the channel and the publish state is updated. ### Method client.unpublish(track) ### Parameters - **track** (object) - Required - The media track to unpublish. ### Request Example ```javascript client.unpublish(track).then(() => { getPublishState('success'); }); ``` ### Response #### Success Response - **Promise** - Resolves when the unpublish operation succeeds. #### Response Example ```javascript // No explicit response body; the promise resolves on success. ``` ``` -------------------------------- ### setMuted(muted) Source: https://github.com/aliyun/alirtcsample/blob/master/Web/vanillaVersion.html Mutes or unmutes a media track (camera or microphone). The track's muted state is toggled based on the user's checkbox selection. ```APIDOC ## setMuted(muted) ### Description Mutes or unmutes a media track (camera or microphone). The track's muted state is toggled based on the user's checkbox selection. ### Method track.setMuted(muted) ### Parameters - **muted** (boolean) - Required - The new muted state (true to mute, false to unmute). ### Request Example ```javascript await track.setMuted(!track.muted); ``` ### Response #### Success Response - **Promise** - Resolves when the mute state is applied. #### Response Example ```javascript // No explicit response body; the promise resolves on success. ``` ```