com.qiniu.rtc.QRTCClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qiniu-java-sdk Show documentation
Show all versions of qiniu-java-sdk Show documentation
Qiniu Cloud Storage SDK for Java
// codebeat:disable[TOO_MANY_IVARS,TOO_MANY_FUNCTIONS,TOTAL_COMPLEXITY,ARITY]
package com.qiniu.rtc;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.rtc.model.*;
import com.qiniu.rtc.service.*;
import com.qiniu.util.Auth;
import com.qiniu.util.Json;
import com.qiniu.util.StringUtils;
import java.util.Map;
/**
* QRTC core api
*/
public class QRTCClient {
private final String accessKey;
private final String secretKey;
//rtc 房间服务接口
private RoomService roomService;
private ForwardService forwardService;
private CallbackService callbackService;
private MergeService mergeService;
private MergeServiceV4 mergeServiceV4;
private AppService appService;
// 应用ID
private final String appId;
//初始化的时候就把auth做了
public QRTCClient(String accessKey, String secretKey, String appId) {
// 变量赋值
this.accessKey = accessKey;
this.secretKey = secretKey;
this.appId = appId;
//auth 本class使用,不对外
Auth auth = auth();
initService(auth);
}
/**
* 初始化服务
*
* @param auth 授权对象
*/
private void initService(Auth auth) {
forwardService = new ForwardService(auth);
roomService = new RoomService(auth);
callbackService = new CallbackService(auth);
mergeService = new MergeService(auth);
appService = new AppService(auth);
mergeServiceV4 = new MergeServiceV4(auth);
}
/////////////////////////app service//////////////////////////////////////
/**
* 获取当前绑定的client的app信息
*
* @return
* @throws QiniuException
*/
public QRTCResult getApp() throws QiniuException {
ServiceCallFunc func = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return appService.getApp(appId);
}
};
return buildResult(func, AppResult.class);
}
/**
* 删除当前的app
*
* @return
* @throws QiniuException
*/
public QRTCResult deleteApp() throws QiniuException {
ServiceCallFunc func = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return appService.deleteApp(appId);
}
};
return buildResult(func, AppResult.class);
}
/**
* 更新app信息
*
* @param appParam
* @return
* @throws QiniuException
*/
public QRTCResult updateApp(final AppParam appParam) throws QiniuException {
ServiceCallFunc func = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return appService.updateApp(appParam);
}
};
return buildResult(func, AppResult.class);
}
/////////////////////////room service//////////////////////////////////////
/**
* 创建房间
*
* @param roomParam
* @return
* @throws QiniuException
*/
public QRTCResult createRoom(final RoomParam roomParam) throws QiniuException {
ServiceCallFunc func = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return roomService.createRoom(appId, roomParam);
}
};
return buildResult(func, RoomResult.class);
}
/**
* 删除房间
*
* @param roomName
* @return
* @throws QiniuException
*/
public QRTCResult deleteRoom(final String roomName) throws QiniuException {
ServiceCallFunc func = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return roomService.deleteRoom(appId, roomName);
}
};
return buildResult(func, RoomResult.class);
}
/**
* 获取房间内的所有用户
*
* @param roomName
* @return
* @throws QiniuException
*/
public QRTCResult listUser(final String roomName) throws QiniuException {
ServiceCallFunc func = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return roomService.listUser(appId, roomName);
}
};
return buildResult(func, RoomResult.class);
}
/**
* 指定一个用户踢出房间
*
* @param roomName
* @param userId
* @return
* @throws QiniuException
*/
public QRTCResult kickUser(final String roomName, final String userId) throws QiniuException {
ServiceCallFunc func = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return roomService.kickUser(appId, roomName, userId);
}
};
return buildResult(func, RoomResult.class);
}
/**
* 获取当前所有活跃的房间
*
* @param roomNamePrefix
* @param offset
* @param limit
* @return
* @throws QiniuException
*/
public QRTCResult listActiveRoom(final String roomNamePrefix, final int offset, final int limit)
throws QiniuException {
ServiceCallFunc func = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
UrlParam pageParam = UrlParam.builder().offset(offset).limit(limit).build();
return roomService.listActiveRoom(appId, roomNamePrefix, pageParam);
}
};
return buildResult(func, RoomResult.class);
}
/**
* 获取房间token
*
* @param roomName 房间名称,需满足规格 ^[a-zA-Z0-9_-]{3,64}$
* @param userId 请求加入房间的用户 ID,需满足规格 ^[a-zA-Z0-9_-]{3,50}$
* @param expireAt int64 类型,鉴权的有效时间,传入以秒为单位的64位Unix绝对时间,token 将在该时间后失效
* @param permission 该用户的房间管理权限,"admin" 或 "user",默认为 "user" 。当权限角色为 "admin" 时,拥有将其他用户移除出房
* 间等特权.
* @return roomToken 房间TOKEN
* @throws Exception
*/
public String getRoomToken(String roomName, String userId,
long expireAt, String permission) throws Exception {
RoomAccess access = new RoomAccess(appId, roomName, userId, expireAt, permission);
return roomService.getRoomToken(access);
}
/////////////////////////track service//////////////////////////////////////
/**
* 创建单路转推任务
*
* @param roomId
* @param param
* @return
* @throws QiniuException
*/
public QRTCResult createForwardJob(final String roomId, final ForwardParam param) throws QiniuException {
ServiceCallFunc createForwardJobFunc = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return forwardService.createForwardJob(appId, roomId, param);
}
};
return buildResult(createForwardJobFunc, ForwardResult.class);
}
/**
* 停止单路转推的能力
*
* @param roomId
* @param param
* @return
* @throws QiniuException
*/
public QRTCResult stopForwardJob(final String roomId, final ForwardParam param) throws QiniuException {
ServiceCallFunc stopForwardJobFunc = new ServiceCallFunc() {
@Override
public Response call() throws QiniuException {
return forwardService.stopForwardJob(appId, roomId, param);
}
};
return buildResult(stopForwardJobFunc, ForwardResult.class);
}
/////////////////////////http callback service//////////////////////////////////////
/**
* 设置服务端回调接口
*
* @param param
* @return
* @throws QiniuException
*/
public QRTCResult
© 2015 - 2024 Weber Informatics LLC | Privacy Policy