mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-30 18:47:51 +00:00 
			
		
		
		
	 16fe912fbd
			
		
	
	16fe912fbd
	
	
	
		
			
			Co-authored-by: Nithin David Thomas <webofnithin@gmail.com> Co-authored-by: Sojan Jose <sojan@pepalo.com>
		
			
				
	
	
		
			27 lines
		
	
	
		
			588 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			588 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 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;
 |