handle.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import {InstructionsCacheType, InstructionsMessageType} from "$utils/request";
  2. import user from "$config/user";
  3. import Shield from '$utils/control/user/const/shield';
  4. import {RowWheat} from "@/pages/talking/const";
  5. import {AgoraRTMIMStatus} from "$utils/socket/agoraRTM/const/status";
  6. import {AgoraRTMessage} from "$utils/socket/agoraRTM/const/channel";
  7. export default <LibMixins>{
  8. data(){
  9. return {
  10. Shield,
  11. // 房间信息
  12. roomInfo:{},
  13. // 麦位信息
  14. microInfo:{}
  15. }
  16. },
  17. computed:{
  18. // 用户是否为房主
  19. isHomeowners(){
  20. let uid = user.uid();
  21. return this.roomInfo.room_owner_uid === uid;
  22. },
  23. // 用户目前是否为 管理员
  24. isAdmin(){
  25. let uid = user.uid();
  26. return (this.roomInfo.room_admin_uid || '').indexOf(uid) >= 0 && uid || this.isHomeowners;
  27. },
  28. // 主持麦位是否有人
  29. hostMicroIsHave(){
  30. return !!(this.microInfo.host_info && this.microInfo.host_info.mc_user_info && this.microInfo.host_info.mc_user_info.uid);
  31. },
  32. // 当前人是否为主持
  33. isHostMicro(){
  34. return !!(this.microInfo.host_info && this.microInfo.host_info.mc_user_info && this.microInfo.host_info.mc_user_info.uid === user.uid());
  35. },
  36. // 自己是否在麦上
  37. inWheat(){
  38. return this.wheat_status === RowWheat.wheat;
  39. }
  40. },
  41. methods:{
  42. // 获取房间信息
  43. getRoomInfo(){
  44. Promise.all([this.fetchRoomInfo(false),this.getUserAdmission()]).then(([roomInfo,data])=>{
  45. this.setUserAddAdmission(data);
  46. });
  47. },
  48. // 房间信息
  49. fetchRoomInfo(updated:boolean=true){
  50. return new Promise((resolve, reject)=>{
  51. if (this.$params.infoData) {
  52. this.setRoomInfo(JSON.parse(this.$params.infoData),resolve,reject);
  53. return resolve(this.$params.infoData);
  54. } else {
  55. return this.$request({
  56. url:'room/enter_room_info',
  57. data:{
  58. rid: this.$params.rid,
  59. password: this.$params.password
  60. },
  61. token:true,
  62. cache:{
  63. type: InstructionsCacheType.storage,
  64. updated,
  65. id:'enter_room_info-'+this.$params.rid
  66. },
  67. failMessage:true,
  68. message:InstructionsMessageType.other
  69. }).then((data)=>{
  70. if (data.isCache) {
  71. this.fetchRoomInfo(true);
  72. }
  73. if (data.isSuccess) {
  74. this.setRoomInfo(data.data,resolve,reject);
  75. } else {
  76. return this.$router.back();
  77. }
  78. }).catch(reject);
  79. }
  80. });
  81. },
  82. setRoomInfo(data,resolve,reject){
  83. this.roomInfo = data;
  84. console.log(data);
  85. if (!this.setRoomInfoStatus && this.agoraRTMIM.status !== AgoraRTMIMStatus.join) {
  86. this.setRoomInfoStatus = true;
  87. // 安装 socket
  88. this.agoraRTMIM.install(this.$params.rid.toString()).then(()=>{
  89. this.sendSystem(data.room_welcome);
  90. // 装载全服消息
  91. this.globalRTMIM.install('global_channel');
  92. resolve();
  93. }).catch(reject);
  94. }
  95. },
  96. // 获取用户排麦状态
  97. getUserRowWheat(updated:boolean=true){
  98. return this.$request({
  99. url:'room/get_user_mc_queue_status',
  100. data:{
  101. rid: this.$params.rid
  102. },
  103. cache:{
  104. type: InstructionsCacheType.storage,
  105. updated
  106. },
  107. token:true
  108. }).then((data)=>{
  109. if (data.isSuccess && data.data.in_mc_queue === 1) {
  110. this.setMicroStatus(RowWheat.queuing);
  111. }
  112. if (data.isCache) {
  113. this.getUserRowWheat();
  114. }
  115. });
  116. },
  117. // 获取用户进入房间特权信息
  118. getUserAdmission(){
  119. return this.$request({
  120. url:'room/get_room_user_vip',
  121. data:{
  122. rid: this.$params.rid
  123. },
  124. cache:{
  125. type: InstructionsCacheType.storage,
  126. id:'get_room_user_vip',
  127. first:true,
  128. updated:true
  129. },
  130. token:true
  131. });
  132. },
  133. // 设置用户进入房间特权
  134. setUserAddAdmission(data){
  135. this.user = data.data;
  136. return this.addAdmission(data.data);
  137. },
  138. // 执行 调用加入房间接口
  139. userJoinRoom(){
  140. return new Promise((resolve)=>{
  141. return this.$request({
  142. url:'room/user_enter_room',
  143. data:{
  144. rid: this.$params.rid,
  145. uid: user.uid()
  146. },
  147. token:true
  148. }).then(resolve).catch(resolve);
  149. })
  150. },
  151. // 获取麦位详情
  152. getRoomMicroInfo(updated:boolean=true){
  153. if (this.roomMicroStatus) return ;
  154. return this.$request({
  155. url:'room/get_room_micro_info',
  156. data:{
  157. rid: this.$params.rid
  158. },
  159. token:true,
  160. next:({status})=> this.roomMicroStatus = status,
  161. failMessage:true,
  162. cache:{
  163. type: InstructionsCacheType.storage,
  164. updated,
  165. id:'get_room_micro_info-'+this.$params.rid
  166. },
  167. message:InstructionsMessageType.other
  168. }).then((data)=>{
  169. this.microInfo = data.data;
  170. this.installMicroInfo();
  171. if (data.isCache) {
  172. this.getRoomMicroInfo(true);
  173. }
  174. // 设置当前排麦状态
  175. if (this.hasMicroInfo()) {
  176. this.downMicro();
  177. } else {
  178. // 否则移除订阅
  179. this.unPublish();
  180. }
  181. })
  182. },
  183. // 安装
  184. install(){
  185. // 请求房间信息
  186. this.getRoomInfo();
  187. // 请求麦位信息
  188. this.getRoomMicroInfo(false);
  189. // 获取用户排麦信息
  190. this.getUserRowWheat(false);
  191. // // 获取用户入场特效
  192. // this.getUserAdmission();
  193. },
  194. },
  195. mounted(){
  196. this.install();
  197. },
  198. created(){
  199. // new WebIM().install(this.$store.state.user.user);
  200. this.roomInfo = this.$params || {};
  201. }
  202. }