Commit c33b7955 by wxl

x

parent 1679c991
......@@ -3,8 +3,7 @@ import { useState } from "vue-vulcan";
/** 当前客户端用户的基本信息(含token) */
export function useAuthData() {
const [authData, setAuth] = useState<UserData>(null, {storage: 'custome', key: 'auth'});
const [authData, setAuth] = useState<UserData>(null, {storage: 'custome', key: 'auth'});
return {
authData,
......
......@@ -6,7 +6,7 @@ import { useInjector, useRequest, useState } from "vue-vulcan";
import { useChannelStore } from "./useChannelStore";
import { useNetSocketStore } from "./useNetSocketStore";
type CallingState = 'net_error' | 'calling' | 'call_successed' | 'being_called' | 'call_accepted' | 'connecting' | 'free';
type CallingState = 'net_error' | 'calling' | 'call_successed' | 'callin' | 'call_accepted' | 'connecting' | 'free';
interface Caller extends UserData {
action: AnyRemoteSubFlag | 'none';
......@@ -72,10 +72,10 @@ export function useCallCenter() {
if(msg.msgMainFlag !== 'CallOffer') return;
switch(msg.msgSubFlag) {
case 'Request':
// 本地呼叫状态为free时,变更为being_called;不为free,则发送繁忙的回应。
// 本地呼叫状态为free时,变更为callin;不为free,则发送繁忙的回应。
console.log(`${currentMsg.value.fromName}呼叫,我目前的状态${myCallState.value}`)
if(myCallState.value === 'free') {
setCallState('being_called');
setCallState('callin');
setCaller({
id: msg.fromID,
nickname: msg.fromName,
......@@ -88,7 +88,7 @@ export function useCallCenter() {
}
//15S秒后若本地用户仍然处于被呼叫状态,则自动发出繁忙恢复,且将状态恢复为free
timer = setTimeout( () => {
if(myCallState.value === 'being_called'){
if(myCallState.value === 'callin'){
answerCaller('Busying', {id: currentMsg.value.fromID, nickname: currentMsg.value.fromName});
setCallState('free');
}
......@@ -106,8 +106,6 @@ export function useCallCenter() {
})
break;
}
})
// 监听呼叫目标的回应
watch(currentMsg, msg => {
......@@ -119,14 +117,13 @@ export function useCallCenter() {
updateMembers([msg.fromID], 'join');
break;
case 'Busying':
case 'Hangup':
setCallState(isEmpty.value ? 'free' : 'connecting');
break;
case 'Hangup':
setCallState(isEmpty.value ? 'free' : 'connecting');
break;
}
})
/** 呼叫挂断功能 */
/** 呼叫挂断功能 */
const hangup = (type?: 'leave' | 'cancel') => {
let flag: AnyRemoteMainFlag, toID: string;
switch(myCallState.value) {
......@@ -138,7 +135,7 @@ export function useCallCenter() {
flag = 'CallOffer';
toID = target.value?.id;
break;
case 'being_called':
case 'callin':
flag = 'CallAnswer';
toID = caller.value?.id;
break;
......@@ -169,7 +166,7 @@ export function useCallCenter() {
})
}
changeCallingState({channel_id: currentChannel.value?.channel_id, userIDs: JSON.stringify([
{userID: authData.value.id, callState: state==='free' ? 'idle' : 'callout'},
{userID: authData.value.id, callState: state==='free' ? 'idle' : state==='calling' ? 'callout' : 'callin'},
{userID: target.value?.id || caller.value?.id, callState: state==='free' ? 'idle' : 'callin'}
])});
})
......
......@@ -14,7 +14,7 @@ export function useChannelStore() {
const [channelMembers, setMembers] = useState<string[]>([]);
const [channelInfo, request] = useRequest<ChannelData>('/getAgoraToken', {auto: false});
const { authData } = useInjector(useAuthData);
const { currentMsg } = useInjector(useNetSocketStore);
const { currentMsg } = useInjector(useNetSocketStore);
const isEmpty = computed( () => channelMembers.value.length < 2); //频道剩余不到1人时,表示为空
......@@ -30,8 +30,7 @@ export function useChannelStore() {
console.log('根据对方呼叫人的频道获取token');
updateMembers([authData.value.id], 'join');
return request({channel_id: cid});
}
}
const updateMembers = (ids: string[], type: 'join' | 'leave') => {
const current = channelMembers.value;
......
import { setKeepScreenOn } from "@tarojs/taro";
import { watch } from "vue";
import { useContacts } from "any-hooks/contacts/useContacts";
import { UserData } from "any-hooks/types/user";
import { onMounted, watch } from "vue";
import { useInjector, useState } from "vue-vulcan";
import { useCallCenter } from "./useCallCenter";
import { useChannelStore } from "./useChannelStore";
......@@ -23,16 +22,13 @@ interface MeetingMember {
/** 会议中心功能, 该功能在呼叫功能生效后使用,此模块会将其他即时交互模块集中到一起,如:音视频通讯模块、文本聊天模块等(目前只有音视频通讯) */
export function useMeetingCenter() {
const {hangup, myCallState} = useInjector(useCallCenter);
const {streamList, localPushurl, voiceMute, mode, join, stopVideoConference, switchLocalMicState, switchVideoOrAudio} = useInjector(useVideoConference);
const {streamList, localPushurl, voiceMute, mode, join, stopVideoConference, switchLocalMicState, switchVideoOrAudio} = useInjector(useVideoConference);
/** 离开会议(分两步:1.挂断当前呼叫, 2.停止音视频功能) */
const leave = () => {
hangup('leave');
stopVideoConference();
}
/** 保持屏幕常亮 */
onMounted(() => setKeepScreenOn({keepScreenOn: true}));
}
/** 监听频道成员信息 */
const { channelMembers } = useInjector(useChannelStore);
......
......@@ -33,7 +33,17 @@ export function useContacts() {
return contactHome
})
const freeContacts = computed( () => contacts.value.filter( item => item.is_calling === '0' && item.is_signin === '1'))
const freeContacts = computed( () => {
const list = contacts.value.filter( item => item.is_calling === '0' && item.is_signin === '1');
const frees = {} as {[props: string]: UserData[]}
list?.forEach( item => {
if(['3','4'].includes(item.permission) ) {
if(!frees[item.group_name]) frees[item.group_name] = [];
frees[item.group_name].push(item);
};
})
return frees
})
const getContactById = (pid: string, type?: 'uid'|'pid') => {
......
import { navigateTo, redirectTo, showToast } from "@tarojs/taro";
import { navigateTo, redirectTo, setKeepScreenOn, showToast } from "@tarojs/taro";
import { useCallCenter } from "any-hooks/communication/useCallCenter";
import { watch } from "vue";
import { onMounted, watch } from "vue";
import { useInjector } from "vue-vulcan";
import { useAppInitInfo } from "../common/useAppInitInfo";
......@@ -8,12 +8,17 @@ import { useAppInitInfo } from "../common/useAppInitInfo";
/** 在小程序平台监听远程联系人的呼叫动作 */
export function useCallerListener() {
const { caller, target, myCallState, answerCaller } = useInjector(useCallCenter);
const { checkCamearSetting } = useInjector(useAppInitInfo)
const { checkCamearSetting } = useInjector(useAppInitInfo);
onMounted(() => {
/** 保持屏幕常亮 */
onMounted(() => setKeepScreenOn({keepScreenOn: true}));
})
watch(caller, current => {
if(!current) return;
switch(current.action) {
case 'Request':
case 'Request':
break;
case 'Hangup':
showToast({title: '对方取消了呼叫', icon: 'none'});
......@@ -42,7 +47,7 @@ export function useCallerListener() {
navigateTo({url: '/pages/calling/index'});
}
break;
case 'being_called':
case 'callin':
checkCamearSetting().then(r => {
r ? navigateTo({url: '/pages/calling/index'}) : answerCaller('NoDevice')
})
......
......@@ -2,8 +2,7 @@ import { CUSTOME_REQUESTER, RequesterFunc, RequestOptions } from 'vue-vulcan';
import { request, showToast } from '@tarojs/taro';
export function useCustomeRequest(): RequesterFunc {
return function (url: string, reqs: RequestOptions) {
console.log('my url', url)
return function (url: string, reqs: RequestOptions) {
return request({
...reqs,
url,
......
import { useAuthData } from "../../../any-hooks/auth/useAuthData";
import { useAuthData } from "any-hooks/auth/useAuthData";
import { HttpIntercept, HttpResponse, HTTP_INTERCEPT, RequestOptions, useInjector } from "vue-vulcan";
import { showToast } from "@tarojs/taro";
......@@ -20,13 +20,7 @@ export function useHttpIntercept(): HttpIntercept {
}
})
}
const checkResData = (data: any) => {
if(data.success) return true;
showToast({title: data.msg, icon: 'none'});
return false;
}
const responseIntercept = (res: HttpResponse) => {
switch(res.status) {
case 404:
......@@ -42,6 +36,13 @@ export function useHttpIntercept(): HttpIntercept {
}
})
}
const checkResData = (data: any) => {
if(data.success) return true;
showToast({title: data.msg, icon: 'none'});
return false;
}
return {
requestIntercept,
......
......@@ -24,7 +24,7 @@
<template>
<view class="page call-container">
<view class="call-box caller" v-if="myCallState==='being_called'">
<view class="call-box caller" v-if="myCallState==='callin'">
<image class="avatar" :src="caller?.avatar"></image>
<text class="tips" >{{caller?.nickname}}向您发起呼叫</text>
</view>
......@@ -35,7 +35,7 @@
</view>
<view class="operators" v-if="myCallState!=='free'">
<image v-if="myCallState==='being_called'" @tap="answerCaller('Connect')" class="op-icon" src="../../assets/answer3x.png"></image>
<image v-if="myCallState==='callin'" @tap="answerCaller('Connect')" class="op-icon" src="../../assets/answer3x.png"></image>
<image @tap="onTapHangup()" class="op-icon" src="../../assets/hangup.png"></image>
</view>
</view>
......
<script lang="ts" setup>
import { navigateTo } from '@tarojs/taro';
import { useContacts } from 'any-hooks/contacts/useContacts';
import { useContacts } from 'any-hooks/contacts/useContacts';
import { useInjector } from 'vue-vulcan';
const { filterGroups } = useInjector(useContacts);
const gotoGroupContacts = (id: string) => {
navigateTo({url: `/pages/group-contacts/index?id=${id}`})
navigateTo({url: `/pages/group-contacts/index?id=${id}`});
}
</script>
......
......@@ -27,7 +27,7 @@
<template>
<scroll-view :scrollY="true" class="invite-container page" :style="{top: topDistance+'px'}" >
<view class="contact-role-group" v-for="(group, key, index) in roleContacts" :key="index">
<view class="contact-role-group" v-for="(group, key, index) in freeContacts" :key="index">
<view class="role-name pd-2" :class="{hide: hideConfig[index]}" @tap="toggleHideByIndex(index)">{{key}}</view>
<view class="white-box" :style="{display: hideConfig[index] ? 'none' : 'block'}">
<view class="contact-item" v-for="(item, i) in group" :key="i" >
......@@ -47,13 +47,15 @@
<style lang="less">
.invite-container{
position: absolute;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
z-index: 1000;
top: 0;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.65);
background-color: #fff;
z-index: 10000;
.contact-role-group{
background-color: #fff;
......@@ -66,7 +68,7 @@
}
&::before{
content: '';
width: 0;
width: 0;
height: 0;
position: absolute;
border-left: 10px solid transparent;
......@@ -100,7 +102,7 @@
display: inline-block;
background: #2b91e2;
color: #fff;
padding: 6px 12px;
padding: 2px 15px;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment