RoomController.java 9.0 KB

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