Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b6277579c8
|
|
@ -0,0 +1,2 @@
|
|||
/.idea/
|
||||
/target/
|
||||
|
|
@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
//@Component
|
||||
public class WebLogAspect {
|
||||
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package com.zhangshu.chat.demo.controller;
|
||||
|
||||
import com.zhangshu.chat.demo.dto.AgoraEventDto;
|
||||
import com.zhangshu.chat.demo.dto.CommonResult;
|
||||
import com.zhangshu.chat.demo.service.EventService;
|
||||
import com.zhangshu.chat.demo.vo.LoginVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -13,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/event")
|
||||
|
|
@ -23,9 +23,9 @@ public class EventController {
|
|||
|
||||
@PostMapping("/agora")
|
||||
@ApiOperation(value = "agora")
|
||||
public CommonResult agora(@RequestBody AgoraEventDto dto) {
|
||||
log.info("事件回调:{}", dto);
|
||||
eventService.agora(dto);
|
||||
public CommonResult agora(@RequestBody Map<String,Object> body) {
|
||||
log.info("事件回调:{}", body);
|
||||
eventService.agora(body);
|
||||
return CommonResult.success();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.zhangshu.chat.demo.service;
|
|||
|
||||
import com.zhangshu.chat.demo.dto.AgoraEventDto;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface EventService {
|
||||
void agora(AgoraEventDto dto);
|
||||
void agora(Map<String, Object> body);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package com.zhangshu.chat.demo.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.zhangshu.chat.demo.config.AgoraProperties;
|
||||
import com.zhangshu.chat.demo.constant.EAgoraEventType;
|
||||
import com.zhangshu.chat.demo.constant.ERoomUserType;
|
||||
import com.zhangshu.chat.demo.dto.AgoraChannelEventDto;
|
||||
import com.zhangshu.chat.demo.dto.AgoraChannelUserEventDto;
|
||||
import com.zhangshu.chat.demo.dto.AgoraEventDto;
|
||||
import com.zhangshu.chat.demo.entity.Room;
|
||||
import com.zhangshu.chat.demo.entity.User;
|
||||
import com.zhangshu.chat.demo.mapper.UserMapper;
|
||||
import com.zhangshu.chat.demo.vo.RoomUserVo;
|
||||
|
|
@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
|
|
@ -25,21 +27,28 @@ public class EventServiceImpl implements EventService {
|
|||
@Autowired
|
||||
UserMapper userMapper;
|
||||
|
||||
<T> T mapToBean(Map<String, Object> map, Class<T> targetClass) {
|
||||
return BeanUtil.mapToBean(map, targetClass, false, CopyOptions.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void agora(AgoraEventDto dto) {
|
||||
switch (dto.getEventType()) {
|
||||
public void agora(Map<String, Object> body) {
|
||||
|
||||
Object eventTypeObj = body.get("eventType");
|
||||
EAgoraEventType eventType = EAgoraEventType.getByType((Integer) eventTypeObj);
|
||||
switch (eventType) {
|
||||
case channel_create: {
|
||||
AgoraChannelEventDto eventDto = dto.convert(AgoraChannelEventDto.class);
|
||||
AgoraChannelEventDto eventDto = mapToBean(body, AgoraChannelEventDto.class);
|
||||
roomCache.add(eventDto.getChannelName());
|
||||
}
|
||||
break;
|
||||
case channel_destroy: {
|
||||
AgoraChannelEventDto eventDto = dto.convert(AgoraChannelEventDto.class);
|
||||
AgoraChannelEventDto eventDto = mapToBean(body, AgoraChannelEventDto.class);
|
||||
roomCache.remove(eventDto.getChannelName());
|
||||
}
|
||||
break;
|
||||
case broadcaster_join_channel: {
|
||||
AgoraChannelUserEventDto eventDto = dto.convert(AgoraChannelUserEventDto.class);
|
||||
AgoraChannelUserEventDto eventDto = mapToBean(body, AgoraChannelUserEventDto.class);
|
||||
User user = userMapper.selectById(eventDto.getUid());
|
||||
if (Objects.isNull(user)) {
|
||||
break;
|
||||
|
|
@ -54,12 +63,12 @@ public class EventServiceImpl implements EventService {
|
|||
break;
|
||||
case broadcaster_leave_channel:
|
||||
case audience_leave_channel: {
|
||||
AgoraChannelUserEventDto eventDto = dto.convert(AgoraChannelUserEventDto.class);
|
||||
AgoraChannelUserEventDto eventDto = mapToBean(body, AgoraChannelUserEventDto.class);
|
||||
roomCache.removeUser(eventDto.getChannelName(), eventDto.getUid());
|
||||
}
|
||||
break;
|
||||
case audience_join_channel: {
|
||||
AgoraChannelUserEventDto eventDto = dto.convert(AgoraChannelUserEventDto.class);
|
||||
AgoraChannelUserEventDto eventDto = mapToBean(body, AgoraChannelUserEventDto.class);
|
||||
User user = userMapper.selectById(eventDto.getUid());
|
||||
if (Objects.isNull(user)) {
|
||||
break;
|
||||
|
|
@ -73,12 +82,12 @@ public class EventServiceImpl implements EventService {
|
|||
}
|
||||
break;
|
||||
case client_role_change_to_audience: {
|
||||
AgoraChannelUserEventDto eventDto = dto.convert(AgoraChannelUserEventDto.class);
|
||||
AgoraChannelUserEventDto eventDto = mapToBean(body, AgoraChannelUserEventDto.class);
|
||||
roomCache.changeUserType(eventDto.getChannelName(), eventDto.getUid(), ERoomUserType.audience);
|
||||
}
|
||||
break;
|
||||
case client_role_change_to_broadcaster: {
|
||||
AgoraChannelUserEventDto eventDto = dto.convert(AgoraChannelUserEventDto.class);
|
||||
AgoraChannelUserEventDto eventDto = mapToBean(body, AgoraChannelUserEventDto.class);
|
||||
roomCache.changeUserType(eventDto.getChannelName(), eventDto.getUid(), ERoomUserType.broadcaster);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue