2023-10-10 18:30:44 +08:00

231 lines
7.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.shayu.onetoone.manager;
import android.Manifest;
import android.view.SurfaceView;
import com.blankj.utilcode.util.PermissionUtils;
import com.shayu.onetoone.listener.OnCallStatusListener;
import com.yunbao.common.manager.IMLoginManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import io.rong.calllib.IRongCallListener;
import io.rong.calllib.IRongReceivedCallListener;
import io.rong.calllib.RongCallClient;
import io.rong.calllib.RongCallCommon;
import io.rong.calllib.RongCallSession;
import io.rong.calllib.StartCameraCallback;
import io.rong.imlib.model.Conversation;
public class CallClientManager {
public static CallClientManager manager;
public static CallClientManager getManager() {
if (manager == null) {
manager = new CallClientManager();
}
return manager;
}
private CallClientManager() {
init();
}
private void init() {
RongCallClient.setReceivedCallListener(new CallMeListener());
}
public void callVideo(String targetId, OnCallStatusListener statusListener) {
List<String> userIds = new ArrayList<>();
userIds.add(targetId);
RongCallClient.getInstance().setVoIPCallListener(new CallStatusListener(statusListener));
RongCallClient.getInstance().startCall(Conversation.ConversationType.PRIVATE,targetId,userIds,null, RongCallCommon.CallMediaType.VIDEO,null);
}
private static class CallMeListener implements IRongReceivedCallListener {
@Override
public void onReceivedCall(RongCallSession callSession) {
}
@Override
public void onCheckPermission(RongCallSession callSession) {
PermissionUtils.permission(Manifest.permission.CAMERA,Manifest.permission.RECORD_AUDIO).callback(new PermissionUtils.SimpleCallback() {
@Override
public void onGranted() {
RongCallClient.getInstance().onPermissionGranted();
}
@Override
public void onDenied() {
RongCallClient.getInstance().onPermissionDenied();
}
});
}
}
private static class CallStatusListener implements IRongCallListener {
OnCallStatusListener statusListener;
public CallStatusListener(OnCallStatusListener statusListener) {
this.statusListener = statusListener;
}
@Override
public void onCallIncoming(RongCallSession callSession, SurfaceView localVideo) {
}
/**
* 电话已拨出。
* 主叫端拨出电话后,通过回调 onCallOutgoing 通知当前 call 的详细信息。
*
* @param callSession 通话实体。
* @param localVideo 本地 camera 信息。
*/
@Override
public void onCallOutgoing(RongCallSession callSession, SurfaceView localVideo) {
statusListener.onCallWait(localVideo);
}
/**
* 已建立通话。
* 通话接通时,通过回调 onCallConnected 通知当前 call 的详细信息。
*
* @param callSession 通话实体。
* @param localVideo 本地 camera 信息。
*/
@Override
public void onCallConnected(RongCallSession callSession, SurfaceView localVideo) {
}
/**
* 通话结束。
* 通话中,对方挂断,己方挂断,或者通话过程网络异常造成的通话中断,都会回调 onCallDisconnected。
*
* @param callSession 通话实体。
* @param reason 通话中断原因。
*/
@Override
public void onCallDisconnected(RongCallSession callSession, RongCallCommon.CallDisconnectedReason reason) {
statusListener.onCallEnd();
}
@Override
public void onRemoteUserRinging(String userId) {
}
@Override
public void onRemoteUserAccept(String userId, RongCallCommon.CallMediaType mediaType) {
}
/**
* 被叫端加入通话。
* 主叫端拨出电话,被叫端收到请求后,加入通话,回调 onRemoteUserJoined。
*
* @param userId 加入用户的 id。<br />
* @param mediaType 加入用户的媒体类型audio or video。<br />
* @param userType 加入用户的类型1:正常用户,2:观察者。<br />
* @param remoteVideo 加入用户者的 camera 信息。如果 userType为2remoteVideo对象为空<br />
* 如果对端调用{@link RongCallClient#startCall(int, boolean, Conversation.ConversationType, String, List, List, RongCallCommon.CallMediaType, String, StartCameraCallback)} 或
* {@link RongCallClient#acceptCall(String, int, boolean, StartCameraCallback)}开始的音视频通话,则可以使用如下设置改变对端视频流的镜像显示:<br />
* <pre class="prettyprint">
* public void onRemoteUserJoined(String userId, RongCallCommon.CallMediaType mediaType, int userType, SurfaceView remoteVideo) {
* if (null != remoteVideo) {
* ((RongRTCVideoView) remoteVideo).setMirror( boolean);//观看对方视频流是否镜像处理
* }
* }
* </pre>
*/
@Override
public void onRemoteUserJoined(String userId, RongCallCommon.CallMediaType mediaType, int userType, SurfaceView remoteVideo) {
statusListener.onCallStart(userId,remoteVideo);
}
@Override
public void onRemoteUserInvited(String userId, RongCallCommon.CallMediaType mediaType) {
}
/**
* 通话中的远端参与者离开。
* 回调 onRemoteUserLeft 通知状态更新。
*
* @param userId 远端参与者的 id。
* @param reason 远端参与者离开原因。
*/
@Override
public void onRemoteUserLeft(String userId, RongCallCommon.CallDisconnectedReason reason) {
}
@Override
public void onMediaTypeChanged(String userId, RongCallCommon.CallMediaType mediaType, SurfaceView video) {
}
@Override
public void onError(RongCallCommon.CallErrorCode errorCode) {
}
@Override
public void onRemoteCameraDisabled(String userId, boolean disabled) {
}
@Override
public void onRemoteMicrophoneDisabled(String userId, boolean disabled) {
}
@Override
public void onNetworkReceiveLost(String userId, int lossRate) {
}
@Override
public void onNetworkSendLost(int lossRate, int delay) {
}
@Override
public void onFirstRemoteVideoFrame(String userId, int height, int width) {
}
@Override
public void onFirstRemoteAudioFrame(String userId) {
}
@Override
public void onAudioLevelSend(String audioLevel) {
}
@Override
public void onAudioLevelReceive(HashMap<String, String> audioLevel) {
}
@Override
public void onRemoteUserPublishVideoStream(String userId, String streamId, String tag, SurfaceView surfaceView) {
}
@Override
public void onRemoteUserUnpublishVideoStream(String userId, String streamId, String tag) {
}
}
}