Skip to content

Commit

Permalink
feat: 支持群呼
Browse files Browse the repository at this point in the history
  • Loading branch information
wulei05 committed Nov 13, 2024
1 parent 3f99922 commit bb38549
Show file tree
Hide file tree
Showing 85 changed files with 5,820 additions and 1,763 deletions.
6 changes: 5 additions & 1 deletion NLiteAVDemo-Android-Java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

namespace "com.netease.yunxin.app.videocall"
defaultConfig {
applicationId "com.netease.yunxin.app.videocall"

minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode Integer.parseInt(VERSION_CODE)
Expand Down Expand Up @@ -64,5 +64,9 @@ dependencies {
implementation(libs.retrofitConverterGson)
implementation(libs.nertc.nenn)
implementation(libs.nertc.segment)
implementation(libs.im.basesdk)
implementation(libs.im.chatroom)
implementation(libs.im.push)
implementation(libs.im.avsignalling)
implementation project(':call-ui')
}
51 changes: 35 additions & 16 deletions NLiteAVDemo-Android-Java/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.netease.yunxin.app.videocall">
<!-- Copyright (c) 2022 NetEase, Inc. All rights reserved. -->
<!-- Use of this source code is governed by a MIT license that can be -->
<!-- found in the LICENSE file. -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- 访问网络状态-->
<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -16,7 +19,6 @@
<!-- 多媒体相关 -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<!-- 控制呼吸灯,振动器等,用于新消息提醒 -->
Expand All @@ -34,12 +36,10 @@

<!-- 下面的 uses-permission 一起加入到你的 AndroidManifest 文件中。 -->
<permission
android:name="com.netease.yunxin.app.videocall.permission.RECEIVE_MSG"
android:name="${applicationId}.permission.RECEIVE_MSG"
android:protectionLevel="signature" />

<uses-permission android:name="com.netease.yunxin.app.videocall.permission.RECEIVE_MSG" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="${applicationId}.permission.RECEIVE_MSG" />

<application
android:name="com.netease.yunxin.app.videocall.DemoApplication"
Expand All @@ -51,6 +51,9 @@
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">

<!--如果 Android targetSdkVersion 大于等于 31,需要添加以下标签,否则虚拟背景功能无法使用-->
<uses-native-library android:name="libOpenCL.so" android:required="false"/>

<activity
android:name="com.netease.yunxin.app.videocall.SplashActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"
Expand All @@ -68,7 +71,7 @@
android:name="com.netease.yunxin.app.videocall.MainActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:screenOrientation="portrait"
android:exported="false"
android:exported="true"
android:launchMode="singleTask">

<intent-filter>
Expand All @@ -94,13 +97,32 @@
android:name="com.netease.yunxin.app.videocall.nertc.ui.NERTCSelectCallUserActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing"
android:theme="@style/Theme.AppCompat.NoActionBar"/>

<activity
android:name=".TestActivity"
android:launchMode="singleTask"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.AppCompat.NoActionBar"/>

<activity
android:name="com.netease.yunxin.app.videocall.nertc.ui.SettingActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar"/>

<activity
android:name="com.netease.yunxin.app.videocall.nertc.ui.SelfSignalActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar"/>

<activity
android:name="com.netease.yunxin.app.videocall.nertc.ui.GroupSettingActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar"/>

<!-- 云信后台服务,请使用独立进程。 -->
<service
Expand Down Expand Up @@ -136,13 +158,10 @@
<!-- 云信进程间通信service -->
<service android:name="com.netease.nimlib.service.ResponseService" />

<!-- 云信进程间通信provider -->
<!-- android:authorities="{包名}.ipc.provider", 请将com.netease.nim.demo替换为自己的包名 -->
<provider
android:name="com.netease.nimlib.ipc.NIMContentProvider"
android:authorities="com.netease.yunxin.app.videocall.ipc.provider"
<service android:name="com.netease.lava.nertc.foreground.ForegroundService"
android:enabled="true"
android:exported="false"
android:process=":core" />
/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

package com.netease.yunxin.app.videocall;

import android.app.Application;
import android.text.TextUtils;

import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.SDKOptions;
import com.netease.nimlib.sdk.auth.LoginInfo;
import com.netease.nimlib.sdk.util.NIMUtil;
import com.netease.yunxin.app.videocall.login.model.ProfileManager;
import com.netease.yunxin.app.videocall.login.model.UserModel;
import com.netease.yunxin.app.videocall.login.model.AuthManager;
import com.netease.yunxin.app.videocall.login.model.LoginModel;
import com.netease.yunxin.nertc.nertcvideocall.utils.NetworkUtils;

import com.netease.yunxin.nertc.ui.CallKitUI;

public class DemoApplication extends Application {
public static DemoApplication app;
public static DemoApplication app;

@Override
public void onCreate() {
super.onCreate();
if (NIMUtil.isMainProcess(this)) {
NetworkUtils.init(this);
app = this;
}
NIMClient.init(this, loginInfo(), options());
@Override
public void onCreate() {
super.onCreate();
if (NIMUtil.isMainProcess(this)) {
app = this;
}

// 如果返回值为 null,则全部使用默认参数。
private SDKOptions options() {
SDKOptions options = new SDKOptions();
//此处仅设置appkey,其他设置请自行参看信令文档设置 :https://dev.yunxin.163.com/docs/product/信令/SDK开发集成/Android开发集成/初始化
options.appKey = BuildConfig.APP_KEY;
return options;
NIMClient.initV2(this, options());
if (NIMUtil.isMainProcess(this)) {
NetworkUtils.init(this);
// 预收到离线消息时需在 IM 初始化后立即注册群组
CallKitUI.preGroupConfig();
}
}

// 如果返回值为 null,则全部使用默认参数。
private SDKOptions options() {
SDKOptions options = new SDKOptions();
//此处仅设置appkey,其他设置请自行参看信令文档设置 :https://dev.yunxin.163.com/docs/product/信令/SDK开发集成/Android开发集成/初始化
options.appKey = BuildConfig.APP_KEY;
return options;
}

// 如果已经存在用户登录信息,返回LoginInfo,否则返回null即可
private LoginInfo loginInfo() {
UserModel userModel = ProfileManager.getInstance().getUserModel();
if (userModel != null && !TextUtils.isEmpty(userModel.imToken) && !TextUtils.isEmpty(userModel.imAccid)) {
return new LoginInfo(String.valueOf(userModel.imAccid), userModel.imToken);
}
return null;
// 如果已经存在用户登录信息,返回LoginInfo,否则返回null即可
private LoginInfo loginInfo() {
LoginModel userModel = AuthManager.getInstance().getUserModel();
if (userModel != null
&& !TextUtils.isEmpty(userModel.imToken)
&& !TextUtils.isEmpty(userModel.imAccid)) {
return new LoginInfo(String.valueOf(userModel.imAccid), userModel.imToken);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

package com.netease.yunxin.app.videocall;

import android.text.TextUtils;
import com.netease.yunxin.kit.alog.ALog;
import com.netease.yunxin.kit.call.group.NEGroupCallInfo;
import com.netease.yunxin.kit.call.p2p.model.NEInviteInfo;
import com.netease.yunxin.nertc.ui.CallKitNotificationConfig;
import kotlin.jvm.functions.Function1;
import org.json.JSONObject;

class DemoSelfNotificationConfigFetcher<T> implements Function1<T, CallKitNotificationConfig> {
public final String TAG = "DemoSelfNotificationConfigFetcher";

@Override
public CallKitNotificationConfig invoke(T info) {
String name = null;
if (info instanceof NEInviteInfo) {
NEInviteInfo invitedInfo = (NEInviteInfo) info;
name = getUserName(invitedInfo.callerAccId, invitedInfo.extraInfo);
} else if (info instanceof NEGroupCallInfo) {
NEGroupCallInfo groupCallInfo = (NEGroupCallInfo) info;
name = getUserName(groupCallInfo.callerAccId, groupCallInfo.extraInfo);
}
return new CallKitNotificationConfig(
R.mipmap.ic_launcher, null, "您有新的来电", name + "邀请您进行【网络通话】");
}

/**
* 这里可以自定义信息展示
*
* @param accId
* @param inviteExtraInfo
* @return
*/
private String getUserName(String accId, String inviteExtraInfo) {
String name;
try {
JSONObject object = new JSONObject(inviteExtraInfo);
name = object.optString("userName");
} catch (Exception exception) {
ALog.e(TAG, "parse inviteInfo extra error.", exception);
name = "";
}
if (TextUtils.isEmpty(name)) {
name = accId;
}
return name;
}
}
Loading

0 comments on commit bb38549

Please sign in to comment.