const getClient = ( ) => { const { navigator : { standalone , userAgent } , } = window as any ; const lowercaseUserAgent = userAgent . toLowerCase ( ) ; const safari = /safari/ . test ( lowercaseUserAgent ) ; const ios = /iphone|ipod|ipad/ . test ( lowercaseUserAgent ) ; if ( ios ) { if ( ! standalone && safari ) { } else if ( standalone && ! safari ) { } else if ( ! standalone && ! safari ) { return 'ios' ; } } if ( typeof ( window as any ) . AndroidInterface !== 'undefined' ) { return 'android' ; } if ( ( window as any ) . chrome && ( window as any ) . chrome . webview ) { return 'webview' ; } return 'web' ; } ; export enum MessageType { NOTIFICATION = 'NOTIFICATION' , RESIZE = 'RESIZE' , HUMAN_VERIFICATION_SUCCESS = 'HUMAN_VERIFICATION_SUCCESS' } type Message = { type : MessageType . NOTIFICATION ; payload : { type : string ; text : string ; } ; } | { type : MessageType . RESIZE ; payload : { height : number ; } ; } | { type : MessageType . HUMAN_VERIFICATION_SUCCESS ; payload : { token : string ; type : string ; } ; } ; const broadcast = ( message ) => { const client = getClient ( ) ; const serialized = JSON . stringify ( message ) ; switch ( client ) { case 'ios' : { ( window as any ) . webkit . messageHandlers . iOS . postMessage ( serialized ) ; break ; } case 'android' : { ( window as any ) . AndroidInterface . dispatch ( serialized ) ; break ; } case 'webview' : { break ; } case 'web' : { window . parent . postMessage ( serialized , '*' ) ; break ; } default : } } ; export default broadcast ;