Unverified Commit 6cd1118b authored by Mikael Mello's avatar Mikael Mello
Browse files

Change subscribe method to be more flexible

Allow any number of parameters
parent ea8bdb74
......@@ -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)
......@@ -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)
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
Supports Markdown
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