Przeglądaj źródła

<去掉一些无用代码>

weizhengliang 4 lat temu
rodzic
commit
28e2e16dc8

+ 2 - 2
webrtc/src/main/AndroidManifest.xml

@@ -47,11 +47,11 @@
             android:showOnLockScreen="true"
             android:theme="@style/AppTheme.NoActionBar" />
 
-        <receiver android:name="com.wdkl.core.voip.VoipReceiver">
+        <!--<receiver android:name="com.wdkl.core.voip.VoipReceiver">
             <intent-filter>
                 <action android:name="${applicationId}.voip.Receiver" />
             </intent-filter>
-        </receiver>
+        </receiver>-->
     </application>
 
 </manifest>

+ 13 - 3
webrtc/src/main/java/com/wdkl/core/socket/SocketManager.java

@@ -7,7 +7,9 @@ import android.os.Handler;
 import android.os.Looper;
 import android.util.Log;
 
+import com.wdkl.core.voip.CallSingleActivity;
 import com.wdkl.core.voip.Utils;
+import com.wdkl.core.voip.VoipEvent;
 import com.wdkl.core.voip.VoipReceiver;
 import com.wdkl.skywebrtc.CallSession;
 import com.wdkl.skywebrtc.EnumType;
@@ -204,8 +206,7 @@ public class SocketManager implements IEvent {
     // ========================================================================================
     @Override
     public void onInvite(String room, boolean audioOnly, String inviteId, String userList) {
-        //todo: 待处理
-        Intent intent = new Intent();
+        /*Intent intent = new Intent();
         intent.putExtra("room", room);
         intent.putExtra("audioOnly", audioOnly);
         intent.putExtra("inviteId", inviteId);
@@ -213,8 +214,17 @@ public class SocketManager implements IEvent {
         intent.setAction(Utils.ACTION_VOIP_RECEIVER);
         intent.setComponent(new ComponentName(mContext.getPackageName(), VoipReceiver.class.getName()));
         // 发送广播
-        mContext.sendBroadcast(intent);
+        mContext.sendBroadcast(intent);*/
 
+        receivedIncomingCall(room, audioOnly, inviteId, userList);
+    }
+
+    private void receivedIncomingCall(String room, boolean audioOnly, String inviteId, String userList) {
+        SkyEngineKit.init(new VoipEvent());
+        boolean b = SkyEngineKit.Instance().startInCall(mContext, room, inviteId, audioOnly);
+        if (b) {
+            CallSingleActivity.openActivity(mContext, inviteId, false, inviteId, audioOnly, false);
+        }
     }
 
     @Override

+ 6 - 107
webrtc/src/main/java/com/wdkl/core/voip/CallSingleActivity.java

@@ -64,9 +64,9 @@ public class CallSingleActivity extends BaseActivity implements CallSession.Call
         voip.putExtra(CallSingleActivity.EXTRA_USER_NAME, inviteUserName);
         voip.putExtra(CallSingleActivity.EXTRA_AUDIO_ONLY, isAudioOnly);
         voip.putExtra(CallSingleActivity.EXTRA_FROM_FLOATING_VIEW, false);
-        if (isClearTop) {
-            voip.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-        }
+        //if (isClearTop) {
+        //    voip.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        //}
         return voip;
     }
 
@@ -74,12 +74,8 @@ public class CallSingleActivity extends BaseActivity implements CallSession.Call
     public static void openActivity(Context context, String targetId, boolean isOutgoing, String inviteUserName,
                                     boolean isAudioOnly, boolean isClearTop) {
         Intent intent = getCallIntent(context, targetId, isOutgoing, inviteUserName, isAudioOnly, isClearTop);
-        //if (context instanceof Activity) {
-        //    context.startActivity(intent);
-        //} else {
-            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            context.startActivity(intent);
-        //}
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        context.startActivity(intent);
     }
 
     @Override
@@ -104,31 +100,7 @@ public class CallSingleActivity extends BaseActivity implements CallSession.Call
         isOutgoing = intent.getBooleanExtra(EXTRA_MO, false);
         isAudioOnly = intent.getBooleanExtra(EXTRA_AUDIO_ONLY, false);
 
