[Feature] Website live chat (#187)
Co-authored-by: Nithin David Thomas <webofnithin@gmail.com> Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
parent
a4114288f3
commit
16fe912fbd
80 changed files with 2040 additions and 106 deletions
26
app/javascript/shared/helpers/BaseActionCableConnector.js
Normal file
26
app/javascript/shared/helpers/BaseActionCableConnector.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { createConsumer } from '@rails/actioncable';
|
||||
|
||||
class BaseActionCableConnector {
|
||||
constructor(app, pubsubToken) {
|
||||
const consumer = createConsumer();
|
||||
consumer.subscriptions.create(
|
||||
{
|
||||
channel: 'RoomChannel',
|
||||
pubsub_token: pubsubToken,
|
||||
},
|
||||
{
|
||||
received: this.onReceived,
|
||||
}
|
||||
);
|
||||
this.app = app;
|
||||
this.events = {};
|
||||
}
|
||||
|
||||
onReceived = ({ event, data } = {}) => {
|
||||
if (this.events[event] && typeof this.events[event] === 'function') {
|
||||
this.events[event](data);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default BaseActionCableConnector;
|
Loading…
Add table
Add a link
Reference in a new issue