Flutter视频会议插件custom_jitsi_meet_with_pointer_test的使用

Flutter视频会议插件custom_jitsi_meet_with_pointer_test的使用

支持我们使用我们的Patreon账户。

Jitsi Meet插件为Flutter而设计。支持Android、iOS和Web平台。

“Jitsi Meet是一个开源(Apache)WebRTC JavaScript应用程序,使用Jitsi Videobridge提供高质量、安全且可扩展的视频会议服务。”

了解更多关于Jitsi Meet的信息 这里

目录

配置

IOS

注意:示例在XCode 12.2和Flutter 1.22.4下编译通过。

Podfile

确保您的Podfile中有类似以下条目,声明平台为11.0或以上,并禁用BITCODE。

platform :ios, '11.0'

...

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end
Info.plist

在您的Info.plist中添加NSCameraUsageDescription和NSMicrophoneUsageDescription。

<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) MyApp needs access to your camera for meetings.</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) MyApp needs access to your microphone for meetings.</string>

Android
Gradle

将构建工具gradle依赖设置为至少3.6.3:

dependencies {
    classpath 'com.android.tools.build:gradle:3.6.3' <!-- 升级这个 -->
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

将分布gradle wrapper设置为至少5.6.4。

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip <!-- 升级这个 -->
AndroidManifest.xml

Jitsi Meet的SDK AndroidManifest.xml将与您的项目冲突,特别是application:label字段。要解决这个问题,请进入android/app/src/main/AndroidManifest.xml,添加工具库并tools:replace="android:label"到application标签。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="yourpackage.com"
    xmlns:tools="http://schemas.android.com/tools"> <!-- 添加这个 -->
    <application 
        tools:replace="android:label"  
        android:name="your.application.name"
        android:label="My Application"
        android:icon="@mipmap/ic_launcher">
        ...
    </application>
...
</manifest>
最低SDK版本23

在android/app/build.gradle中更新您的最低sdk版本至23。

defaultConfig {
    applicationId "com.gunschu.jitsi_meet_example"
    minSdkVersion 23 //Required for Jitsi
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}
Proguard

Jitsi的SDK启用proguard,但如果没有proguard-rules.pro文件,您的发布apk构建将缺少Flutter包装器以及react-native代码。在您的Flutter项目的android/app/build.gradle文件中添加proguard支持。

buildTypes {
    release {
        // TODO: 添加自己的签名配置用于发布构建。
        // 目前使用调试密钥,以便`flutter run --release`工作。
        signingConfig signingConfigs.debug
        
        // 添加以下三行用于proguard
        minifyEnabled true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

然后在同一目录中添加一个名为proguard-rules.pro的文件。查看示例应用的proguard-rules.pro文件以了解需要粘贴的内容。

注意

如果您不创建proguard-rules.pro文件,那么当您尝试加入会议或者会议屏幕试图打开但立即关闭时,您的应用将会崩溃。您将在logcat中看到以下错误之一。

## 应用崩溃 ##
java.lang.RuntimeException: Parcel android.os.Parcel@8530c57: Unmarshalling unknown type code 7536745 at offset 104
    at android.os.Parcel.readValue(Parcel.java:2747)
    at android.os.Parcel.readSparseArrayInternal(Parcel.java:3118)
    at android.os.Parcel.readSparseArray(Parcel.java:2351)
    .....
## 会议无法打开,您返回到上一个屏幕 ##
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.BV.LinearGradient.LinearGradientManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.uimanager.g
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTGroupViewManager
W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.a
.....

WEB

要在web部分的index.html中包含Jitsi Js库。

<script src="https://meet.jit.si/external_api.js" type="application/javascript"></script>

示例:

<body>
  <!-- 这个脚本安装service_worker.js以提供PWA功能给应用。更多信息,请参阅:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('load', function () {
        navigator.serviceWorker.register('/flutter_service_worker.js');
      });
    }
  </script>
  <script src="https://meet.jit.si/external_api.js" type="application/javascript"></script>
  <script src="main.dart.js" type="application/javascript"></script>
</body>
</html>

注意 查看jitsi_meet插件中的使用示例。

加入会议

_joinMeeting() async {
    try {
      FeatureFlag featureFlag = FeatureFlag();
      featureFlag.welcomePageEnabled = false;
      featureFlag.resolution = FeatureFlagVideoResolution.MD_RESOLUTION; // 限制视频分辨率为360p
      
      var options = JitsiMeetingOptions()
        ..room = "myroom" // 必须,空格会被删除
        ..serverURL = "https://someHost.com"
        ..subject = "Meeting with Gunschu"
        ..userDisplayName = "My Name"
        ..userEmail = "myemail@email.com"
        ..userAvatarURL = "https://someimageurl.com/image.jpg" // 或.png
        ..audioOnly = true
        ..audioMuted = true
        ..videoMuted = true
        ..featureFlag = featureFlag;

      await JitsiMeet.joinMeeting(options);
    } catch (error) {
      debugPrint("error: $error");
    }
  }

JitsiMeetingOptions

字段 必须 默认值 描述
room N/A 唯一的房间名称,附加到serverURL。有效字符:字母数字、破折号和下划线。
subject $room 会议名称显示在会议顶部。如果为空,则默认为房间名称,其中破折号和下划线替换为空格,首字母大写。
userDisplayName Fellow Jitster 用户的显示名称。
userEmail none 用户的电子邮件地址。
audioOnly false 无视频开始会议。可以在会议中开启。
audioMuted false 开始会议时音频静音。可以在会议中开启。
videoMuted false 开始会议时视频静音。可以在会议中开启。
serverURL meet.jitsi.si 指定自己的托管服务器。必须是格式正确的绝对URL,如https://someHost.com。默认为Jitsi Meet的服务器。
userAvatarURL N/A none 用户的头像URL。
token N/A none 用于认证的JWT令牌。
featureFlag 见下文 FeatureFlag类的对象,用于启用/禁用功能并设置Jitsi Meet SDK的视频分辨率。

FeatureFlag

特性标志允许您限制视频分辨率并启用/禁用Jitsi Meet SDK的某些功能。如果您未向JitsiMeetingOptions提供任何标志,则将使用默认值。

我们正在使用来自Jitsi Meet存储库的官方标志列表

标志 默认(Android) 默认(iOS) 描述
addPeopleEnabled true true 启用蓝色按钮“添加人员”,当您独自一人时显示。需要启用inviteEnabled标志。
calendarEnabled true auto 启用日历集成。
callIntegrationEnabled true true 启用呼叫集成(iOS上的CallKit,Android上的ConnectionService)。 注意
closeCaptionsEnabled true true 启用菜单中的字幕选项。
conferenceTimerEnabled true true 启用会议计时器。
chatEnabled true true 启用聊天(按钮和功能)。
inviteEnabled true true 启用菜单中的邀请选项。
iOSRecordingEnabled N/A false 在iOS上启用录制。
kickOutEnabled true true 启用视频缩略图中的踢出选项。
liveStreamingEnabled auto auto 启用菜单中的直播选项。
meetingNameEnabled true true 显示会议名称。
meetingPasswordEnabled true true 启用菜单中的会议密码选项(如果设置了会议密码,对话框仍然会显示)。
pipEnabled auto auto 启用画中画模式。
raiseHandEnabled true true 启用菜单中的举手选项。
recordingEnabled auto N/A 启用菜单中的录制选项。
resoulution N/A N/A 设置本地和(最大)远程视频分辨率。覆盖服务器配置。接受的值有:LD_RESOLUTION(180p),MD_RESOLUTION(360p),SD_RESOLUTION(480p/标清),HD_RESOLUTION(720p/高清)。
serverURLChangeEnabled true true 启用服务器URL更改。
tileViewEnabled true true 启用菜单中的拼图视图选项。
toolboxAlwaysVisible true true 工具箱(按钮和菜单)在通话期间始终可见(如果不,则单击显示它)。
videoShareButtonEnabled true true 启用视频共享按钮。
welcomePageEnabled false false 启用欢迎页面。“欢迎页面列出了最近的会议和日历约会,旨在被独立应用程序使用。”

关于呼叫集成的说明 Android上的呼叫集成(称为ConnectionService)已被官方Jitsi Meet应用禁用,因为它造成了许多问题。您应该也禁用它以避免这些问题。

JitsiMeetingResponse

字段 类型 描述
isSuccess bool 成功指示器。
message String 成功消息或错误作为字符串。
error dynamic 可选,仅在isSuccess为false时存在。错误对象。

监听会议事件

支持的事件

名称 描述
onConferenceWillJoin 会议正在加载。
onConferenceJoined 用户已加入会议。
onConferenceTerminated 用户已退出会议。
onPictureInPictureWillEnter 用户进入画中画模式。
onPictureInPictureTerminated 用户退出画中画模式。
onError 发生了错误,监听会议事件。

每会议事件

要按会议监听事件,请在加入会议时传递JitsiMeetingListener。当触发onConferenceTerminated事件时,监听器将自动移除。

await JitsiMeet.joinMeeting(options,
  listener: JitsiMeetingListener(onConferenceWillJoin: ({message}) {
    debugPrint("${options.room} will join with message: $message");
  }, onConferenceJoined: ({message}) {
    debugPrint("${options.room} joined with message: $message");
  }, onConferenceTerminated: ({message}) {
    debugPrint("${options.room} terminated with message: $message");
  }, onPictureInPictureWillEnter: ({message}) {
	debugPrint("${options.room} entered PIP mode with message: $message");
  }, onPictureInPictureTerminated: ({message}) {
	debugPrint("${options.room} exited PIP mode with message: $message");
  }));

全局会议事件

要监听全局会议事件,只需使用JitsiMeet.addListener(myListener)添加一个JitsiMeetListener。可以使用JitsiMeet.removeListener(listener)JitsiMeet.removeAllListeners()来移除监听器。

@override
void initState() {
  super.initState();
  JitsiMeet.addListener(JitsiMeetingListener(
    onConferenceWillJoin: _onConferenceWillJoin,
    onConferenceJoined: _onConferenceJoined,
    onConferenceTerminated: _onConferenceTerminated,
    onPictureInPictureWillEnter: _onPictureInPictureWillEnter,
    onPictureInPictureTerminated: _onPictureInPictureTerminated,
    onError: _onError));
}

@override
void dispose() {
  super.dispose();
  JitsiMeet.removeAllListeners();
}

_onConferenceWillJoin({message}) {
  debugPrint("_onConferenceWillJoin broadcasted");
}

_onConferenceJoined({message}) {
  debugPrint("_onConferenceJoined broadcasted");
}

_onConferenceTerminated({message}) {
  debugPrint("_onConferenceTerminated broadcasted");
}

_onPictureInPictureWillEnter({message}) {
debugPrint("_onPictureInPictureWillEnter broadcasted with message: $message");
}

_onPictureInPictureTerminated({message}) {
debugPrint("_onPictureInPictureTerminated broadcasted with message: $message");
}

_onError(error) {
  debugPrint("_onError broadcasted");
}

程序化关闭会议

JitsiMeet.closeMeeting();

更多关于Flutter视频会议插件custom_jitsi_meet_with_pointer_test的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter视频会议插件custom_jitsi_meet_with_pointer_test的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


当然,以下是如何在Flutter项目中集成和使用custom_jitsi_meet_with_pointer_test插件的一个基本示例。请注意,custom_jitsi_meet_with_pointer_test这个包名看起来像是为测试目的而定制的,通常在实际项目中,你可能会使用flutter_jitsi_meet或者类似的官方或广泛使用的插件。不过,这里我们假设custom_jitsi_meet_with_pointer_test是一个可用的插件,并且其API与flutter_jitsi_meet类似。

1. 添加依赖

首先,你需要在pubspec.yaml文件中添加这个插件的依赖:

dependencies:
  flutter:
    sdk: flutter
  custom_jitsi_meet_with_pointer_test: ^x.y.z  # 替换为实际的版本号

然后运行flutter pub get来安装依赖。

2. 导入插件

在你的Dart文件中导入插件:

import 'package:custom_jitsi_meet_with_pointer_test/custom_jitsi_meet_with_pointer_test.dart';

3. 配置Jitsi Meet选项

你可以配置Jitsi Meet会议的各种选项,如房间URL、用户名、服务器URL等。下面是一个基本的示例:

class _MyHomePageState extends State<MyHomePage> {
  final JitsiMeetOptions options = JitsiMeetOptions(
    room: 'https://meet.jit.si/YourRoomName', // 替换为你的Jitsi Meet房间URL
    userInfo: UserInfo(
      displayName: 'Your Display Name', // 替换为你的显示名称
      email: 'your.email@example.com', // 可选:用户的电子邮件地址
    ),
    audioOnly: false, // 是否仅音频
    videoMuted: false, // 视频是否静音
    audioMuted: false, // 音频是否静音
    // 其他配置选项...
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Jitsi Meet Example'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            // 启动Jitsi Meet会议
            await JitsiMeet().join(options);
          },
          child: Text('Join Meeting'),
        ),
      ),
    );
  }
}

4. 处理会议结束回调(可选)

如果你需要在会议结束时执行某些操作,你可以监听Jitsi Meet插件提供的事件。不过,由于custom_jitsi_meet_with_pointer_test可能是一个特定版本的插件,具体的回调方法可能会有所不同。以下是一个假设性的示例:

@override
void initState() {
  super.initState();
  // 假设插件提供了会议结束的事件监听
  JitsiMeet().addListener(() {
    // 会议结束时的回调逻辑
    print('Meeting ended');
  });
}

@override
void dispose() {
  // 移除监听器
  JitsiMeet().removeListener();
  super.dispose();
}

注意

  • 由于custom_jitsi_meet_with_pointer_test这个包名听起来非常特定,且可能不是官方或广泛使用的插件,因此具体的API和实现细节可能会有所不同。
  • 在实际项目中,更推荐使用经过验证和广泛使用的插件,如flutter_jitsi_meet
  • 确保你阅读并遵循插件的官方文档和示例代码,以获得最佳实践和最新信息。

如果你确实在使用flutter_jitsi_meet或类似的插件,并且需要更具体的帮助,请告知,我可以提供针对那个插件的详细示例。

回到顶部