-        if (isFromFloatingView) {
-            //Intent serviceIntent = new Intent(this, FloatingVoipService.class);
-            //stopService(serviceIntent);
-            //init(targetId, false, isAudioOnly, false);
-        } else {
-            // 权限检测
-            String[] per;
-            if (isAudioOnly) {
-                per = new String[]{Manifest.permission.RECORD_AUDIO};
-            } else {
-                per = new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA};
-            }
-            Permissions.request(this, per, integer -> {
-                Log.d(TAG, "Permissions.request integer = " + integer);
-                if (integer == 0) {
-                    // 权限同意
-                    init(targetId, isOutgoing, isAudioOnly);
-                } else {
-                    Toast.makeText(this, "权限被拒绝", Toast.LENGTH_SHORT).show();
-                    // 权限拒绝
-                    finish();
-                }
-            });
-        }
-
+        init(targetId, isOutgoing, isAudioOnly);
 
     }
 
@@ -179,72 +151,12 @@ public class CallSingleActivity extends BaseActivity implements CallSession.Call
             if (session == null) {
                 finish();
             } else {
-                /*if (session.isAudioOnly() && !audioOnly) { //这种情况是,对方切换成音频的时候,activity还没启动,这里启动后需要切换一下
-                    isAudioOnly = session.isAudioOnly();
-                    fragment.didChangeMode(true);
-                }*/
                 session.setSessionCallback(this);
-                //session.toggleSpeaker(true);
-
-                //之前已经通过tcp接受了,此时sip通话建立,直接接通
-                /*if (session.getState() == EnumType.CallState.Incoming) {
-                    session.joinHome(session.getRoomId());
-                } else {
-                    session.sendRefuse();
-                }*/
             }
         }
 
     }
 
-    private void init(String targetId, boolean outgoing, boolean audioOnly, boolean isReplace) {
-        SingleCallFragment fragment;
-        if (audioOnly) {
-            fragment = new FragmentAudio();
-        } else {
-            fragment = new FragmentVideo();
-        }
-        FragmentManager fragmentManager = getSupportFragmentManager();
-        currentFragment = fragment;
-        if (isReplace) {
-            fragmentManager.beginTransaction()
-                    .replace(android.R.id.content, fragment)
-                    .commit();
-        } else {
-            fragmentManager.beginTransaction()
-                    .add(android.R.id.content, fragment)
-                    .commit();
-        }
-        if (outgoing && !isReplace) {
-            // 创建会话
-            room = UUID.randomUUID().toString() + System.currentTimeMillis();
-            boolean b = gEngineKit.startOutCall(getApplicationContext(), room, targetId, audioOnly);
-            if (!b) {
-                finish();
-                return;
-            }
-            //App.getInstance().setRoomId(room);
-            //App.getInstance().setOtherUserId(targetId);
-            CallSession session = gEngineKit.getCurrentSession();
-            if (session == null) {
-                finish();
-            } else {
-                session.setSessionCallback(this);
-            }
-        } else {
-            CallSession session = gEngineKit.getCurrentSession();
-            if (session == null) {
-                finish();
-            } else {
-                //if (session.isAudioOnly() && !audioOnly) { //这种情况是,对方切换成音频的时候,activity还没启动,这里启动后需要切换一下
-                //    isAudioOnly = session.isAudioOnly();
-                //    fragment.didChangeMode(true);
-                //}
-                session.setSessionCallback(this);
-            }
-        }
-
-    }
 
     public SkyEngineKit getEngineKit() {
         return gEngineKit;
@@ -259,19 +171,6 @@ public class CallSingleActivity extends BaseActivity implements CallSession.Call
         return isFromFloatingView;
     }
 
-    // 显示小窗
-    /*public void showFloatingView() {
-        if (!checkOverlayPermission()) {
-            return;
-        }
-        Intent intent = new Intent(this, FloatingVoipService.class);
-        intent.putExtra(EXTRA_TARGET, targetId);
-        intent.putExtra(EXTRA_AUDIO_ONLY, isAudioOnly);
-        intent.putExtra(EXTRA_MO, isOutgoing);
-        startService(intent);
-        finish();
-    }*/
-
     // 切换到语音通话
     public void switchAudio() {
         //init(targetId, isOutgoing, true, true);