react-zinnion-streaming

1.0.8 • Public • Published

react-zinnion-streaming

Installation

To get the latest version, simply install the package using npm:

npm install react-zinnion-streaming --save

Usage

You can disable token authentication with insecure: true parameter, but this mode is mostly for personal and demonstration uses.

All configuration parameters are described in zinnionrifuge-js documentation

Add provider:

const config = {
  url: "ws://localhost:8002/connection/websocket?format=protobuf",
  insecure: true // disable token auth
  // user: 'USER ID',
  // timestamp: 'UNIX TIMESTAMP',
  // token: 'TOKEN',
};

ReactDOM.render(
  <Provider store={store}>
    <ZinnionProvider config={config}>
      <Router>
        <Route path="/" component={App} />
      </Router>
    </ZinnionProvider>
  </Provider>,
  document.getElementById("app")
);

Handle messages:

import React from "react";
import { zinnion } from "react-zinnion-streaming";

// Make Centrifuge client accessible through `this.props.zinnion`
@zinnion
export class SiteMetrics extends React.Component {
  constructor(props) {
    super(props);

    // Subscribe on `site-metrics` channel.
    this.props.zinnion
      .subscribe("site-metrics", message => {
        this.handleMessage(message);
      })
      .history()
      .then(history => {
        this.handleHistory(history);
      });
  }

  handleMessage(message) {
    console.log("message", message.data);
  }

  handleHistory(history) {
    console.log("history", history.data);
  }
}

Documentation

Built With

  • CentrifugeJS - Javascript client to communicate with Centrifugo from web browser over Websockets or SockJS
  • React - A declarative, efficient, and flexible JavaScript library for building user interfaces.

Building & Testing

  • source can be loaded via npm, or downloaded from github repo.
  • npm run build to build
  • npm test to run tests

License

react-zinnion-streaming is licensed under The MIT License (MIT).


Package Sidebar

Install

npm i react-zinnion-streaming

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

9.34 kB

Total Files

11

Last publish

Collaborators

  • maurodelazeri