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
6cd1118b
Unverified
Commit
6cd1118b
authored
May 30, 2018
by
Mikael Mello
Browse files
Change subscribe method to be more flexible
Allow any number of parameters
parent
ea8bdb74
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
6cd1118b
...
...
@@ -206,10 +206,10 @@ Login to Rocket.Chat via Asteroid
Logout current user via Asteroid
-
Returns promise
### `driver.subscribe(
topic, roomId
)`
### `driver.subscribe(
subscriptionName, ...params
)`
Subscribe to Meteor subscription
-
Accepts parameters for
Rocket.Chat streamer
-
Accepts parameters for
the subscription
-
Returns promise
-
Resolves with subscription instance (with ID)
...
...
src/lib/driver.ts
View file @
6cd1118b
...
...
@@ -283,12 +283,13 @@ export function logout (): Promise<void | null> {
/**
* Subscribe to Meteor subscription
* Resolves with subscription (added to array), with ID property
* @todo - 3rd param of asteroid.subscribe is deprecated in Rocket.Chat?
* @param subscriptionName Name of the publication to subscribe to
* @param params Any params required by the publication
*/
export
function
subscribe
(
topic
:
string
,
roomId
:
string
):
Promise
<
ISubscription
>
{
export
function
subscribe
(
subscriptionName
:
string
,
...
params
:
any
[]
):
Promise
<
ISubscription
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
logger
.
info
(
`[subscribe] Preparing subscription:
${
topic
}
:
${
roomId
}
`
)
const
subscription
=
asteroid
.
subscribe
(
topic
,
roomId
,
true
)
logger
.
info
(
`[subscribe] Preparing subscription:
${
subscriptionName
}
with params
${
params
}
`
)
const
subscription
=
asteroid
.
subscribe
(
subscriptionName
,
...
params
)
subscriptions
.
push
(
subscription
)
return
subscription
.
ready
.
then
((
id
)
=>
{
logger
.
info
(
`[subscribe] Stream ready:
${
id
}
`
)
...
...
@@ -331,7 +332,7 @@ export function unsubscribeAll (): void {
* Older adapters used an option for this method but it was always the default.
*/
export
function
subscribeToMessages
():
Promise
<
ISubscription
>
{
return
subscribe
(
_messageCollectionName
,
_messageStreamName
)
return
subscribe
(
_messageCollectionName
,
_messageStreamName
,
true
)
.
then
((
subscription
)
=>
{
messages
=
asteroid
.
getCollection
(
_messageCollectionName
)
// v2
...
...
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