mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			981 B
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			981 B
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
import { WOOT_PREFIX } from './constants';
 | 
						|
 | 
						|
export const isEmptyObject = obj =>
 | 
						|
  Object.keys(obj).length === 0 && obj.constructor === Object;
 | 
						|
 | 
						|
export const arrayToHashById = array =>
 | 
						|
  array.reduce((map, obj) => {
 | 
						|
    const newMap = map;
 | 
						|
    newMap[obj.id] = obj;
 | 
						|
    return newMap;
 | 
						|
  }, {});
 | 
						|
 | 
						|
export const IFrameHelper = {
 | 
						|
  isIFrame: () => window.self !== window.top,
 | 
						|
  sendMessage: msg => {
 | 
						|
    window.parent.postMessage(
 | 
						|
      `chatwoot-widget:${JSON.stringify({ ...msg })}`,
 | 
						|
      '*'
 | 
						|
    );
 | 
						|
  },
 | 
						|
  isAValidEvent: e => {
 | 
						|
    const isDataAString = typeof e.data === 'string';
 | 
						|
    const isAValidWootEvent =
 | 
						|
      isDataAString && e.data.indexOf(WOOT_PREFIX) === 0;
 | 
						|
    return isAValidWootEvent;
 | 
						|
  },
 | 
						|
  getMessage: e => JSON.parse(e.data.replace(WOOT_PREFIX, '')),
 | 
						|
};
 | 
						|
export const RNHelper = {
 | 
						|
  isRNWebView: () => window.ReactNativeWebView,
 | 
						|
  sendMessage: msg => {
 | 
						|
    window.ReactNativeWebView.postMessage(
 | 
						|
      `chatwoot-widget:${JSON.stringify({ ...msg })}`
 | 
						|
    );
 | 
						|
  },
 | 
						|
};
 |