Skip to content

Commit

Permalink
Merge pull request #56 from chandarlee/v1.3.1
Browse files Browse the repository at this point in the history
V1.3.1
  • Loading branch information
liuqijun authored Nov 16, 2020
2 parents 8b2b1e8 + 4b0aff2 commit 678d838
Show file tree
Hide file tree
Showing 44 changed files with 1,543 additions and 214 deletions.
16 changes: 8 additions & 8 deletions SampleCode/Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ android {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//app demo dependencies

//Demo依赖
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
Expand All @@ -55,16 +56,15 @@ dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'

//meeting
implementation 'com.netease.yunxin:meetinglib:1.3.0'
//nim
implementation 'com.netease.nimlib:basesdk:7.6.0'

//third party
implementation 'com.manu:MDatePicker:1.0.1'
implementation 'com.kyleduo.switchbutton:library:2.0.2'

//NEMeeting-SDK
implementation 'com.netease.yunxin:meetinglib:1.3.1'

//NIM-SDK, 如果单独接入了云信NIM,则可根据需要进行依赖声明。正常情况下不用声明
implementation 'com.netease.nimlib:basesdk:7.6.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
16 changes: 13 additions & 3 deletions SampleCode/Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,32 @@
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:resizeableActivity="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="meeting.netease.im"
android:scheme="nemeetingdemo" />
</intent-filter>

</activity>
<activity
android:name=".MeetingSettingsActivity"
android:label="会议设置" />
<activity
android:name=".AppSettingsActivity"
android:label="应用设置" />
<activity
android:name=".nim.NIMLoginActivity"
android:label="IM登录" />
</application>
<!--日历-->
<uses-permission android:name="android.permission.READ_CALENDAR" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -209,6 +212,22 @@ private void updateMeetingTime(String timeText) {
binding.meetingTime.setText(timeText);
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String deepLink = intent.getDataString();
ssoLogin(deepLink);
}

private void ssoLogin(String deepLink){
if(!TextUtils.isEmpty(deepLink)) {
String ssoToken = Uri.parse(deepLink).getQueryParameter("ssoToken");
if(!TextUtils.isEmpty(ssoToken)){
SdkAuthenticator.getInstance().loginWithSSO(ssoToken);
}
}
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.app.Application;

import com.netease.meetinglib.demo.log.LogUtil;
import com.netease.meetinglib.demo.nim.NIMInitializer;

public class MeetingApplication extends Application {
private static MeetingApplication instance;
Expand All @@ -17,6 +18,7 @@ public void onCreate() {
super.onCreate();
instance = this;
LogUtil.init(this);
NIMInitializer.getInstance().startInitialize(this);
SdkAuthenticator.getInstance().initialize(this);
SdkInitializer.getInstance().startInitialize(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public static SdkAuthenticator getInstance() {
return INSTANCE;
}

private static final String KEY_LOGIN_SUCCEED = "LOGIN_SUCCEED";
private static final String KEY_ACCOUNT = "ACCOUNT";
private static final String KEY_PWD = "PWD";
public static final String KEY_NICK_NAME = "NICK_NAME";

private Context context;

private AtomicInteger state = new AtomicInteger(UN_AUTHORIZE);
private final AtomicInteger state = new AtomicInteger(UN_AUTHORIZE);
private AuthStateChangeListener authStateChangeListener;
private DataRepository dataRepository = new DefaultDataRepository();
private final DataRepository dataRepository = new DefaultDataRepository();

private SdkAuthenticator() {
}
private SdkAuthenticator() {}

public void initialize(Context context) {
this.context = context;
Expand All @@ -62,7 +62,7 @@ public void initialize(Context context) {
@Override
public void onInitialized(int initializeIndex) {
if (initializeIndex == 1) {
loginWithCachedAccount();
tryAutoLogin();
}
NEMeetingSDK.getInstance().addAuthListener(new NEAuthListener() {
@Override
Expand Down Expand Up @@ -99,11 +99,13 @@ public int getState() {
return state.get();
}

private void loginWithCachedAccount() {
final String account = SPUtils.getInstance().getString(KEY_ACCOUNT, "");
final String pwd = SPUtils.getInstance().getString(KEY_PWD, "");
if (!TextUtils.isEmpty(account) && !TextUtils.isEmpty(pwd)) {
login(account, pwd);
public void loginWithNEMeeting(final String account, final String pwd) {
if (state.get() == AUTHORIZED) {
Toast.makeText(context, "您已登录", Toast.LENGTH_SHORT).show();
}else{
state.set(AUTHORIZING);
notifyStateChanged();
handleLoginWithNEMeeting(account, pwd);
}
}

Expand All @@ -130,6 +132,28 @@ protected void onPostExecute(Response<SDKAuthInfo> response) {
}
}

@SuppressLint("StaticFieldLeak")
public void loginWithSDKToken(final String accountId, final String accountToken) {
NEMeetingSDK.getInstance().login(accountId, accountToken,
new ToastCallback<Void>(context, "登录") {
@Override
public void onResult(int resultCode, String resultMsg, Void resultData) {
super.onResult(resultCode, resultMsg, resultData);
onLoginResult(resultCode, null, null);
}
});
}

public void loginWithSSO(final String ssoToken) {
if (state.get() == AUTHORIZED) {
Toast.makeText(context, "您已登录", Toast.LENGTH_SHORT).show();
}else{
state.set(AUTHORIZING);
notifyStateChanged();
handleLoginWithSSO(ssoToken);
}
}

public void logout(boolean manual) {
if (state.get() == AUTHORIZED) {
NEMeetingSDK.getInstance().logout(new ToastCallback<Void>(context, "注销") {
Expand All @@ -143,6 +167,7 @@ public void onResult(int resultCode, String resultMsg, Void resultData) {
SPUtils.getInstance().remove(KEY_NICK_NAME);
notifyStateChanged();
}
SPUtils.getInstance().put(KEY_LOGIN_SUCCEED, false);
}
}
});
Expand All @@ -156,15 +181,9 @@ private void handleResponse(String account, String pwd, Response<SDKAuthInfo> re
@Override
public void onResult(int resultCode, String resultMsg, Void resultData) {
super.onResult(resultCode, resultMsg, resultData);
if (resultCode == NEMeetingError.ERROR_CODE_SUCCESS) {
state.set(AUTHORIZED);
SPUtils.getInstance()
.put(KEY_ACCOUNT, account)
.put(KEY_PWD, pwd);
} else {
state.set(AUTHOR_FAIL);
}
notifyStateChanged();
onLoginResult(resultCode,
() -> SPUtils.getInstance().put(KEY_ACCOUNT, account).put(KEY_PWD, pwd),
null);
}
});
} else {
Expand All @@ -176,6 +195,62 @@ public void onResult(int resultCode, String resultMsg, Void resultData) {
}
}

private void handleLoginWithNEMeeting(String account, String pwd) {
NEMeetingSDK.getInstance().loginWithNEMeeting(account, pwd,
new ToastCallback<Void>(context, "登录") {
@Override
public void onResult(int resultCode, String resultMsg, Void resultData) {
super.onResult(resultCode, resultMsg, resultData);
onLoginResult(resultCode,
() -> SPUtils.getInstance().put(KEY_ACCOUNT, account).put(KEY_PWD, pwd),
null);
}
});
}

private void handleLoginWithSSO(String ssoToken) {
NEMeetingSDK.getInstance().loginWithSSOToken(ssoToken,
new ToastCallback<Void>(context, "SSO登录") {
@Override
public void onResult(int resultCode, String resultMsg, Void resultData) {
super.onResult(resultCode, resultMsg, resultData);
onLoginResult(resultCode, null, null);
}
});
}

private void tryAutoLogin(){
if (SPUtils.getInstance().getBoolean(KEY_LOGIN_SUCCEED)) {
NEMeetingSDK.getInstance().tryAutoLogin(
new ToastCallback<Void>(context, "自动登录") {
@Override
public void onResult(int resultCode, String resultMsg, Void resultData) {
super.onResult(resultCode, resultMsg, resultData);
onLoginResult(resultCode, null, null);
}
});
}
}

private void onLoginResult(int code, Runnable onSuccessAction, Runnable onFailAction) {
final boolean success;
if (code == NEMeetingError.ERROR_CODE_SUCCESS) {
success = true;
state.set(AUTHORIZED);
if (onSuccessAction != null) {
onSuccessAction.run();
}
} else {
success = false;
state.set(AUTHOR_FAIL);
if (onFailAction != null) {
onFailAction.run();
}
}
SPUtils.getInstance().put(KEY_LOGIN_SUCCEED, success);
notifyStateChanged();
}

private void onKickedOut() {
Log.i(TAG, "onKickOut");
Toast.makeText(context, "当前账号已在其他设备上登录", Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -225,4 +300,4 @@ public interface AuthStateChangeListener {
void onAuthStateChanged(int state);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import androidx.annotation.NonNull;

import com.netease.meetinglib.demo.nim.NIMInitializer;
import com.netease.meetinglib.demo.utils.SPUtils;
import com.netease.meetinglib.sdk.NEMeetingError;
import com.netease.meetinglib.sdk.NEMeetingSDK;
Expand Down Expand Up @@ -77,6 +78,7 @@ private void initializeSdk() {
Log.i(TAG, "initializeSdk");
NEMeetingSDKConfig config = new NEMeetingSDKConfig();
config.appKey = context.getString(R.string.appkey);
config.reuseNIM = NIMInitializer.getInstance().isReuseNIMEnabled();
config.appName = context.getString(R.string.app_name);
config.useAssetServerConfig = SPUtils.getInstance().getBoolean("use-asset-server-config");
//配置会议时显示前台服务
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2014-2020 NetEase, Inc.
* All right reserved.
*/

package com.netease.meetinglib.demo.nim;

import android.content.Context;
import android.util.Log;

import com.netease.meetinglib.demo.utils.ProcessUtils;
import com.netease.meetinglib.demo.utils.SPUtils;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.SDKOptions;

import java.io.File;

public class NIMInitializer {

private static final String TAG = "NIMInitializer";

private static NIMInitializer sInstance;

public synchronized static NIMInitializer getInstance() {
if (sInstance == null) {
sInstance = new NIMInitializer();
}
return sInstance;
}

private NIMInitializer() {}

//如果开启了NIM复用,则需要单独进行NIM的初始化
//正常情况下不需要单独手动进行初始化
public void startInitialize(Context context) {
if (isReuseNIMEnabled()) {
Log.i(TAG, "reuse nim is enabled");
SDKOptions sdkOptions = SDKOptions.DEFAULT;
sdkOptions.disableAwake = true;
sdkOptions.useAssetServerAddressConfig = SPUtils.getInstance().getBoolean("use-asset-server-config");
File externalFilesDir = context.getExternalFilesDir(null);
sdkOptions.sdkStorageRootPath = externalFilesDir != null ? externalFilesDir.getAbsolutePath() : null;
NIMClient.config(context, null, sdkOptions);
if (ProcessUtils.isMainProcess(context)) {
NIMClient.initSDK();
}
}
}

public boolean isReuseNIMEnabled() {
return SPUtils.getInstance().getBoolean("meeting-reuse-nim", false);
}

public void setReuseNIMEnabled(boolean enable) {
SPUtils.getInstance().put("meeting-reuse-nim", enable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ public class EntranceFragment extends BaseFragment<FragmentEntranceBinding> {
protected void initView() {

setHandleOnBackDesktopPressed(true);
binding.btnLogin.setOnClickListener(v ->
Navigation.findNavController(getView()).navigate(R.id.action_entranceFragment_to_loginFragment)

binding.btnLoginWithNeMeeting.setOnClickListener(v ->
Navigation.findNavController(getView()).navigate(R.id.action_entranceFragment_to_loginWithNEMeetingFragment)
);

binding.btnLoginWithToken.setOnClickListener(v ->
Navigation.findNavController(getView()).navigate(R.id.action_entranceFragment_to_loginWithTokenFragment)
);

binding.btnLoginWithSso.setOnClickListener(v ->
Navigation.findNavController(getView()).navigate(R.id.action_entranceFragment_to_loginWithSSOFragment)
);

binding.btnJoinMeeting.setOnClickListener(v ->
Expand Down
Loading

0 comments on commit 678d838

Please sign in to comment.