Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
anyremote-miniapp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wxl
anyremote-miniapp
Commits
9432799a
Commit
9432799a
authored
Mar 04, 2021
by
wxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善call呼叫功能2
parent
5d4a286a
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
89 additions
and
43 deletions
+89
-43
any-hooks/common/useSocket.ts
+3
-2
any-hooks/communication/useCallCenter.ts
+7
-5
any-hooks/communication/useNetSocketCenter.ts
+7
-1
src/hooks/call/useCallerListener.ts
+36
-6
src/hooks/socket/useSocketSettings.ts
+9
-9
src/pages/calling/index.config.ts
+1
-1
src/pages/calling/index.vue
+13
-3
src/pages/index/index.vue
+10
-16
src/pages/meeting/index.config.ts
+3
-0
No files found.
any-hooks/common/useSocket.ts
View file @
9432799a
...
@@ -29,9 +29,9 @@ export function useSocket<S = any>() {
...
@@ -29,9 +29,9 @@ export function useSocket<S = any>() {
}
}
// 心跳链接
// 心跳链接
const
startHeartConnect
=
()
=>
{
const
startHeartConnect
=
(
data
?:
any
)
=>
{
const
time
=
socketSettings
.
heartInterval
;
const
time
=
socketSettings
.
heartInterval
;
setInterval
(
()
=>
ws
.
send
(
socketSettings
.
heartData
),
time
&&
time
>=
3000
?
time
:
5000
)
setInterval
(
()
=>
ws
.
send
(
data
||
socketSettings
.
heartData
),
time
&&
time
>=
3000
?
time
:
5000
)
}
}
// 重连功能
// 重连功能
...
@@ -51,6 +51,7 @@ export function useSocket<S = any>() {
...
@@ -51,6 +51,7 @@ export function useSocket<S = any>() {
currentMsg
,
currentMsg
,
status
,
status
,
connect
,
connect
,
startHeartConnect
,
send
:
ws
.
send
,
send
:
ws
.
send
,
close
:
ws
.
close
close
:
ws
.
close
}
}
...
...
any-hooks/communication/useCallCenter.ts
View file @
9432799a
...
@@ -19,7 +19,7 @@ export function useCallCenter() {
...
@@ -19,7 +19,7 @@ export function useCallCenter() {
/** 主动呼叫功能 */
/** 主动呼叫功能 */
const
[
target
,
setTarget
]
=
useState
<
Caller
>
(
null
);
const
[
target
,
setTarget
]
=
useState
<
Caller
>
(
null
);
const
[
myCallState
,
setCallState
]
=
useState
<
CallingState
>
(
null
);
const
[
myCallState
,
setCallState
]
=
useState
<
CallingState
>
(
'free'
);
const
{
currentChannel
,
createChannel
,
joinCallingChannel
}
=
useInjector
(
useChannelStore
);
const
{
currentChannel
,
createChannel
,
joinCallingChannel
}
=
useInjector
(
useChannelStore
);
const
callContact
=
(
user
:
UserData
)
=>
{
const
callContact
=
(
user
:
UserData
)
=>
{
setTarget
({...
user
,
action
:
'none'
});
//保存呼叫目标的信息
setTarget
({...
user
,
action
:
'none'
});
//保存呼叫目标的信息
...
@@ -51,10 +51,11 @@ export function useCallCenter() {
...
@@ -51,10 +51,11 @@ export function useCallCenter() {
/** 呼叫监听功能 */
/** 呼叫监听功能 */
const
[
caller
,
setCaller
]
=
useState
<
Caller
>
(
null
);
const
[
caller
,
setCaller
]
=
useState
<
Caller
>
(
null
);
// 监听来自其他用户的呼叫
// 监听来自其他用户的呼叫
请求
watch
(
currentMsg
,
msg
=>
{
watch
(
currentMsg
,
msg
=>
{
if
(
msg
.
msgMainFlag
!==
'CallOffer'
)
return
;
if
(
msg
.
msgMainFlag
!==
'CallOffer'
)
return
;
if
(
myCallState
.
value
!==
'free'
)
answerCaller
(
'Busying'
);
if
(
myCallState
.
value
!==
'free'
)
answerCaller
(
'Busying'
);
console
.
log
(
msg
.
msgSubFlag
);
setCaller
({
setCaller
({
id
:
currentMsg
.
value
.
fromID
,
id
:
currentMsg
.
value
.
fromID
,
nickname
:
currentMsg
.
value
.
fromName
,
nickname
:
currentMsg
.
value
.
fromName
,
...
@@ -71,21 +72,22 @@ export function useCallCenter() {
...
@@ -71,21 +72,22 @@ export function useCallCenter() {
break
;
break
;
case
'Busying'
:
case
'Busying'
:
case
'Hangup'
:
case
'Hangup'
:
console
.
log
(
'对方拒绝呼叫请求'
)
setCallState
(
'free'
);
setCallState
(
'free'
);
target
.
value
.
action
=
msg
.
msgSubFlag
;
setTarget
({...
target
.
value
,
action
:
msg
.
msgSubFlag
});
break
;
break
;
}
}
})
})
/** 呼叫挂断功能 */
/** 呼叫挂断功能 */
const
hangup
=
()
=>
{
const
hangup
=
()
=>
{
setCallState
(
'free'
);
sendMsg
({
sendMsg
({
channelID
:
currentChannel
.
value
.
channel_id
,
channelID
:
currentChannel
.
value
.
channel_id
,
msgMainFlag
:
myCallState
.
value
===
'call
_successed
'
?
'CallOffer'
:
'CallAnswer'
,
msgMainFlag
:
myCallState
.
value
===
'call
ing
'
?
'CallOffer'
:
'CallAnswer'
,
msgSubFlag
:
'Hangup'
,
msgSubFlag
:
'Hangup'
,
toID
:
myCallState
.
value
===
'calling'
?
target
.
value
.
id
:
caller
.
value
.
id
toID
:
myCallState
.
value
===
'calling'
?
target
.
value
.
id
:
caller
.
value
.
id
})
})
setCallState
(
'free'
);
}
}
return
{
return
{
...
...
any-hooks/communication/useNetSocketCenter.ts
View file @
9432799a
...
@@ -15,7 +15,7 @@ enum NetStates {
...
@@ -15,7 +15,7 @@ enum NetStates {
export
function
useNetSocketCenter
()
{
export
function
useNetSocketCenter
()
{
const
{
authData
}
=
useInjector
(
useAuthData
);
const
{
authData
}
=
useInjector
(
useAuthData
);
const
{
connect
,
send
,
currentMsg
}
=
useSocket
<
AnyRemoteSocketMessage
>
();
const
{
connect
,
send
,
currentMsg
,
startHeartConnect
}
=
useSocket
<
AnyRemoteSocketMessage
>
();
const
[
netState
,
setNetState
]
=
useState
<
NetStates
>
(
0
);
const
[
netState
,
setNetState
]
=
useState
<
NetStates
>
(
0
);
watch
(
authData
,
data
=>
{
watch
(
authData
,
data
=>
{
...
@@ -23,6 +23,12 @@ export function useNetSocketCenter() {
...
@@ -23,6 +23,12 @@ export function useNetSocketCenter() {
connect
(
connect
(
`wss://www.if-ar.com:3009?fromID=
${
data
.
id
}
&fromName=
${
data
.
nickname
}
&signID=SA&companyID=
${
data
.
company_id
}
`
`wss://www.if-ar.com:3009?fromID=
${
data
.
id
}
&fromName=
${
data
.
nickname
}
&signID=SA&companyID=
${
data
.
company_id
}
`
)
)
startHeartConnect
({
fromID
:
authData
.
value
.
id
,
fromName
:
authData
.
value
.
nickname
,
toID
:
'0'
,
msgMainFlag
:
'Heart'
})
})
})
const
sendMsg
=
(
data
:
AnyRemoteSocketMessage
)
=>
{
const
sendMsg
=
(
data
:
AnyRemoteSocketMessage
)
=>
{
...
...
src/hooks/call/useCallerListener.ts
View file @
9432799a
import
{
showModal
}
from
"@tarojs/taro"
;
import
{
navigateBack
,
navigateTo
,
redirectTo
,
showModal
,
showToast
}
from
"@tarojs/taro"
;
import
{
useCallCenter
}
from
"any-hooks/communication/useCallCenter"
;
import
{
useCallCenter
}
from
"any-hooks/communication/useCallCenter"
;
import
{
watch
}
from
"vue"
;
import
{
watch
}
from
"vue"
;
import
{
useInjector
}
from
"vue-vulcan"
;
import
{
useInjector
}
from
"vue-vulcan"
;
...
@@ -6,15 +6,44 @@ import { useInjector } from "vue-vulcan";
...
@@ -6,15 +6,44 @@ import { useInjector } from "vue-vulcan";
/** 在小程序平台监听远程联系人的呼叫动作 */
/** 在小程序平台监听远程联系人的呼叫动作 */
export
function
useCallerListener
()
{
export
function
useCallerListener
()
{
const
{
caller
,
answerCaller
}
=
useInjector
(
useCallCenter
);
const
{
caller
,
myCallState
,
answerCaller
}
=
useInjector
(
useCallCenter
);
watch
(
caller
,
value
=>
{
watch
(
caller
,
current
=>
{
if
(
caller
)
{
switch
(
current
.
action
)
{
case
'Request'
:
showModal
({
showModal
({
title
:
`来自
${
value
.
nickname
}
的呼叫,是否接受?`
,
content
:
`来自
${
current
.
nickname
}
的呼叫,是否接受?`
,
success
:
()
=>
answerCaller
(
'Connect'
),
cancelText
:
'拒绝'
,
cancelColor
:
'red'
,
confirmText
:
'接受'
,
success
:
res
=>
{
if
(
caller
.
value
.
action
!==
'Request'
)
return
;
//此次必须通过caller访问action值
res
.
confirm
?
answerCaller
(
'Connect'
)
:
answerCaller
(
'Hangup'
);
},
fail
:
()
=>
answerCaller
(
'Hangup'
)
fail
:
()
=>
answerCaller
(
'Hangup'
)
})
})
break
;
case
'Hangup'
:
showToast
({
title
:
'对方已取消呼叫,您可以关闭呼叫对话框'
,
icon
:
'none'
});
break
;
}
})
// 根据用户的呼叫状态变化,执行相应的页面跳转逻辑
watch
(
myCallState
,
state
=>
{
switch
(
state
)
{
case
'call_accepted'
:
navigateTo
({
url
:
'/pages/meeting/index'
});
break
;
case
'call_successed'
:
redirectTo
({
url
:
'/pages/meeting/index'
});
break
;
case
'calling'
:
navigateTo
({
url
:
'/pages/calling/index'
});
break
;
case
'free'
:
navigateBack
({
delta
:
2
})
break
;
}
}
})
})
}
}
\ No newline at end of file
src/hooks/socket/useSocketSettings.ts
View file @
9432799a
import
{
useAuthData
}
from
"any-hooks/auth/useAuthData"
;
//
import { useAuthData } from "any-hooks/auth/useAuthData";
import
{
SOCKET_SETTINGS
}
from
"any-hooks/communication/token"
;
import
{
SOCKET_SETTINGS
}
from
"any-hooks/communication/token"
;
import
{
SocketSettings
}
from
"any-hooks/types/socket"
;
import
{
SocketSettings
}
from
"any-hooks/types/socket"
;
import
{
useInjector
}
from
"vue-vulcan"
;
//
import { useInjector } from "vue-vulcan";
export
function
useSocketSetting
():
SocketSettings
{
export
function
useSocketSetting
():
SocketSettings
{
const
{
authData
}
=
useInjector
(
useAuthData
);
//
const { authData } = useInjector(useAuthData);
return
{
return
{
heartData
:
{
//
heartData: {
msgMainFlag
:
"Heart"
,
//
msgMainFlag:"Heart",
fromID
:
authData
.
value
.
id
,
//
fromID: authData.value.id,
fromName
:
authData
.
value
.
nickname
,
//
fromName: authData.value.nickname,
toID
:
'0'
//
toID: '0'
},
//
},
retryLimit
:
10
retryLimit
:
10
}
}
}
}
...
...
src/pages/calling/index.config.ts
View file @
9432799a
export
default
{
export
default
{
navigation
BarTitleText
:
'呼叫联系人'
,
navigation
Style
:
'custom'
}
}
src/pages/calling/index.vue
View file @
9432799a
<
script
setup
>
<
script
setup
>
import
{
useInjector
}
from
'vue-vulcan'
;
import
{
useInjector
}
from
'vue-vulcan'
;
import
{
computed
,
getCurrentInstance
,
onMounted
}
from
'vue'
;
import
{
computed
,
getCurrentInstance
,
onMounted
,
watch
}
from
'vue'
;
import
{
useCallCenter
}
from
'any-hooks/communication/useCallCenter'
;
import
{
useCallCenter
}
from
'any-hooks/communication/useCallCenter'
;
import
{
navigateBack
,
showToast
}
from
'@tarojs/taro'
;
const
{
target
}
=
useInjector
(
useCallCenter
);
const
{
target
,
hangup
}
=
useInjector
(
useCallCenter
);
watch
(
target
,
val
=>
{
if
(
val
.
action
===
'Hangup'
)
{
showToast
({
title
:
'对方拒绝了您的呼叫请求'
,
icon
:
'none'
});
}
})
</
script
>
</
script
>
...
@@ -13,7 +23,7 @@
...
@@ -13,7 +23,7 @@
<image
class=
"avatar"
:src=
"target?.avatar"
></image>
<image
class=
"avatar"
:src=
"target?.avatar"
></image>
<text
class=
"tips"
>
正在呼叫
{{
target
?.
nickname
}}
...
</text>
<text
class=
"tips"
>
正在呼叫
{{
target
?.
nickname
}}
...
</text>
</view>
</view>
<image
class=
"hangup"
src=
"../../assets/hangup.png"
></image>
<image
@
tap=
"hangup()"
class=
"hangup"
src=
"../../assets/hangup.png"
></image>
</view>
</view>
</
template
>
</
template
>
...
...
src/pages/index/index.vue
View file @
9432799a
<
script
setup
lang=
"ts"
>
import
{
useInjector
}
from
'vue-vulcan'
;
import
{
useContacts
}
from
'../../../any-hooks/contacts/useContacts'
;
import
{
useCallCenter
}
from
'any-hooks/communication/useCallCenter'
;
const
{
callContact
}
=
useInjector
(
useCallCenter
);
const
{
contacts
}
=
useContacts
();
</
script
>
<
template
>
<
template
>
<view
class=
"index"
>
<view
class=
"index"
>
<view
class=
"contact-list"
>
<view
class=
"contact-list"
>
...
@@ -7,28 +16,13 @@
...
@@ -7,28 +16,13 @@
<view>
{{
item
.
nickname
}}
</view>
<view>
{{
item
.
nickname
}}
</view>
<text>
{{
item
.
permission
}}
</text>
<text>
{{
item
.
permission
}}
</text>
</view>
</view>
<image
@
tap=
"call(item)"
class=
"call"
src=
"../../assets/call.png"
/>
<image
@
tap=
"call
Contact
(item)"
class=
"call"
src=
"../../assets/call.png"
/>
</view>
</view>
</view>
</view>
</view>
</view>
</
template
>
</
template
>
<
script
setup
lang=
"ts"
>
import
{
navigateTo
}
from
'@tarojs/taro'
;
import
{
useInjector
}
from
'vue-vulcan'
;
import
{
useContacts
}
from
'../../../any-hooks/contacts/useContacts'
;
import
{
useCallCenter
}
from
'any-hooks/communication/useCallCenter'
;
import
{
UserData
}
from
'any-hooks/types/user'
;
const
{
callContact
}
=
useInjector
(
useCallCenter
);
const
call
=
(
data
:
UserData
)
=>
{
callContact
(
data
);
navigateTo
({
url
:
'/pages/calling/index'
});
}
const
{
contacts
}
=
useContacts
()
</
script
>
<
style
lang=
"less"
>
<
style
lang=
"less"
>
.contact-list
{
.contact-list
{
...
...
src/pages/meeting/index.config.ts
0 → 100644
View file @
9432799a
export
default
{
navigationBarTitleText
:
'通讯页'
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment