How to listen Salesforce Chat Close Event?

Salesforce Chats can be ended by embedded_svc.addEventHandler() can be used for listening onChatEndedByChasitor, onChatEndedByAgent and onChatEndedByChatbot events. Sample Code: embedded_svc.addEventHandler() should be added before the embedded_svc.init().