123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- import {InstructionsCacheType, InstructionsMessageType} from "$utils/request";
- import user from "$config/user";
- import Shield from '$utils/control/user/const/shield';
- import {RowWheat} from "@/pages/talking/const";
- import {AgoraRTMIMStatus} from "$utils/socket/agoraRTM/const/status";
- import {AgoraRTMessage} from "$utils/socket/agoraRTM/const/channel";
- export default <LibMixins>{
- data(){
- return {
- Shield,
- // 房间信息
- roomInfo:{},
- // 麦位信息
- microInfo:{}
- }
- },
- computed:{
- // 用户是否为房主
- isHomeowners(){
- let uid = user.uid();
- return this.roomInfo.room_owner_uid === uid;
- },
- // 用户目前是否为 管理员
- isAdmin(){
- let uid = user.uid();
- return (this.roomInfo.room_admin_uid || '').indexOf(uid) >= 0 && uid || this.isHomeowners;
- },
- // 主持麦位是否有人
- hostMicroIsHave(){
- return !!(this.microInfo.host_info && this.microInfo.host_info.mc_user_info && this.microInfo.host_info.mc_user_info.uid);
- },
- // 当前人是否为主持
- isHostMicro(){
- return !!(this.microInfo.host_info && this.microInfo.host_info.mc_user_info && this.microInfo.host_info.mc_user_info.uid === user.uid());
- },
- // 自己是否在麦上
- inWheat(){
- return this.wheat_status === RowWheat.wheat;
- }
- },
- methods:{
- // 获取房间信息
- getRoomInfo(){
- Promise.all([this.fetchRoomInfo(false),this.getUserAdmission()]).then(([roomInfo,data])=>{
- this.setUserAddAdmission(data);
- });
- },
- // 房间信息
- fetchRoomInfo(updated:boolean=true){
- return new Promise((resolve, reject)=>{
- if (this.$params.infoData) {
- this.setRoomInfo(JSON.parse(this.$params.infoData),resolve,reject);
- return resolve(this.$params.infoData);
- } else {
- return this.$request({
- url:'room/enter_room_info',
- data:{
- rid: this.$params.rid,
- password: this.$params.password
- },
- token:true,
- cache:{
- type: InstructionsCacheType.storage,
- updated,
- id:'enter_room_info-'+this.$params.rid
- },
- failMessage:true,
- message:InstructionsMessageType.other
- }).then((data)=>{
- if (data.isCache) {
- this.fetchRoomInfo(true);
- }
- if (data.isSuccess) {
- this.setRoomInfo(data.data,resolve,reject);
- } else {
- return this.$router.back();
- }
- }).catch(reject);
- }
- });
- },
- setRoomInfo(data,resolve,reject){
- this.roomInfo = data;
- console.log(data);
- if (!this.setRoomInfoStatus && this.agoraRTMIM.status !== AgoraRTMIMStatus.join) {
- this.setRoomInfoStatus = true;
- // 安装 socket
- this.agoraRTMIM.install(this.$params.rid.toString()).then(()=>{
- this.sendSystem(data.room_welcome);
- // 装载全服消息
- this.globalRTMIM.install('global_channel');
- resolve();
- }).catch(reject);
- }
- },
- // 获取用户排麦状态
- getUserRowWheat(updated:boolean=true){
- return this.$request({
- url:'room/get_user_mc_queue_status',
- data:{
- rid: this.$params.rid
- },
- cache:{
- type: InstructionsCacheType.storage,
- updated
- },
- token:true
- }).then((data)=>{
- if (data.isSuccess && data.data.in_mc_queue === 1) {
- this.setMicroStatus(RowWheat.queuing);
- }
- if (data.isCache) {
- this.getUserRowWheat();
- }
- });
- },
- // 获取用户进入房间特权信息
- getUserAdmission(){
- return this.$request({
- url:'room/get_room_user_vip',
- data:{
- rid: this.$params.rid
- },
- cache:{
- type: InstructionsCacheType.storage,
- id:'get_room_user_vip',
- first:true,
- updated:true
- },
- token:true
- });
- },
- // 设置用户进入房间特权
- setUserAddAdmission(data){
- this.user = data.data;
- return this.addAdmission(data.data);
- },
- // 执行 调用加入房间接口
- userJoinRoom(){
- return new Promise((resolve)=>{
- return this.$request({
- url:'room/user_enter_room',
- data:{
- rid: this.$params.rid,
- uid: user.uid()
- },
- token:true
- }).then(resolve).catch(resolve);
- })
- },
- // 获取麦位详情
- getRoomMicroInfo(updated:boolean=true){
- if (this.roomMicroStatus) return ;
- return this.$request({
- url:'room/get_room_micro_info',
- data:{
- rid: this.$params.rid
- },
- token:true,
- next:({status})=> this.roomMicroStatus = status,
- failMessage:true,
- cache:{
- type: InstructionsCacheType.storage,
- updated,
- id:'get_room_micro_info-'+this.$params.rid
- },
- message:InstructionsMessageType.other
- }).then((data)=>{
- this.microInfo = data.data;
- this.installMicroInfo();
- if (data.isCache) {
- this.getRoomMicroInfo(true);
- }
- // 设置当前排麦状态
- if (this.hasMicroInfo()) {
- this.downMicro();
- } else {
- // 否则移除订阅
- this.unPublish();
- }
- })
- },
- // 安装
- install(){
- // 请求房间信息
- this.getRoomInfo();
- // 请求麦位信息
- this.getRoomMicroInfo(false);
- // 获取用户排麦信息
- this.getUserRowWheat(false);
- // // 获取用户入场特效
- // this.getUserAdmission();
- },
- },
- mounted(){
- this.install();
- },
- created(){
- // new WebIM().install(this.$store.state.user.user);
- this.roomInfo = this.$params || {};
- }
- }
|