滚动条样式&切刀后台重进小程序需重连
This commit is contained in:
parent
3574ee052e
commit
18eb8f136a
|
|
@ -74,6 +74,7 @@
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
&-content {
|
&-content {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
import { GetRoomInfo, GetRoomUser, GetShowUser, GetApplySpeak, PostMuteAll, PostOpenMicr, PostOpenCamera, DeleteRoomManager } from '../../api/meeting/index'
|
import { GetRoomInfo, GetRoomUser, GetShowUser, GetApplySpeak, PostMuteAll, PostOpenMicr, PostOpenCamera, DeleteRoomManager, PostRoomManager } from '../../api/meeting/index'
|
||||||
|
import { GetRoomRtcToken } from '../../api/form/index'
|
||||||
import { agora } from '../../utils/agora'
|
import { agora } from '../../utils/agora'
|
||||||
import { onInvoke, onSignalr } from '../../utils/singlr'
|
import { onInvoke, onSignalr, getSignIr, offSignalr } from '../../utils/singlr'
|
||||||
import { role, getStorage } from '../../utils/utils'
|
import { role, getStorage } from '../../utils/utils'
|
||||||
import { Message } from 'tdesign-miniprogram';
|
import { Message } from 'tdesign-miniprogram';
|
||||||
|
import * as signalR from "signalr-for-wx";
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
const computedBehavior = require('miniprogram-computed').behavior;
|
const computedBehavior = require('miniprogram-computed').behavior;
|
||||||
|
let reconnectTime = "" as any;
|
||||||
Page({
|
Page({
|
||||||
behaviors: [computedBehavior],
|
behaviors: [computedBehavior],
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -92,7 +95,9 @@ Page({
|
||||||
'听得到',
|
'听得到',
|
||||||
'听不到',
|
'听不到',
|
||||||
'我要发言',
|
'我要发言',
|
||||||
]
|
],
|
||||||
|
isFirstShow: true,
|
||||||
|
isCurrePage: false,
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'roomUserList.**': function (roomUserList) {
|
'roomUserList.**': function (roomUserList) {
|
||||||
|
|
@ -198,11 +203,91 @@ Page({
|
||||||
onReady() {
|
onReady() {
|
||||||
wx.onNetworkStatusChange(this.listener)
|
wx.onNetworkStatusChange(this.listener)
|
||||||
},
|
},
|
||||||
|
onShow() {
|
||||||
|
this.setData({
|
||||||
|
isCurrePage: true
|
||||||
|
})
|
||||||
|
if (this.data.isFirstShow) {
|
||||||
|
this.setData({
|
||||||
|
isFirstShow: false,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const item = this.data.roomUserList.find(row => row.uid === this.data.user.uid)
|
||||||
|
if (item && !item.isRoomManager) {
|
||||||
|
wx.showLoading({
|
||||||
|
title: '重连中',
|
||||||
|
})
|
||||||
|
agora.destroy(() => {
|
||||||
|
reconnectTime = setInterval(() => {
|
||||||
|
if (getSignIr() === signalR.HubConnectionState.Connected) {
|
||||||
|
this.reconnecFun()
|
||||||
|
clearInterval(reconnectTime)
|
||||||
|
reconnectTime = ''
|
||||||
|
}
|
||||||
|
}, 2000)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onHide() {
|
||||||
|
this.setData({
|
||||||
|
isCurrePage: false
|
||||||
|
})
|
||||||
|
if (reconnectTime) {
|
||||||
|
clearInterval(reconnectTime)
|
||||||
|
reconnectTime = ''
|
||||||
|
}
|
||||||
|
wx.hideLoading()
|
||||||
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
wx.offNetworkStatusChange(this.listener)
|
wx.offNetworkStatusChange(this.listener)
|
||||||
|
if (reconnectTime) {
|
||||||
|
clearInterval(reconnectTime)
|
||||||
|
reconnectTime = ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async reconnecFun() {
|
||||||
|
offSignalr()
|
||||||
|
await GetRoomRtcToken(this.data.channelId).then(res => {
|
||||||
|
if (res.code === 200) {
|
||||||
|
agora.reconnecSetOption(res.data, async () => {
|
||||||
|
await this.joinChannel()
|
||||||
|
this.startClientEvent()
|
||||||
|
this.startSignalr()
|
||||||
|
await this.getRoomUser()
|
||||||
|
await this.getShowUser()
|
||||||
|
wx.hideLoading()
|
||||||
|
Message.success({
|
||||||
|
context: this,
|
||||||
|
offset: [90, 32],
|
||||||
|
duration: 3000,
|
||||||
|
content: '重连成功',
|
||||||
|
});
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
wx.hideLoading()
|
||||||
|
Message.error({
|
||||||
|
context: this,
|
||||||
|
offset: [90, 32],
|
||||||
|
duration: 3000,
|
||||||
|
content: '重连失败,请退出房间重试!',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
wx.hideLoading()
|
||||||
|
Message.error({
|
||||||
|
context: this,
|
||||||
|
offset: [90, 32],
|
||||||
|
duration: 3000,
|
||||||
|
content: '重连失败,请退出房间重试!',
|
||||||
|
});
|
||||||
|
})
|
||||||
},
|
},
|
||||||
startSignalr() {
|
startSignalr() {
|
||||||
onSignalr(async (item) => {
|
onSignalr(async (item) => {
|
||||||
|
if (!this.data.isCurrePage) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const userInfo: any = await getStorage('user')
|
const userInfo: any = await getStorage('user')
|
||||||
switch (item.key) {
|
switch (item.key) {
|
||||||
// 聊天
|
// 聊天
|
||||||
|
|
@ -398,6 +483,13 @@ Page({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
tokenRef: () => {
|
||||||
|
GetRoomRtcToken(this.data.channelId).then(res => {
|
||||||
|
if (res.code === 200) {
|
||||||
|
agora.renewToken(res.data)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
<live-player id="player" src="{{currentUser.shareSrc}}" mode="RTC" autoplay="true" bindstatechange="playerStateChange" object-fit="contain" />
|
<live-player id="player" src="{{currentUser.shareSrc}}" mode="RTC" autoplay="true" bindstatechange="playerStateChange" object-fit="contain" />
|
||||||
</view>
|
</view>
|
||||||
<view class="meeting-content-video-canvas" wx:elif="{{currentUser.src && currentUser.enableCamera}}">
|
<view class="meeting-content-video-canvas" wx:elif="{{currentUser.src && currentUser.enableCamera}}">
|
||||||
<live-player id="player" src="{{currentUser.src}}" mode="RTC" autoplay="true" bindstatechange="playerStateChange" object-fit="fillCrop" muted="{{currentUser.uid === user.uid}}" />
|
<live-player id="player" src="{{currentUser.src}}" mode="RTC" autoplay="true" bindstatechange="playerStateChange" object-fit="contain" muted="{{currentUser.uid === user.uid}}" />
|
||||||
</view>
|
</view>
|
||||||
<view class="meeting-content-video-user">
|
<view class="meeting-content-video-user">
|
||||||
<view class="meeting-content-video-user-view" style=" background:{{currentUser.roleId === '1' || currentUser.roleId === '3'? '#FDC229' : '#3F51B5' }}">
|
<view class="meeting-content-video-user-view" style=" background:{{currentUser.roleId === '1' || currentUser.roleId === '3'? '#FDC229' : '#3F51B5' }}">
|
||||||
|
|
@ -38,8 +38,8 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="meeting-content-smallvideo-box-view-canvas" wx:if="{{item.src}}">
|
<view class="meeting-content-smallvideo-box-view-canvas" wx:if="{{item.src}}">
|
||||||
<live-pusher wx:if="{{user.uid === item.uid}}" url="{{item.src}}" mode="RTC" bindstatechange="recorderStateChange" background-mute enable-mic="{{footerList[1].active}}" enable-camera max-bitrate="500" min-bitrate="200" autopush enable-agc enable-ans device-position="front" class="meeting-content-smallvideo-box-view-canvas-play" data-uid="{{item.uid}}" bindaudiovolumenotify="playerAudioVolumenotify" beauty='{{9}}' whiteness='{{9}}' />
|
<live-pusher wx:if="{{user.uid === item.uid}}" url="{{item.src}}" mode="RTC" object-fit="contain" bindstatechange="recorderStateChange" background-mute enable-mic="{{footerList[1].active}}" enable-camera max-bitrate="500" min-bitrate="200" autopush enable-agc enable-ans device-position="front" class="meeting-content-smallvideo-box-view-canvas-play" data-uid="{{item.uid}}" bindaudiovolumenotify="playerAudioVolumenotify" beauty='{{9}}' whiteness='{{9}}' />
|
||||||
<live-player src="{{item.src}}" class="meeting-content-smallvideo-box-view-canvas-play" mode="RTC" autoplay="true" bindstatechange="playerStateChange" object-fit="fillCrop" data-uid="{{item.uid}}" bindaudiovolumenotify="playerAudioVolumenotify" wx:else />
|
<live-player src="{{item.src}}" class="meeting-content-smallvideo-box-view-canvas-play" mode="RTC" autoplay="true" bindstatechange="playerStateChange" object-fit="contain" data-uid="{{item.uid}}" bindaudiovolumenotify="playerAudioVolumenotify" wx:else />
|
||||||
</view>
|
</view>
|
||||||
<view class="meeting-content-smallvideo-box-view-user">
|
<view class="meeting-content-smallvideo-box-view-user">
|
||||||
<view class="meeting-content-smallvideo-box-view-user-view" style=" background:{{ item.roleId === '1' || item.roleId === '3' ? '#FDC229' : '#3F51B5' }}">
|
<view class="meeting-content-smallvideo-box-view-user-view" style=" background:{{ item.roleId === '1' || item.roleId === '3' ? '#FDC229' : '#3F51B5' }}">
|
||||||
|
|
@ -96,7 +96,7 @@
|
||||||
<view class="user-popup-title">
|
<view class="user-popup-title">
|
||||||
成员
|
成员
|
||||||
</view>
|
</view>
|
||||||
<view class="user-popup-view">
|
<scroll-view scroll-y class="user-popup-view" enhanced>
|
||||||
<view class="user-popup-view-view" wx:for="{{roomUserList}}" data-item="{{item}}" wx:key="index" wx:if="{{item.isRoom}}">
|
<view class="user-popup-view-view" wx:for="{{roomUserList}}" data-item="{{item}}" wx:key="index" wx:if="{{item.isRoom}}">
|
||||||
<view class="user-popup-view-view-avatar">
|
<view class="user-popup-view-view-avatar">
|
||||||
<t-avatar size="36rpx">{{item.avatarName}}</t-avatar>
|
<t-avatar size="36rpx">{{item.avatarName}}</t-avatar>
|
||||||
|
|
@ -107,7 +107,7 @@
|
||||||
<image src="/assets/{{item.enableCamera ? 'icon3' : 'icon3-active'}}.png" class="user-popup-view-view-image-icon" />
|
<image src="/assets/{{item.enableCamera ? 'icon3' : 'icon3-active'}}.png" class="user-popup-view-view-image-icon" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
</t-popup>
|
</t-popup>
|
||||||
<t-popup visible="{{chatPopupVisible}}" bind:visible-change="onVisibleChange" placement="right">
|
<t-popup visible="{{chatPopupVisible}}" bind:visible-change="onVisibleChange" placement="right">
|
||||||
|
|
@ -115,7 +115,7 @@
|
||||||
<view class="chat-popup-title">
|
<view class="chat-popup-title">
|
||||||
聊天
|
聊天
|
||||||
</view>
|
</view>
|
||||||
<scroll-view scroll-y="true" class="chat-popup-list" id="chatView" enhanced>
|
<scroll-view scroll-y class="chat-popup-list" id="chatView" enhanced>
|
||||||
<view class="chat-popup-list-view" wx:for="{{chatList}}" data-item="{{item}}" wx:key="index" style="text-align: {{item.me ? 'right' : 'left'}}">
|
<view class="chat-popup-list-view" wx:for="{{chatList}}" data-item="{{item}}" wx:key="index" style="text-align: {{item.me ? 'right' : 'left'}}">
|
||||||
<text style="color: #666;font-size: 10rpx;margin-right: 4rpx;" wx:if="{{item.me}}">({{item.timestamp}})</text>
|
<text style="color: #666;font-size: 10rpx;margin-right: 4rpx;" wx:if="{{item.me}}">({{item.timestamp}})</text>
|
||||||
<text>{{item.me ? item.message : item.userName}}</text>
|
<text>{{item.me ? item.message : item.userName}}</text>
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,20 @@ const option = {
|
||||||
let client: any = '';
|
let client: any = '';
|
||||||
export const agora = {
|
export const agora = {
|
||||||
// 初始化
|
// 初始化
|
||||||
init: async () => {
|
init: async (callback?) => {
|
||||||
client = new AgoraMiniappSDK.Client();
|
client = new AgoraMiniappSDK.Client();
|
||||||
await client.init(option.appId);
|
await client.init(option.appId, () => {
|
||||||
|
callback?.()
|
||||||
|
});
|
||||||
},
|
},
|
||||||
// 销毁
|
// 销毁
|
||||||
destroy: async () => {
|
destroy: async (callback?) => {
|
||||||
if (client) {
|
if (client) {
|
||||||
await client.leave()
|
await client.leave()
|
||||||
await client.destroy()
|
await client.destroy(() => {
|
||||||
|
callback?.()
|
||||||
client = '';
|
client = '';
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 设置角色
|
// 设置角色
|
||||||
|
|
@ -41,14 +45,22 @@ export const agora = {
|
||||||
option.screenShareId = data.screenShareId;
|
option.screenShareId = data.screenShareId;
|
||||||
await agora.init()
|
await agora.init()
|
||||||
},
|
},
|
||||||
|
reconnecSetOption: async (token, callback) => {
|
||||||
|
option.token = token;
|
||||||
|
await agora.init(callback)
|
||||||
|
},
|
||||||
// 加入频道
|
// 加入频道
|
||||||
joinChannel: () => {
|
joinChannel: () => {
|
||||||
client.join(option.token, option.channelId, option.uid, () => {
|
client.join(option.token, option.channelId, option.uid, () => {
|
||||||
agora.setRole(false)
|
agora.setRole(false)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
// 刷新token
|
||||||
|
renewToken: (token) => {
|
||||||
|
client.renewToken(token)
|
||||||
|
},
|
||||||
// 监听
|
// 监听
|
||||||
clientEvent: ({ streamAdded, streamRemoved }) => {
|
clientEvent: ({ streamAdded, streamRemoved, tokenRef }) => {
|
||||||
client.on("stream-added", async e => {
|
client.on("stream-added", async e => {
|
||||||
await agora.subscribe(e.uid, (url: string, uid: number | string) => {
|
await agora.subscribe(e.uid, (url: string, uid: number | string) => {
|
||||||
streamAdded(url, uid)
|
streamAdded(url, uid)
|
||||||
|
|
@ -57,6 +69,9 @@ export const agora = {
|
||||||
client.on("stream-removed", async e => {
|
client.on("stream-removed", async e => {
|
||||||
streamRemoved(e.uid)
|
streamRemoved(e.uid)
|
||||||
});
|
});
|
||||||
|
client.on("token-privilege-will-expire", async e => {
|
||||||
|
tokenRef()
|
||||||
|
});
|
||||||
},
|
},
|
||||||
// 订阅远端音视频流
|
// 订阅远端音视频流
|
||||||
subscribe: async (uid: number | string, callBack: Function) => {
|
subscribe: async (uid: number | string, callBack: Function) => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const apiBase = "https://meeting-api.23544.com/pc"
|
const apiBase = "https://meeting-api.23544.com/pc"
|
||||||
|
import { Message } from 'tdesign-miniprogram';
|
||||||
export const Request = (params) => {
|
export const Request = (params) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
wx.getStorage({
|
wx.getStorage({
|
||||||
|
|
@ -36,6 +36,7 @@ function requestMethods(obj, callback) {
|
||||||
wx.request({
|
wx.request({
|
||||||
...obj.params,
|
...obj.params,
|
||||||
url: apiBase + obj.params.url,
|
url: apiBase + obj.params.url,
|
||||||
|
timeout: 500,
|
||||||
header: {
|
header: {
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
'Authorization': `Bearer ${obj.token}`
|
'Authorization': `Bearer ${obj.token}`
|
||||||
|
|
@ -44,6 +45,22 @@ function requestMethods(obj, callback) {
|
||||||
callback('success', res)
|
callback('success', res)
|
||||||
},
|
},
|
||||||
fail: res => {
|
fail: res => {
|
||||||
|
if (res.errMsg === 'request:fail timeout') {
|
||||||
|
Message.error({
|
||||||
|
context: this,
|
||||||
|
offset: [20, 32],
|
||||||
|
duration: 2000,
|
||||||
|
content: '网络连接超时,请检查网络状态',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (res.errMsg === 'request:fail ') {
|
||||||
|
Message.error({
|
||||||
|
context: this,
|
||||||
|
offset: [20, 32],
|
||||||
|
duration: 2000,
|
||||||
|
content: '网络已断开,请检查网络状态',
|
||||||
|
});
|
||||||
|
}
|
||||||
callback('fail', res)
|
callback('fail', res)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,9 @@ export const onStop = async () => {
|
||||||
connection = '';
|
connection = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export const getSignIr = () => {
|
||||||
|
return connection ? connection.state : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue