| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- export * from './api/index'
- import util from '../../../utils/util'
- import api from '../../../config/api'
- export const authorizeRecord = async () => {
- let isAuth = await new Promise((r, j) => {
- wx.authorize({
- scope: 'scope.record',
- success: () => r(true),
- fail: () => r(false)
- })
- })
- if (isAuth) return true
- let res = await new Promise(r => {
- wx.showModal({
- title: '提示',
- content: '您未授权录音,说话功能将无法使用',
- showCancel: true,
- confirmText: "授权",
- confirmColor: "#52a2d8",
- success: res => r(res),
- fail: () => r(false)
- })
- })
- if (!res || res.cancel) return;
- isAuth = await new Promise((r) => {
- wx.openSetting({
- success: res => r(res.authSetting['scope.record']),
- fail: () => r(false)
- })
- })
- return isAuth
- }
- const agetUserInfo = async () => {
- const res = await util.request(api.UserInfo)
- if (res.errno === 401) {
- return {
- userId: UNLOGIN,
- avatar: ''
- }
- } else {
- const data = res.data
- data.region = data.city ? data.city.split(',') : []
- data.birthday = data.birthday || '1990-01-01'
- return data
- }
- }
- export const getUserInfo = async () => {
- let userInfo = wx.getStorageSync('userInfo');
- let token = wx.getStorageSync('token');
- if (userInfo && userInfo.userId && token) {
- let info = await agetUserInfo()
- return {
- ...info,
- ...userInfo,
- avatarUrl: info.avatar
- };
- } else {
- return {
- userId: UNLOGIN,
- avatar: ''
- }
- }
- }
- export const voiceFactory = (params) => {
- let ring = false
- const start = () => {
- if (!ring) {
- ring = true
- // getApp().globalData.roomId = 'KKV4_RID_' + params.roomId.toString()
- getApp().globalData.roomId = '266' + params.roomId.toString()
- getApp().setVoiceProps({
- ...params.user,
- sdkAppID: params.sdkAppId.toString(),
- sig: params.sig,
- // sdkAppID: '1400431163',
- // sig: "eJyrVgrxCdYrSy1SslIy0jNQ0gHzM1NS80oy0zLBwiYmUNHilOzEgoLMFCUrQxMDAxNjQ0MzY4hMSWZuKlDUzMzEyMzMwNIcIppaUZBZBBS3MAMqhxqRmQ400cnEqyAkKDjLvbg4wjPP1CLA3dI5wzEzpKgoq7jUIjHEN9M7KsDM1C8lx9NWqRYAq4gvLA__",
- noMute: false,
- action: 'startCall'
- })
- }
- }
- const changeMute = (noMute) => {
- getApp().setVoiceProps({
- noMute
- })
- }
- const stop = () => {
- console.error('stop', ring)
- if (ring) {
- ring = false
- getApp().setVoiceProps({
- noMute: true,
- action: 'stopCall'
- })
- }
- }
- return { start, stop, ring, changeMute }
- }
|