Giter VIP home page Giter VIP logo

rocket.chat.realtime.api.rxjs's Introduction

Rocket.Chat.RealTime.API.RxJS

Commitizen friendly Build Status codecov npm semantic-release

Abstraction for Utilizing Rocket.Chat's Realtime API Methods with RxJS v6

Installation

npm install --save rocket.chat.realtime.api.rxjs

For RxJS v5 Version of the Package

npm install --save [email protected]

Usage


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.

Methods

Methods Functionality
connectToServer() Initiates Connections to the Server to the RealTime API. Returns Observable with the server's response
keepAlive() Returns Observable to subscribe which Responds "pong" to the "ping" message sent by the Realtime API. To keep the connection alive.
login(username, password) Returns Observable to the Result/Response from the RealTime API.
loginWithAuthToken(authToken) Returns Observable to the Result/Response from the RealTime API.
loginWithOAuth(credToken, credSecret) Returns Observable to the Result/Response from the RealTime API.
callMethod(methodName, ...params) Returns Observable to the Result of Method Call from Rocket.Chat Realtime API
sendMessage(jsonObject) Sends the JSON Object to the API Server
onMessage( message => console.log(message) ) Subscribes to the Messages sent from the server
onError( error => console.error(error) ) Subscribes to the Errors.
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

Checkout the Rocket.Chat's RealTime API documentation for further information on working of the RealTime API.

rocket.chat.realtime.api.rxjs's People

Contributors

alexandrtovmach avatar chris-schra avatar dependabot[bot] avatar inf3cti0n95 avatar insanenaman avatar kawin-impekable avatar yiin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rocket.chat.realtime.api.rxjs's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

[Bug] `obj is undefined` error on login

If Websocket Connection is terminated before getLoginObservable function is executed this error will be thrown

screen shot 2561-06-21 at 12 42 57 am

The problem is in this line
https://github.com/inf3cti0n95/Rocket.Chat.RealTime.API.RxJS/blob/master/src/RealTimeAPI.ts#L176

If I understand it correctly, when Websocket is terminated and there is no response that match the find operator. The .map(obj => obj[0]) statement at the end of the line will throw out this error.

So my proposed fix is to add the condition to check if obj exist to resolve this issue.

Bug, websocket error

There is an error

/node_modules/rxjs/observable/dom/WebSocketSubject.js:39
    throw new Error('no WebSocket constructor can be found');

Rocket chat login error

when logging with rocket chat websocket url it shows error but on rest api it works well

Firefox can’t establish a connection to the server at wss://164.52.202.86:3002/websocket. bundle.js:53164:16
Incoming data:
error
​
bubbles: false
​
cancelBubble: false
​
cancelable: false
​
composed: false
​
currentTarget: null
​
defaultPrevented: false
​
eventPhase: 0
​
explicitOriginalTarget: WebSocket { url: "wss://164.52.202.86:3002/websocket", readyState: 3, bufferedAmount: 0, … }
​
isTrusted: true
​
originalTarget: WebSocket { url: "wss://164.52.202.86:3002/websocket", readyState: 3, bufferedAmount: 0, … }
​
returnValue: true
​
srcElement: WebSocket { url: "wss://164.52.202.86:3002/websocket", readyState: 3, bufferedAmount: 0, … }
​
target: WebSocket { url: "wss://164.52.202.86:3002/websocket", readyState: 3, bufferedAmount: 0, … }
​
timeStamp: 3571
​
type: "error"

can you please able to solve it.

Reconnecting Websocket.

I want to reconnect the Websocket after my app goes from the background to the foreground (Currently automatically disconnected when goes from the foreground to the background). How do I do this?

Prettify Code

The source code written has many inconsistency, like using double quotes and single quotes for strings, etc.

Documentation for RealTimeAPI

As there is a general lack of documentation for RealtimeAPI in Rocket.Chat's official docs and this package also needs a better example based docs, a New, Better Documentation

obj is undefined error showing on login subscribe

I am using the Rocket.Chat.RealTime.API.RxJS to integrating with my existing ionic (3.7) mobile application. my application requirement is Rocket.chat direct message only.

Server Setup Information:

Version of Rocket.Chat Server: 0.59.1
Operating System: Ubuntu 14.04.5 LTS
Deployment Method: Docker

My sample Code


import { Component } from '@angular/core';
import { IonicPage, LoadingController, ToastController, MenuController, Platform } from 'ionic-angular';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { LoginServices } from '../../services/loginservices';
import { Storage } from '@ionic/storage';
import { Events } from 'ionic-angular';
import { Network } from '@ionic-native/network';
import { RealTimeAPI } from "rocket.chat.realtime.api.rxjs";


@IonicPage()
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
})
export class LoginPage {

  loginData = { UserName: '', Password: '', RememberMe: false };
  data: any;
  loginForm: FormGroup;
  isConnectionExists: boolean = true;
  constructor(public authService: LoginServices, public loadingCtrl: LoadingController, private toastCtrl: ToastController, public fb: FormBuilder, public menuCtrl: MenuController, public storage: Storage, public events: Events, public platform: Platform, public network: Network) {
  
  }
 
  doLogin() {

    if (this.loginForm.dirty && this.loginForm.valid) {
     
        this.showLoader();
        
        const realTimeAPI =  new RealTimeAPI("ws://mydomain:3001/websocket");
        realTimeAPI.keepAlive(); 
        const auth = realTimeAPI.login(loginData.UserName, loginData.Password);
        auth.subscribe(
          (data) => console.log(data),
          (err) => console.log(err),
          () => console.log('completed'));
       
    }
  }

}

Screenshot of my console

image

Please any one help me on this.

[Question] Method for closing websocket connection

Is there a way to disconnect the websocket from Rocket.Chat ? if I understand it correctly there is no way to access this.webSocket from outside the lib. this.getObservable().unsubscribe() won't work either I guess because it returns this.webSocket.catch(). If this is true what about having new method for disconnecting the socket like this ? If it looks okay I can make a merge request for it

public disconnect() {
    return this.webSocket.unsubscribe();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.