Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
RocketChat
Rocket.Chat.js.SDK
Commits
111c353a
Commit
111c353a
authored
Feb 22, 2019
by
Marcos Defendi
Browse files
Trigger onTyping when agent disconnects
parent
d6c6fda0
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/clients/Livechat.ts
View file @
111c353a
...
...
@@ -33,6 +33,13 @@ export default class LivechatClient extends LivechatRest implements ISocket {
throw
new
Error
(
`Invalid Protocol:
${
protocol
}
, valids:
${
Object
.
keys
(
Protocols
).
join
()}
`
)
}
}
private
_onAgentStatusChange
(
cb
:
ICallback
){
this
.
onStreamData
(
this
.
livechatStream
,
({
fields
:
{
args
:
[{
type
,
status
,
username
}]
}
}:
any
)
=>
{
if
(
type
===
'
agentStatus
'
)
{
cb
(
null
,
{
status
,
username
});
}
})
}
async
connect
(
options
:
ISocketOptions
,
callback
?:
ICallback
):
Promise
<
any
>
{
return
(
await
this
.
socket
as
ISocket
).
connect
(
options
)
}
async
disconnect
():
Promise
<
any
>
{
return
(
await
this
.
socket
as
ISocket
).
disconnect
()
}
async
unsubscribe
(
subscription
:
ISubscription
):
Promise
<
any
>
{
return
(
await
this
.
socket
as
ISocket
).
unsubscribe
(
subscription
)
}
...
...
@@ -41,7 +48,15 @@ export default class LivechatClient extends LivechatRest implements ISocket {
async
subscribeLoggedNotify
():
Promise
<
any
>
{
return
(
await
this
.
socket
as
IDriver
)
.
subscribeLoggedNotify
()
}
async
subscribeNotifyUser
():
Promise
<
any
>
{
return
(
await
this
.
socket
as
IDriver
)
.
subscribeNotifyUser
()
}
async
onMessage
(
cb
:
ICallback
):
Promise
<
any
>
{
return
(
await
this
.
socket
as
IDriver
).
onMessage
(
cb
)
}
async
onTyping
(
cb
:
ICallback
):
Promise
<
any
>
{
return
(
await
this
.
socket
as
IDriver
).
onTyping
(
cb
)
}
async
onTyping
(
rid
:
string
,
cb
:
ICallback
):
Promise
<
any
>
{
await
this
.
subscribe
(
this
.
livechatStream
,
rid
)
this
.
_onAgentStatusChange
(
async
(
error
,
{
status
,
username
}:
any
)
=>
{
if
(
status
===
'
offline
'
)
{
return
(
await
this
.
socket
as
IDriver
).
onTyping
(
cb
,
username
,
false
);
}
})
return
(
await
this
.
socket
as
IDriver
).
onTyping
(
cb
)
}
async
onAgentChange
(
rid
:
string
,
cb
:
ICallback
)
{
await
this
.
subscribe
(
this
.
livechatStream
,
rid
)
this
.
onStreamData
(
this
.
livechatStream
,
({
fields
:
{
args
:
[{
type
,
data
}]
}
}:
any
)
=>
{
...
...
@@ -52,10 +67,8 @@ export default class LivechatClient extends LivechatRest implements ISocket {
}
async
onAgentStatusChange
(
rid
:
string
,
cb
:
ICallback
){
await
this
.
subscribe
(
this
.
livechatStream
,
rid
);
this
.
onStreamData
(
this
.
livechatStream
,
({
fields
:
{
args
:
[{
type
,
status
}]
}
}:
any
)
=>
{
if
(
type
===
'
agentStatus
'
)
{
cb
(
status
)
}
this
.
_onAgentStatusChange
((
error
,
{
status
}:
any
)
=>
{
cb
(
status
)
})
}
...
...
src/lib/drivers/ddp.ts
View file @
111c353a
...
...
@@ -570,7 +570,10 @@ export class DDPDriver extends EventEmitter implements ISocket, IDriver {
this
.
ddp
.
on
(
'
stream-room-messages
'
,
({
fields
:
{
args
:
[
message
]
}
}:
any
)
=>
cb
(
this
.
ejsonMessage
(
message
)))
}
onTyping
=
(
cb
:
ICallback
):
Promise
<
any
>
=>
{
onTyping
=
(
cb
:
ICallback
,
username
?:
any
,
isTyping
?:
boolean
):
Promise
<
any
>
=>
{
if
(
status
!==
undefined
&&
username
)
{
cb
(
username
,
isTyping
)
}
return
this
.
ddp
.
on
(
'
stream-notify-room
'
,
({
fields
:
{
args
:
[
username
,
isTyping
]
}
}:
any
)
=>
{
cb
(
username
,
isTyping
)
})
as
any
...
...
src/lib/drivers/index.ts
View file @
111c353a
...
...
@@ -47,7 +47,7 @@ export interface IDriver {
subscribeNotifyUser
():
Promise
<
IDriver
>
onTyping
(
cb
:
ICallback
):
Promise
<
any
>
onTyping
(
cb
:
ICallback
,
username
?:
any
,
isTyping
?:
boolean
):
Promise
<
any
>
notifyVisitorTyping
(
rid
:
string
,
username
:
string
,
typing
:
boolean
,
token
:
string
):
Promise
<
any
>
...
...
Write
Preview
Supports
Markdown
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