@ovos-media/react-realtime
v0.0.2
Published
Official React bindings for Realtime
Downloads
5
Readme
React Realtime
Official React bindings for Realtime.
Installation
React Realtime requires React 16 or later.
npm install --save ovos-media/react-realtime
This assumes that you’re using npm package manager with a module bundler like Webpack or Browserify to consume CommonJS modules.
How Does It Work?
// App.js
import React, { Component } from 'react';
import { Provider as RealtimeProvider } from '@ovos-media/react-realtime';
import realtime from '@ovos-media/play-live-realtime-ws-client';
realtime.init({
host: 'localhost',
port: '3215',
user: {}, // optional, user defined json data
handshakeCallback : function(data){} // optional, handshake callback function
}, () => {
console.log('success');
});
class App extends Component {
render() {
return (
<RealtimeProvider realtime={realtime}>
{children}
</RealtimeProvider>
);
}
}
export default App;
// MyButton.js
import React, { Component } from 'react';
import { withRealtime } from '@ovos-media/react-realtime';
class MyButton extends Component {
render() {
return (
<button onClick={this.pingRealtimeService}>
);
}
pingRealtimeService = () => {
const { realtime } = this.props;
realtime.request("connector.entryHandler.ping", {
foo: "bar"
}, function(response) {
console.log(response);
});
}
}
export default withRealtime()(MyButton);
License
MIT