RoomController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. package com.ym.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ym.common.BaseResponse;
  4. import com.ym.mec.biz.dal.dto.TencentData;
  5. import com.ym.mec.biz.dal.enums.ETencentTRTCCallbackCommand;
  6. import com.ym.pojo.*;
  7. import com.ym.service.MessageService;
  8. import com.ym.service.RoomService;
  9. import io.swagger.annotations.ApiImplicitParam;
  10. import io.swagger.annotations.ApiImplicitParams;
  11. import io.swagger.annotations.ApiOperation;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.joda.time.DateTime;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.*;
  16. import java.util.List;
  17. import java.util.Objects;
  18. @RestController
  19. @RequestMapping("/room")
  20. @Slf4j
  21. public class RoomController{
  22. @Autowired
  23. RoomService roomService;
  24. @Autowired
  25. MessageService messageService;
  26. @RequestMapping(value = "/join", method = RequestMethod.POST)
  27. public BaseResponse joinRoom(@RequestBody ReqUserData data) throws Exception {
  28. return roomService.joinRoom(data.getRoomId(), true);
  29. }
  30. @RequestMapping(value = "/joinLive", method = RequestMethod.POST)
  31. public BaseResponse joinLiveRoom(@RequestBody ReqUserData data) throws Exception {
  32. return new BaseResponse(roomService.joinRoom(data.getRoomId(), false));
  33. }
  34. @ApiOperation("查询网络教室信息")
  35. @ApiImplicitParams({
  36. @ApiImplicitParam(name = "roomId", value = "房间id", required = true, dataType = "String", paramType = "query")
  37. })
  38. @GetMapping(value = "/info")
  39. public BaseResponse getRoomInfo(@RequestParam String roomId) throws Exception {
  40. return roomService.joinRoom(roomId.substring(1), false);
  41. }
  42. @RequestMapping(value = "/signIn", method = RequestMethod.POST)
  43. public Object signIn(Long roomId){
  44. return new BaseResponse<>();
  45. }
  46. @RequestMapping(value = "/statusImMsg", method = RequestMethod.POST)
  47. public Object statusImMsg(ImMsg imMsg){
  48. return new BaseResponse<>();
  49. }
  50. @RequestMapping(value = "/leave", method = RequestMethod.POST)
  51. public Object leaveRoom(@RequestBody RoomStatusNotify roomStatusNotify) throws Exception {
  52. //成员退出
  53. roomService.leaveRoomSuccess(roomStatusNotify.getRoomId(), roomStatusNotify.getUserId(), roomStatusNotify.getDeviceNum());
  54. return new BaseResponse<>();
  55. }
  56. @RequestMapping(value = "/queryNoJoinStu", method = RequestMethod.GET)
  57. public Object queryNoJoinStu(String roomId){
  58. return new BaseResponse<>(roomService.queryNoJoinStu(roomId));
  59. }
  60. @RequestMapping(value = "/sendImPlayMidiMessage", method = RequestMethod.POST)
  61. public Object sendImPlayMidiMessage(@RequestBody PlayMidiMessageData playMidiMessageData) throws Exception {
  62. log.info("sendImPlayMidiMessage: {}",JSONObject.toJSON(playMidiMessageData));
  63. roomService.sendImPlayMidiMessage(playMidiMessageData);
  64. return new BaseResponse<>();
  65. }
  66. @RequestMapping(value = "pushDownloadExamSongMsg", method = RequestMethod.POST)
  67. public Object pushDownloadExamSongMsg(@RequestBody ExamSongData examSongData) throws Exception {
  68. roomService.pushDownloadExamSongMsg(examSongData.getRoomId(),examSongData.getExamSongId());
  69. return new BaseResponse<>();
  70. }
  71. @ApiOperation(value = "老师通知学员下载伴奏")
  72. @RequestMapping(value = "pushDownloadMusicScoreMsg", method = RequestMethod.POST)
  73. public Object pushDownloadMusicScoreMsg(@RequestBody MusicScoreData musicScoreData) throws Exception {
  74. roomService.pushDownloadMusicScoreMsg(musicScoreData);
  75. return new BaseResponse<>();
  76. }
  77. @RequestMapping(value = "joinRoomStatusNotify", method = RequestMethod.POST)
  78. public Object joinRoomStatusNotify(@RequestBody RoomStatusNotify roomStatusNotify) throws Exception {
  79. log.info("joinRoomStatusNotify: {}",JSONObject.toJSON(roomStatusNotify));
  80. String roomId = roomStatusNotify.getRoomId();
  81. String userId = roomStatusNotify.getUserId();
  82. String deviceNum = roomStatusNotify.getDeviceNum();
  83. if(roomStatusNotify.isRequestStatus()){
  84. roomService.joinRoomSuccess(roomId, userId,deviceNum);
  85. }else {
  86. roomService.joinRoomFailure(roomId, userId);
  87. }
  88. return new BaseResponse<>();
  89. }
  90. @RequestMapping(value = "/statusSync")
  91. public void statusSync(@RequestBody String body) throws Exception {
  92. try {
  93. ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
  94. log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
  95. String roomId = notify.getChannelId();
  96. String userId = notify.getUserId();
  97. switch (notify.getEvent()){
  98. case 11:
  99. //成员加入
  100. roomService.joinRoomSuccess(roomId, userId,null);
  101. break;
  102. case 12:
  103. //成员退出
  104. roomService.leaveRoomSuccess(roomId, userId,null, notify.getTimestamp());
  105. break;
  106. }
  107. }catch (Exception e){
  108. log.error(e.getLocalizedMessage());
  109. }
  110. }
  111. @PostMapping(value = "/statusSyncTencent")
  112. public void statusSyncTencent(@RequestBody TencentData.TRTCEventInfo eventInfo) {
  113. try {
  114. if (Objects.isNull(eventInfo.getEventInfo())) {
  115. log.warn("statusSyncTencent eventInfo is null, time={}", DateTime.now().toString("yyy-MM-dd HH:mm:ss"));
  116. return;
  117. }
  118. log.info("statusSyncTencent: {}", eventInfo.jsonString());
  119. String roomId = eventInfo.getEventInfo().getRoomId();
  120. // 网络教室回调整消息
  121. if (roomId.startsWith("S") || roomId.startsWith("I")) {
  122. // 进出用户信息
  123. String userId = eventInfo.getEventInfo().getUserId();
  124. switch (ETencentTRTCCallbackCommand.get(eventInfo.getEventType())){
  125. case EVENT_TYPE_ENTER_ROOM:
  126. //成员加入
  127. roomService.joinRoomSuccess(roomId, userId,null);
  128. break;
  129. case EVENT_TYPE_EXIT_ROOM:
  130. //成员退出
  131. roomService.leaveRoomSuccess(roomId, userId,null, eventInfo.getCallbackTs());
  132. break;
  133. default:
  134. // 默认事件,直接忽略
  135. break;
  136. }
  137. }
  138. // 直播回调整消息, roomId.startsWith("LIVE")
  139. }catch (Exception e){
  140. log.error("statusSyncTencent event={}", eventInfo.jsonString(), e);
  141. }
  142. }
  143. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  144. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  145. throws Exception {
  146. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  147. return new BaseResponse<>(result);
  148. }
  149. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  150. public Object kickMember(@RequestBody ReqUserData data)
  151. throws Exception {
  152. boolean result = roomService.kickMember(data.getRoomId());
  153. return new BaseResponse<>(result);
  154. }
  155. //only teacher
  156. @RequestMapping(value = "/display", method = RequestMethod.POST)
  157. public Object display(@RequestBody ReqDisplayData data)
  158. throws Exception {
  159. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri(),data.getUserId());
  160. return new BaseResponse<>(result);
  161. }
  162. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  163. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  164. throws Exception {
  165. String result = roomService.createWhiteBoard(data.getRoomId());
  166. return new BaseResponse<>(result);
  167. }
  168. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  169. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  170. throws Exception {
  171. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  172. return new BaseResponse<>(result);
  173. }
  174. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  175. public Object getWhiteBoard(@RequestParam String roomId)
  176. throws Exception {
  177. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  178. return new BaseResponse<>(whiteboards);
  179. }
  180. @ApiOperation(value = "通知学员打开,麦克风、摄像头等权限请求")
  181. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  182. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  183. throws Exception {
  184. boolean result;
  185. result = roomService.approveControlDevice(data);
  186. return new BaseResponse<>(result);
  187. }
  188. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  189. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  190. throws Exception {
  191. boolean result;
  192. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  193. return new BaseResponse<>(result);
  194. }
  195. @ApiOperation(value = "学员麦克风、摄像头等开关控制")
  196. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  197. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  198. throws Exception {
  199. log.info("device_control: {}",JSONObject.toJSON(data));
  200. return new BaseResponse<>(roomService.controlDevice(data));
  201. }
  202. @ApiOperation(value = "学员伴奏下载状态回调")
  203. @RequestMapping(value = "adjustExamSong", method = RequestMethod.POST)
  204. public Object adjustExamSong(@RequestBody ExamSongData examSongData) throws Exception {
  205. log.info("adjustExamSong: {}",JSONObject.toJSON(examSongData));
  206. roomService.adjustExamSong(examSongData.getRoomId(),examSongData.getStatus(),examSongData.getExamSongId());
  207. return new BaseResponse<>();
  208. }
  209. @ApiOperation(value = "学员伴奏下载状态回调")
  210. @RequestMapping(value = "adjustMusicScore", method = RequestMethod.POST)
  211. public Object adjustMusicScore(@RequestBody MusicScoreData musicScoreData) throws Exception {
  212. roomService.adjustMusicScore(musicScoreData);
  213. return new BaseResponse<>();
  214. }
  215. @ApiOperation(value = "学员麦克风、摄像头等开关批量控制")
  216. @RequestMapping(value = "/device/batchControl", method = RequestMethod.POST)
  217. public Object batchControlDevice(@RequestBody ReqDeviceControlData data)throws Exception {
  218. log.info("batchControl: {}",JSONObject.toJSON(data));
  219. return new BaseResponse<>(roomService.batchControlDevice(data));
  220. }
  221. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  222. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  223. throws Exception {
  224. log.info("syncDeviceState: {}",JSONObject.toJSON(data));
  225. return new BaseResponse<>(roomService.syncDeviceState(data));
  226. }
  227. @RequestMapping(value = "/whiteboard/turn-page", method = RequestMethod.POST)
  228. public Object turnPage(@RequestBody ReqWhiteboardData data)
  229. throws Exception {
  230. boolean result = roomService.turnWhiteBoardPage(data.getRoomId(), data.getWhiteboardId(), data.getPage());
  231. return new BaseResponse<>(result);
  232. }
  233. @ApiImplicitParams({
  234. @ApiImplicitParam(name = "roomId", value = "房间id", required = true, dataType = "String"),
  235. @ApiImplicitParam(name = "userId", value = "用户Id", dataType = "String"),
  236. })
  237. @RequestMapping(value = "/members", method = RequestMethod.GET)
  238. public Object getMembers(@RequestParam String roomId, @RequestParam String userId)
  239. throws Exception {
  240. List<RoomResult.MemberResult> whiteboards = roomService.getMembers(roomId, userId);
  241. return new BaseResponse<>(whiteboards);
  242. }
  243. @RequestMapping(value = "/speech/apply", method = RequestMethod.POST)
  244. public Object apply(@RequestBody ReqSpeechData data)
  245. throws Exception {
  246. Boolean result = roomService.applySpeech(data.getRoomId());
  247. return new BaseResponse<>(result);
  248. }
  249. @RequestMapping(value = "/speech/approve", method = RequestMethod.POST)
  250. public Object approval(@RequestBody ReqSpeechData data)
  251. throws Exception {
  252. Boolean result = roomService.approveSpeech(data.getRoomId(), data.getTicket());
  253. return new BaseResponse<>(result);
  254. }
  255. @RequestMapping(value = "/speech/reject", method = RequestMethod.POST)
  256. public Object reject(@RequestBody ReqSpeechData data)
  257. throws Exception {
  258. Boolean result = roomService.rejectSpeech(data.getRoomId(), data.getTicket());
  259. return new BaseResponse<>(result);
  260. }
  261. @RequestMapping(value = "/transfer", method = RequestMethod.POST)
  262. public Object transfer(@RequestBody ReqUpgradeRoleData data)
  263. throws Exception {
  264. Boolean result = roomService.transfer(data.getRoomId(), data.getUserId());
  265. return new BaseResponse<>(result);
  266. }
  267. @RequestMapping(value = "/upgrade/invite", method = RequestMethod.POST)
  268. public Object inviteUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  269. throws Exception {
  270. Boolean result = roomService.inviteUpgradeRole(data.getRoomId(), data.getUserId(), data.getRole());
  271. return new BaseResponse<>(result);
  272. }
  273. @RequestMapping(value = "/upgrade/approve", method = RequestMethod.POST)
  274. public Object approveUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  275. throws Exception {
  276. Boolean result = roomService.approveUpgradeRole(data.getRoomId(), data.getTicket());
  277. return new BaseResponse<>(result);
  278. }
  279. @RequestMapping(value = "/upgrade/reject", method = RequestMethod.POST)
  280. public Object rejectUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  281. throws Exception {
  282. Boolean result = roomService.rejectUpgradeRole(data.getRoomId(), data.getTicket());
  283. return new BaseResponse<>(result);
  284. }
  285. @RequestMapping(value = "/change-role", method = RequestMethod.POST)
  286. public Object changeRole(@RequestBody ReqChangeRole data)
  287. throws Exception {
  288. Boolean result = roomService.changeRole(data.getRoomId(), data.getUserId(), data.getRole());
  289. return new BaseResponse<>(result);
  290. }
  291. @RequestMapping(value = "/members/online-status", method = RequestMethod.POST)
  292. public Object memberOnlineStatus(@RequestBody List<ReqMemberOnlineStatus> statusList,
  293. @RequestParam(value = "timestamp", required = false) String timestamp,
  294. @RequestParam(value = "nonce", required = false) String nonce,
  295. @RequestParam(value = "signature", required = false) String signature)
  296. throws Exception {
  297. Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
  298. return new BaseResponse<>(result);
  299. }
  300. }