RoomController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package com.ym.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ym.common.ApiException;
  4. import com.ym.common.BaseResponse;
  5. import com.ym.common.ErrorEnum;
  6. import com.ym.pojo.*;
  7. import com.ym.service.RoomService;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.List;
  12. /**
  13. * Created by weiqinxiao on 2019/2/25.
  14. */
  15. @RestController
  16. @RequestMapping("/room")
  17. @Slf4j
  18. public class RoomController{
  19. @Autowired
  20. RoomService roomService;
  21. @RequestMapping(value = "/join", method = RequestMethod.POST)
  22. public Object joinRoom(@RequestBody ReqUserData data)
  23. throws ApiException, Exception {
  24. RoomResult roomResult = roomService.joinRoom(data.getUserName(), data.getRoomId(), data.isAudience(), data.isDisableCamera());
  25. return new BaseResponse<>(roomResult);
  26. }
  27. @RequestMapping(value = "/signIn", method = RequestMethod.POST)
  28. public Object signIn(String roomId){
  29. roomService.signIn(roomId);
  30. return new BaseResponse<>();
  31. }
  32. @RequestMapping(value = "/leave", method = RequestMethod.POST)
  33. public Object leaveRoom(@RequestBody ReqUserData data)
  34. throws ApiException, Exception {
  35. boolean result = roomService.leaveRoom(data.getRoomId());
  36. return new BaseResponse<>(result);
  37. }
  38. @RequestMapping(value = "/statusSync")
  39. public Object statusSync(@RequestBody String body) throws Exception {
  40. ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
  41. log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
  42. boolean result = false;
  43. if(notify.getEvent() == 12 || notify.getEvent() == 3){
  44. result = roomService.statusSync(notify.getChannelId(), notify.getUserId());
  45. }else if(notify.getEvent() == 11){
  46. // Teacher teacher = teacherDao.get(Integer.parseInt(notify.getUserId()));
  47. // Long roomId = Long.parseLong(notify.getChannelId().substring(1));
  48. // CourseSchedule courseSchedule = courseScheduleDao.get(roomId);
  49. // if(teacher != null && teacher.getId().equals(courseSchedule.getActualTeacherId())){
  50. // roomService.joinRoom(teacher.getRealName(),roomId.toString(),false,false);
  51. // }else {
  52. // roomService.joinRoom(teacher.getUsername(),roomId.toString(),false,false);
  53. // }
  54. }
  55. return new BaseResponse<>(result);
  56. }
  57. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  58. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  59. throws ApiException, Exception {
  60. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  61. return new BaseResponse<>(result);
  62. }
  63. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  64. public Object kickMember(@RequestBody ReqUserData data)
  65. throws ApiException, Exception {
  66. boolean result = roomService.kickMember(data.getRoomId());
  67. return new BaseResponse<>(result);
  68. }
  69. //only teacher
  70. @RequestMapping(value = "/display", method = RequestMethod.POST)
  71. public Object display(@RequestBody ReqDisplayData data)
  72. throws ApiException, Exception {
  73. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri());
  74. return new BaseResponse<>(result);
  75. }
  76. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  77. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  78. throws ApiException, Exception {
  79. String result = roomService.createWhiteBoard(data.getRoomId());
  80. return new BaseResponse<>(result);
  81. }
  82. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  83. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  84. throws ApiException, Exception {
  85. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  86. return new BaseResponse<>(result);
  87. }
  88. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  89. public Object getWhiteBoard(@RequestParam String roomId)
  90. throws ApiException, Exception {
  91. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  92. return new BaseResponse<>(whiteboards);
  93. }
  94. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  95. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  96. throws ApiException, Exception {
  97. boolean result;
  98. result = roomService.approveControlDevice(data.getRoomId(), data.getTicket());
  99. return new BaseResponse<>(result);
  100. }
  101. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  102. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  103. throws ApiException, Exception {
  104. boolean result;
  105. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  106. return new BaseResponse<>(result);
  107. }
  108. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  109. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  110. throws ApiException, Exception {
  111. boolean result;
  112. if (data.getCameraOn() != null) {
  113. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Camera, data.getCameraOn());
  114. } else if (data.getMicrophoneOn() != null) {
  115. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  116. } else {
  117. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  118. }
  119. return new BaseResponse<>(result);
  120. }
  121. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  122. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  123. throws ApiException, Exception {
  124. boolean result;
  125. if (data.getCameraOn() != null) {
  126. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Camera, data.getCameraOn());
  127. } else if (data.getMicrophoneOn() != null) {
  128. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  129. } else {
  130. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  131. }
  132. return new BaseResponse<>(result);
  133. }
  134. @RequestMapping(value = "/whiteboard/turn-page", method = RequestMethod.POST)
  135. public Object turnPage(@RequestBody ReqWhiteboardData data)
  136. throws ApiException, Exception {
  137. boolean result = roomService.turnWhiteBoardPage(data.getRoomId(), data.getWhiteboardId(), data.getPage());
  138. return new BaseResponse<>(result);
  139. }
  140. @RequestMapping(value = "/members", method = RequestMethod.GET)
  141. public Object getMembers(@RequestParam String roomId)
  142. throws ApiException, Exception {
  143. List<RoomResult.MemberResult> whiteboards = roomService.getMembers(roomId);
  144. return new BaseResponse<>(whiteboards);
  145. }
  146. @RequestMapping(value = "/speech/apply", method = RequestMethod.POST)
  147. public Object apply(@RequestBody ReqSpeechData data)
  148. throws ApiException, Exception {
  149. Boolean result = roomService.applySpeech(data.getRoomId());
  150. return new BaseResponse<>(result);
  151. }
  152. @RequestMapping(value = "/speech/approve", method = RequestMethod.POST)
  153. public Object approval(@RequestBody ReqSpeechData data)
  154. throws ApiException, Exception {
  155. Boolean result = roomService.approveSpeech(data.getRoomId(), data.getTicket());
  156. return new BaseResponse<>(result);
  157. }
  158. @RequestMapping(value = "/speech/reject", method = RequestMethod.POST)
  159. public Object reject(@RequestBody ReqSpeechData data)
  160. throws ApiException, Exception {
  161. Boolean result = roomService.rejectSpeech(data.getRoomId(), data.getTicket());
  162. return new BaseResponse<>(result);
  163. }
  164. @RequestMapping(value = "/transfer", method = RequestMethod.POST)
  165. public Object transfer(@RequestBody ReqUpgradeRoleData data)
  166. throws ApiException, Exception {
  167. Boolean result = roomService.transfer(data.getRoomId(), data.getUserId());
  168. return new BaseResponse<>(result);
  169. }
  170. @RequestMapping(value = "/upgrade/invite", method = RequestMethod.POST)
  171. public Object inviteUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  172. throws ApiException, Exception {
  173. Boolean result = roomService.inviteUpgradeRole(data.getRoomId(), data.getUserId(), data.getRole());
  174. return new BaseResponse<>(result);
  175. }
  176. @RequestMapping(value = "/upgrade/approve", method = RequestMethod.POST)
  177. public Object approveUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  178. throws ApiException, Exception {
  179. Boolean result = roomService.approveUpgradeRole(data.getRoomId(), data.getTicket());
  180. return new BaseResponse<>(result);
  181. }
  182. @RequestMapping(value = "/upgrade/reject", method = RequestMethod.POST)
  183. public Object rejectUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  184. throws ApiException, Exception {
  185. Boolean result = roomService.rejectUpgradeRole(data.getRoomId(), data.getTicket());
  186. return new BaseResponse<>(result);
  187. }
  188. @RequestMapping(value = "/change-role", method = RequestMethod.POST)
  189. public Object changeRole(@RequestBody ReqChangeRole data)
  190. throws ApiException, Exception {
  191. Boolean result = roomService.changeRole(data.getRoomId(), data.getUserId(), data.getRole());
  192. return new BaseResponse<>(result);
  193. }
  194. @RequestMapping(value = "/members/online-status", method = RequestMethod.POST)
  195. public Object memberOnlineStatus(@RequestBody List<ReqMemberOnlineStatus> statusList,
  196. @RequestParam(value = "timestamp", required = false) String timestamp,
  197. @RequestParam(value = "nonce", required = false) String nonce,
  198. @RequestParam(value = "signature", required = false) String signature)
  199. throws ApiException, Exception {
  200. Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
  201. return new BaseResponse<>(result);
  202. }
  203. }