From f3c05c12650bfdf03958984da56d0a424910ac9b Mon Sep 17 00:00:00 2001 From: Kawin Date: Thu, 21 Jun 2018 00:13:28 +0700 Subject: [PATCH] Add disconnect method & Update documentation --- README.md | 5 +++-- src/RealTimeAPI.ts | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2678d92..b638c22 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Abstraction for Utilizing [Rocket.Chat](https://rocket.chat/)'s [Realtime API](h ## Installation ``` -npm install --save rocket.chat.realtime.api.rxjs +npm install --save rocket.chat.realtime.api.rxjs ``` ## Usage @@ -15,7 +15,7 @@ import { RealTimeAPI } from "rocket.chat.realtime.api.rxjs"; const realTimeAPI = new RealTimeAPI("wss://demo.rocket.chat/websocket"); // Provide, URL to the Rocket.Chat's Realtime API. -realTimeAPI.keepAlive(); +realTimeAPI.keepAlive(); // Responds "pong" to the "ping" message sent by the Realtime API. To keep the connection alive. const auth = realTimeApi.login(USERNAME, PASSWORD); @@ -50,6 +50,7 @@ const auth = realTimeApi.login(USERNAME, PASSWORD); | onCompletion(() => console.info("Complete")) | Subscribes to Completion on the Websocket Connection | | subscribe(messageHandler, errorHandler, completionHandler) | Subscribes to All three i.e - messages, errors and completion | | getObservable() | Returns observable of the WebSocket Connection to the RealTime API | +| disconnect() | Disconnect the WebSocket Connection between client and RealTime API | | | | diff --git a/src/RealTimeAPI.ts b/src/RealTimeAPI.ts index 480b74f..0a58f32 100644 --- a/src/RealTimeAPI.ts +++ b/src/RealTimeAPI.ts @@ -33,6 +33,13 @@ export class RealTimeAPI { return this.webSocket.catch(err => Observable.of(err)); } + /** + * Disconnect the WebSocket Connection between client and RealTime API + */ + public disconnect() { + return this.webSocket.unsubscribe(); + } + /** * onMessage */