1 Star 0 Fork 0

融云 RongCloud / rtc-flutter-wrapper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

融云 RTC Wrapper Plugin

GitHub stars Pub version

本文档主要讲解了如何使用融云 RTC Wrapper Plugin,基于 融云 iOS/Android 平台的 RTCLib SDK

Flutter 官网

融云 iOS RTC 文档

融云 Android RTC 文档

前期准备

1 申请开发者账号

融云官网申请开发者账号

通过管理后台的 "基本信息"->"App Key" 获取 AppKey

通过管理后台的 "IM 服务"—>"API 调用"->"用户服务"->"获取 Token",通过用户 id 获取 IMToken

2 开通音视频服务

管理后台的 "音视频服务"->"服务设置" 开通音视频 RTC 3.0 ,开通两个小时后生效

依赖 RTC Wrapper Plugin

在项目的 pubspec.yaml 中写如下依赖

dependencies:
  flutter:
    sdk: flutter
  rongcloud_rtc_wrapper_plugin: 5.6.11

iOS 需要在 Info.plist 中需要加入对相机和麦克风的权限申请

<key>NSCameraUsageDescription</key>
<string>使用相机</string>
<key>NSMicrophoneUsageDescription</key>
<string>使用麦克风</string>

还需要添加字段 io.flutter.embedded_views_preview 值为 YES

Android 需要在 AndroidManifest.xml 文件中声明对相机和麦克风的权限

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />

前置接口说明

初始化 IM SDK

RongIMClient.init(RongAppKey);

连接 IM

RongIMClient.connect(IMToken, (code, userId) {
});

创建 RTC 引擎

engine = await RCRTCEngine.create();

音视频模式接口说明

用户加入房间,渲染并发布资源

加入 RTC 房间

// 设置加入 RTC 房间事件监听
engine.onRoomJoined = (int code, String? message) {
};

// 加入 RTC 房间
RCRTCRoomSetup setup = RCRTCRoomSetup.create(
    type: RCRTCMediaType.audio_video,
    role: RCRTCRole.meeting_member,
);
engine.joinRoom(id, setup);

采集音频

引擎默认开启音频采集

engine.enableMicrophone(true);

采集视频

engine.enableCamera(true);

渲染视频

RCRTCView view = await RCRTCView.create();
engine.setLocalView(view);

发布资源

engine.publish(RCRTCMediaType.audio_video);

渲染远端用户

监听远端用户加入的回调

当用户加入的时候,不要做订阅渲染的处理,因为此时该用户可能刚加入房间成功,但是尚未发布资源

engine.onUserJoined = (roomId, userId) {
};

监听远端用户发布资源的回调

engine.onRemotePublished = (roomId, userId, type) {

};

远端用户发布资源后,订阅远端用户资源

engine.subscribe(userId, type);

渲染远端用户资源

RCRTCView view = await RCRTCView.create();
engine.setRemoteView(userId, view);

直播模式接口说明

主播加入房间,渲染并发布资源

加入 RTC 房间

// 设置加入 RTC 房间事件监听
engine.onRoomJoined = (int code, String? message) {
};

// 加入 RTC 房间
RCRTCRoomSetup setup = RCRTCRoomSetup.create(
    type: RCRTCMediaType.audio_video,
    role: RCRTCRole.live_broadcaster,
);
engine.joinRoom(id, setup);

采集音频

引擎默认开启音频采集

engine.enableMicrophone(true);

采集视频

engine.enableCamera(true);

渲染视频

RCRTCView view = await RCRTCView.create();
engine.setLocalView(view);

发布资源

engine.publish(RCRTCMediaType.audio_video);

渲染远端主播

监听远端主播加入的回调

当主播加入的时候,不要做订阅渲染的处理,因为此时该主播可能刚加入房间成功,但是尚未发布资源

engine.onUserJoined = (roomId, userId) {
};

监听远端主播发布资源的回调

engine.onRemotePublished = (roomId, userId, type) {

};

远端主播发布资源后,订阅远端主播资源

engine.subscribe(userId, type);

渲染远端主播资源

RCRTCView view = await RCRTCView.create();
engine.setRemoteView(userId, view);

观众加入房间,订阅并渲染MCU资源

加入 RTC 房间

// 设置加入 RTC 房间事件监听
engine.onRoomJoined = (int code, String? message) {
};

// 加入 RTC 房间
RCRTCRoomSetup setup = RCRTCRoomSetup.create(
    type: RCRTCMediaType.audio_video,
    role: RCRTCRole.live_audience,
);
engine.joinRoom(id, setup);

监听MCU资源发布回调

engine.onRemoteLiveMixPublished = (type) {
};

MCU资源发布后,订阅MCU资源

engine.subscribeLiveMix(type);

渲染MCU资源

RCRTCView view = await RCRTCView.create();
engine.setLiveMixView(view);

观众加入房间,订阅并渲染主播资源

加入 RTC 房间

// 设置加入 RTC 房间事件监听
engine.onRoomJoined = (int code, String? message) {
};

// 加入 RTC 房间
RCRTCRoomSetup setup = RCRTCRoomSetup.create(
    type: RCRTCMediaType.audio_video,
    role: RCRTCRole.live_audience,
);
engine.joinRoom(id, setup);

监听远端主播加入的回调

当主播加入的时候,不要做订阅渲染的处理,因为此时该主播可能刚加入房间成功,但是尚未发布资源

engine.onUserJoined = (roomId, userId) {
};

监听远端主播发布资源的回调

engine.onRemotePublished = (roomId, userId, type) {

};

远端主播发布资源后,订阅远端主播资源

engine.subscribe(userId, type);

渲染远端主播资源

RCRTCView view = await RCRTCView.create();
engine.setRemoteView(userId, view);

其他接口

离开房间

engine.leaveRoom();

销毁引擎

engine.destroy();
MIT License Copyright (c) 2019 融云 RongCloud Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Objective-C 等 5 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/rongcloud/rtc-flutter-wrapper.git
git@gitee.com:rongcloud/rtc-flutter-wrapper.git
rongcloud
rtc-flutter-wrapper
rtc-flutter-wrapper
main

搜索帮助