forked from netease-kit/NEVideoCall-1to1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
5,820 additions
and
1,763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 36 additions & 27 deletions
63
...Demo-Android-Java/app/src/main/java/com/netease/yunxin/app/videocall/DemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...app/src/main/java/com/netease/yunxin/app/videocall/DemoSelfNotificationConfigFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.