RoomController.java 17 KB

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