fix: Decouple call popup from exotel
diff --git a/erpnext/communication/doctype/call_log/call_log.py b/erpnext/communication/doctype/call_log/call_log.py
index fcca0e4..0534706 100644
--- a/erpnext/communication/doctype/call_log/call_log.py
+++ b/erpnext/communication/doctype/call_log/call_log.py
@@ -3,8 +3,17 @@
 # For license information, please see license.txt
 
 from __future__ import unicode_literals
-# import frappe
+import frappe
 from frappe.model.document import Document
+from erpnext.crm.doctype.utils import get_employee_emails_for_popup
 
 class CallLog(Document):
-	pass
+	def after_insert(self):
+		employee_emails = get_employee_emails_for_popup(self.medium)
+		for email in employee_emails:
+			frappe.publish_realtime('show_call_popup', self, user=email)
+
+	def on_update(self):
+		doc_before_save = self.get_doc_before_save()
+		if doc_before_save.status in ['Ringing'] and self.status in ['Missed', 'Completed']:
+			frappe.publish_realtime('call_{id}_disconnected'.format(id=self.id), self)
diff --git a/erpnext/erpnext_integrations/exotel_integration.py b/erpnext/erpnext_integrations/exotel_integration.py
index 32602d6..f91f757 100644
--- a/erpnext/erpnext_integrations/exotel_integration.py
+++ b/erpnext/erpnext_integrations/exotel_integration.py
@@ -1,5 +1,4 @@
 import frappe
-from erpnext.crm.doctype.utils import get_employee_emails_for_popup
 import requests
 
 # api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call
@@ -17,14 +16,9 @@
 
 	call_log = get_call_log(kwargs)
 
-	employee_emails = get_employee_emails_for_popup(kwargs.get('To'))
-	for email in employee_emails:
-		frappe.publish_realtime('show_call_popup', call_log, user=email)
-
 @frappe.whitelist(allow_guest=True)
 def handle_end_call(*args, **kwargs):
 	call_log = update_call_log(kwargs, 'Completed')
-	frappe.publish_realtime('call_disconnected', call_log)
 
 @frappe.whitelist(allow_guest=True)
 def handle_missed_call(*args, **kwargs):
diff --git a/erpnext/public/js/call_popup/call_popup.js b/erpnext/public/js/call_popup/call_popup.js
index 4df2321..8748980 100644
--- a/erpnext/public/js/call_popup/call_popup.js
+++ b/erpnext/public/js/call_popup/call_popup.js
@@ -2,6 +2,7 @@
 	constructor(call_log) {
 		this.caller_number = call_log.from;
 		this.call_log = call_log;
+		this.setup_listener();
 		this.make();
 	}
 
@@ -187,6 +188,13 @@
 			}
 		});
 	}
+	setup_listener() {
+		frappe.realtime.on(`call_${this.call_log.id}_disconnected`, call_log => {
+			this.call_disconnected(call_log);
+			// Remove call disconnect listener after the call is disconnected
+			frappe.realtime.off(`call_${this.call_log.id}_disconnected`);
+		});
+	}
 }
 
 $(document).on('app_ready', function () {
@@ -198,9 +206,4 @@
 			erpnext.call_popup.dialog.show();
 		}
 	});
-	frappe.realtime.on('call_disconnected', call_log => {
-		if (erpnext.call_popup && erpnext.call_popup.call_log.id === call_log.id) {
-			erpnext.call_popup.call_disconnected(call_log);
-		}
-	});
 });