mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			646 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			646 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import { createConsumer } from '@rails/actioncable';
 | 
						|
 | 
						|
class BaseActionCableConnector {
 | 
						|
  constructor(app, pubsubToken) {
 | 
						|
    this.consumer = createConsumer();
 | 
						|
    this.consumer.subscriptions.create(
 | 
						|
      {
 | 
						|
        channel: 'RoomChannel',
 | 
						|
        pubsub_token: pubsubToken,
 | 
						|
      },
 | 
						|
      {
 | 
						|
        received: this.onReceived,
 | 
						|
      }
 | 
						|
    );
 | 
						|
    this.app = app;
 | 
						|
    this.events = {};
 | 
						|
  }
 | 
						|
 | 
						|
  disconnect() {
 | 
						|
    this.consumer.disconnect();
 | 
						|
  }
 | 
						|
 | 
						|
  onReceived = ({ event, data } = {}) => {
 | 
						|
    if (this.events[event] && typeof this.events[event] === 'function') {
 | 
						|
      this.events[event](data);
 | 
						|
    }
 | 
						|
  };
 | 
						|
}
 | 
						|
 | 
						|
export default BaseActionCableConnector;
 |