Commit b50bfc64 by giaogiao

1.增加接口:创建频道,并邀请客户端加入;

2.RTC相关实体类创建;
3.RTC相关工具类创建;
parent 54fb1017
package com.wecloud.im.controller;
import com.wecloud.im.param.CreateRtcChannelResult;
import com.wecloud.im.param.add.CreateRtcChannelParam;
import com.wecloud.rtc.service.RtcService;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 音视频通话 控制器
*
* @author wei
* @since 2021-10-18
*/
@Slf4j
@RestController
@RequestMapping("/rtc")
@Api(value = "音视频通话", tags = {"音视频通话"})
public class ImRtcController extends BaseController {
@Autowired
private RtcService rtcService;
/**
* 创建频道,并邀请客户端加入
*/
@PostMapping("/createAndCall")
@ApiOperation(value = "创建频道,并邀请客户端加入", notes = "创建频道,并邀请客户端加入")
public ApiResult<CreateRtcChannelResult> createAndCall(@RequestBody CreateRtcChannelParam createRtcChannelParam) throws Exception {
CreateRtcChannelResult createRtcChannelResult = rtcService.create(createRtcChannelParam);
return ApiResult.ok(createRtcChannelResult);
}
public ApiResult<Boolean> join() {
return ApiResult.result(true);
}
public ApiResult<Boolean> reject() {
return ApiResult.result(true);
}
public ApiResult<Boolean> leave() {
return ApiResult.result(true);
}
public ApiResult<Boolean> sdpForword() {
return ApiResult.result(true);
}
public ApiResult<Boolean> candidateForword() {
return ApiResult.result(true);
}
}
package com.wecloud.im.param;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 创建频道返回参数
*
* @author wei
* @since 2021-04-29
*/
@Data
@ApiModel(value = "CreateRtcChannelResult")
public class CreateRtcChannelResult implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("频道id")
private Long channelId;
}
package com.wecloud.im.param.add;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 创建频道请求参数
*
* @author wei
* @since 2021-04-29
*/
@Data
@ApiModel(value = "CreateRtcChannelParam")
public class CreateRtcChannelParam implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "被邀请的客户端ID", required = true)
private String toClient;
@ApiModelProperty(value = "客户端自定义数据", required = false)
private String attrs;
@ApiModelProperty(value = "类型: video或voice", required = true)
private String type;
@ApiModelProperty(value = "绑定的会话id,可选", required = false)
private String toConversation;
@ApiModelProperty(value = "接收方展示的系统推送内容,可", required = false, example = "{" +
" \"title\":\"xxx正在邀请你视频通话\"," +
" \"subTitle\":\"点击接听\"" +
" }")
private String push;
@ApiModelProperty(value = "是否需要给对方发系统通知", required = true)
private Boolean pushCall;
}
package com.wecloud.im.param.add;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 创建频道请求参数
*
* @author wei
* @since 2021-04-29
*/
@Data
@ApiModel(value = "CreateRtcChannelParam")
public class JoinRtcChannelParam implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("频道id")
private Long channelId;
}
package com.wecloud.rtc.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* rtc 频道信息
*/
@Data
public class RtcChannelInfo implements Serializable {
@ApiModelProperty("当前房主")
String owner;
@ApiModelProperty("创建时间")
Long createTimestamp;
}
package com.wecloud.rtc.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* rtc 频道内的用户
*/
@Data
public class RtcJoinUser implements Serializable {
@ApiModelProperty("客户端")
String clientId;
@ApiModelProperty("加入时间")
Long createTimestamp;
String sdp;
}
package com.wecloud.rtc.entity;
import lombok.Data;
import java.io.Serializable;
/**
* rtc 频道内所有用户
*/
@Data
public class RtcJoinUsers implements Serializable {
}
package com.wecloud.rtc.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.wecloud.im.param.CreateRtcChannelResult;
import com.wecloud.im.param.add.CreateRtcChannelParam;
/**
* 管理rtc频道
*/
public interface RtcService {
/**
* 创建一个频道
*/
CreateRtcChannelResult create(CreateRtcChannelParam createRtcChannelParam) throws JsonProcessingException;
/**
* 加入频道
*/
void join();
/**
* 拒接加入频道
*/
void reject();
/**
* 退出频道
*/
void leave();
void sdpForword();
void candidateForword();
}
package com.wecloud.rtc.service.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient;
import com.wecloud.im.param.CreateRtcChannelResult;
import com.wecloud.im.param.add.CreateRtcChannelParam;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientService;
import com.wecloud.rtc.service.MangerRtcCacheService;
import com.wecloud.rtc.service.RtcService;
import io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class RtcServiceImpl implements RtcService {
@Autowired
private ImApplicationService imApplicationService;
/**
* redis缓存
*/
@Autowired
private MangerRtcCacheService mangerRtcCacheService;
@Autowired
private ImClientService imClientService;
@Override
public CreateRtcChannelResult create(CreateRtcChannelParam createRtcChannelParam) throws JsonProcessingException {
ImClient client = imClientService.getCurentClient();
Long rtcChannelId = SnowflakeUtil.getId();
// 根据appKey查询appid
ImApplication imApplication = imApplicationService.getById(client.getFkAppid());
mangerRtcCacheService.create(imApplication.getAppKey(), client.getClientId(), rtcChannelId);
CreateRtcChannelResult createRtcChannelResult = new CreateRtcChannelResult();
createRtcChannelResult.setChannelId(rtcChannelId);
// 像对方发送邀请
return createRtcChannelResult;
}
@Override
public void join() {
}
@Override
public void reject() {
}
@Override
public void leave() {
}
@Override
public void sdpForword() {
}
@Override
public void candidateForword() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment