package Ġtw ilio . flutter . tw ilio _ program mable _ chat . listeners Ċ Ċ import Ġcom . tw ilio . chat . Channel Ċ import Ġcom . tw ilio . chat . Chat Client Ċ import Ġcom . tw ilio . chat . Chat Client Listener Ċ import Ġcom . tw ilio . chat . Error Info Ċ import Ġcom . tw ilio . chat . User Ċ import Ġio . flutter . plugin . common . Event Channel Ċ import Ġtw ilio . flutter . tw ilio _ program mable _ chat . Mapper Ċ import Ġtw ilio . flutter . tw ilio _ program mable _ chat . Tw ilio Program mable Chat Plugin Ċ Ċ class ĠChat Listener ( val Ġtoken : ĠString , Ġval Ġproperties : ĠChat Client . Properties ) Ġ: ĠChat Client Listener Ġ{ ĊĠĠĠ Ġvar Ġevents : ĠEvent Channel . Event Sink ? Ġ= Ġnull ĊĊĠĠĠ Ġvar Ġchat Client : ĠChat Client ? Ġ= Ġnull ĊĊĠĠĠ Ġoverride Ġfun Ġon Added To Channel Notification ( channel Sid : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Added To Channel Notification Ġ=> Ġchannel Sid Ġ= Ġ$ channel Sid ") ĊĠĠĠĠĠĠĠ Ġsend Event (" added To Channel Notification ", Ġmap Of (" channel Sid " Ġto Ġchannel Sid )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Channel Added ( channel : ĠChannel ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Channel Added Ġ=> Ġsid Ġ= Ġ${ channel . sid }") ĊĠĠĠĠĠĠĠ Ġsend Event (" channel Added ", Ġmap Of (" channel " Ġto ĠMapper . channel ToMap ( channel ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Channel Deleted ( channel : ĠChannel ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Channel Deleted Ġ=> Ġsid Ġ= Ġ${ channel . sid }") ĊĠĠĠĠĠĠĠ Ġsend Event (" channel Deleted ", Ġmap Of (" channel " Ġto ĠMapper . channel ToMap ( channel ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Channel Inv ited ( channel : ĠChannel ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Channel Inv ited Ġ=> Ġsid Ġ= Ġ${ channel . sid }") ĊĠĠĠĠĠĠĠ Ġsend Event (" channel Inv ited ", Ġmap Of (" channel " Ġto ĠMapper . channel ToMap ( channel ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Channel Joined ( channel : ĠChannel ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Channel Joined Ġ=> Ġsid Ġ= Ġ${ channel . sid }") ĊĠĠĠĠĠĠĠ Ġsend Event (" channel Joined ", Ġmap Of (" channel " Ġto ĠMapper . channel ToMap ( channel ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Channel Synchronization Change ( channel : ĠChannel ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Channel Synchronization Change Ġ=> Ġsid Ġ= Ġ${ channel . sid }") ĊĠĠĠĠĠĠĠ Ġsend Event (" channel Synchronization Change ", Ġmap Of (" channel " Ġto ĠMapper . channel ToMap ( channel ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Channel Updated ( channel : ĠChannel , Ġreason : ĠChannel . Update Reason ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Channel Updated Ġ=> Ġchannel Ġ'${ channel . sid }' Ġupdated , Ġ$ reason ") ĊĠĠĠĠĠĠĠ Ġsend Event (" channel Updated ", Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" channel " Ġto ĠMapper . channel ToMap ( channel ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" reason " Ġto Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" type " Ġto Ġ" channel ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" value " Ġto Ġreason . toString () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Client Synchronization ( synchron ization Status : ĠChat Client . Synchronization Status ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Client Synchronization Ġ=> Ġstatus Ġ= Ġ$ synchron ization Status ") ĊĠĠĠĠĠĠĠ Ġsend Event (" client Synchronization ", Ġmap Of (" synchron ization Status " Ġto Ġsynchronization Status . toString ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Connection StateChange ( connection State : ĠChat Client . Connection State ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Connection StateChange Ġ=> Ġstatus Ġ= Ġ$ connection State ") ĊĠĠĠĠĠĠĠ Ġsend Event (" connection StateChange ", Ġmap Of (" connection State " Ġto Ġconnection State . toString ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonError ( error Info : ĠError Info ) Ġ{ ĊĠĠĠĠĠĠĠ Ġsend Event (" error ", Ġnull , Ġerror Info ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Inv ited To Channel Notification ( channel Sid : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Inv ited To Channel Notification Ġ=> Ġchannel Sid Ġ= Ġ$ channel Sid ") ĊĠĠĠĠĠĠĠ Ġsend Event (" inv ited To Channel Notification ", Ġmap Of (" channel Sid " Ġto Ġchannel Sid )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon New Message Notification ( channel Sid : ĠString ?, Ġmessage Sid : ĠString ?, Ġmessage Index : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on New Message Notification Ġ=> Ġchannel Sid Ġ= Ġ$ channel Sid , Ġmessage Sid Ġ= Ġ$ message Sid , Ġmessage Index Ġ= Ġ$ message Index ") ĊĠĠĠĠĠĠĠ Ġsend Event (" new Message Notification ", Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" channel Sid " Ġto Ġchannel Sid , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" message Sid " Ġto Ġmessage Sid , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" message Index " Ġto Ġmessage Index ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Notification Sub scribed () Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Notification Sub scribed ") ĊĠĠĠĠĠĠĠ Ġsend Event (" notification Sub scribed ", Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Notification Failed ( error Info : ĠError Info ) Ġ{ ĊĠĠĠĠĠĠĠ Ġsend Event (" notification Failed ", Ġnull , Ġerror Info ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Removed From Channel Notification ( channel Sid : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Removed From Channel Notification Ġ=> Ġchannel Sid Ġ= Ġ$ channel Sid ") ĊĠĠĠĠĠĠĠ Ġsend Event (" removed From Channel Notification ", Ġmap Of (" channel Sid " Ġto Ġchannel Sid )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Token About To Expire () Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Token About To Expire ") ĊĠĠĠĠĠĠĠ Ġsend Event (" token About To Expire ", Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Token Expired () Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on Token Expired ") ĊĠĠĠĠĠĠĠ Ġsend Event (" token Expired ", Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon User Sub scribed ( user : ĠUser ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on User Sub scribed Ġ=> Ġuser Ġ'${ user . friendly Name }' ") ĊĠĠĠĠĠĠĠ Ġsend Event (" user Sub scribed ", Ġmap Of (" user " Ġto ĠMapper . user ToMap ( user ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon User Un subscribed ( user : ĠUser ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on User Un subscribed Ġ=> Ġuser Ġ'${ user . friendly Name }' ") ĊĠĠĠĠĠĠĠ Ġsend Event (" user Un subscribed ", Ġmap Of (" user " Ġto ĠMapper . user ToMap ( user ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon User Updated ( user : ĠUser , Ġreason : ĠUser . Update Reason ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTw ilio Program mable Chat Plugin . debug (" Chat Listener . on User Updated Ġ=> Ġuser Ġ'${ user . friendly Name }' Ġupdated , Ġ$ reason ") ĊĠĠĠĠĠĠĠ Ġsend Event (" user Updated ", Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" user " Ġto ĠMapper . user ToMap ( user ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" reason " Ġto Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" type " Ġto Ġ" user ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" value " Ġto Ġreason . toString () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsend Event ( name : ĠString , Ġdata : ĠAny ?, Ġe : ĠError Info ? Ġ= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġevent Data Ġ= Ġmap Of (" name " Ġto Ġname , Ġ" data " Ġto Ġdata , Ġ" error " Ġto ĠMapper . error Info ToMap ( e )) ĊĠĠĠĠĠĠĠ Ġevents ?. success ( event Data ) ĊĠĠĠ Ġ} Ċ } Ċ