Rocket.Chat.RealTime.API.RxJS
v2.1.1
用于利用Rocket.Chat的实时API方法的抽象使用RXJS V6
npm install --save rocket.chat.realtime.api.rxjs
用于rxjs v5版本的软件包
npm install --save [email protected]
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().subscribe();
// Responds "pong" to the "ping" message sent by the Realtime API. To keep the connection alive.
const auth = realTimeAPI.login(USERNAME, PASSWORD);
// Creating Observable
//Now subscribing the observable
auth.subscribe(
(data) => console.log(data),
(err) => console.log(err),
() => console.log('completed'));
...
...
// Use any of the methods implmented in the package.
| 方法 | 功能 |
|---|---|
| ConnectToserver() | 启动到服务器连接到实时API。通过服务器的响应返回可观察的 |
| keepalive() | 返回可观察到的订阅,该订阅对实时API发送的“ ping”响应“ pong”。保持连接的活力。 |
| 登录(用户名,密码) | 可观察到实时API的结果/响应的返回。 |
| loginwithauthtoken(authtoken) | 可观察到实时API的结果/响应的返回。 |
| loginwithoauth(CredToken,CredSecret) | 可观察到实时API的结果/响应的返回。 |
| callmethod(方法名称,...参数) | 返回可观察到的方法是来自Rocket.Chat实时API的方法的结果 |
| sendmessage(jsonobject) | 将JSON对象发送到API服务器 |
| onMessage(消息=> console.log(message)) | 订阅从服务器发送的消息 |
| OnError(error => console.error(error)) | 订阅错误。 |
| oncompletion(()=> console.info(“ pountty”)) | 在WebSocket连接上订阅完成 |
| 订阅(MessageHandler,ErryHandler,plotehhandler) | 订阅所有三个IE-消息,错误和完成 |
| getObservable() | 返回可观察到的Websocket连接到实时API的连接 |
| 断开() | 断开客户端和实时API之间的WebSocket连接 |