Add comprehensive debugging for hold button state issues

Debugging Enhancements:
- Added detailed console logging for hold button element detection
- Enhanced AJAX request/response logging for hold operations
- Added button state verification with delayed checks
- Tracked endCall() function calls that might reset button state
- Added logging for button text and class changes

This will help identify:
1. Whether the button element is found correctly
2. If AJAX calls are succeeding or failing
3. Whether button updates are being applied
4. If other functions are interfering with button state
5. Timing issues with DOM updates

Use browser console to debug hold button behavior during testing.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-08-30 17:44:05 -07:00
parent 0b8c5f4a4c
commit c8c02da433

View File

@@ -527,6 +527,7 @@
$('.twp-browser-phone-container').removeClass('incoming-call'); $('.twp-browser-phone-container').removeClass('incoming-call');
// Reset control buttons // Reset control buttons
console.log('endCall() called - resetting hold button from:', $('#twp-hold-btn').text());
$('#twp-hold-btn').text('Hold').removeClass('btn-active'); $('#twp-hold-btn').text('Hold').removeClass('btn-active');
$('#twp-record-btn').text('Record').removeClass('btn-active'); $('#twp-record-btn').text('Record').removeClass('btn-active');
@@ -1559,6 +1560,10 @@
const $holdBtn = $('#twp-hold-btn'); const $holdBtn = $('#twp-hold-btn');
const currentHoldState = isOnHold; const currentHoldState = isOnHold;
console.log('Hold button element found:', $holdBtn.length);
console.log('Current hold state:', currentHoldState);
console.log('Current button text:', $holdBtn.text());
// Update button immediately for better UX // Update button immediately for better UX
if (currentHoldState) { if (currentHoldState) {
$holdBtn.text('Resuming...').prop('disabled', true); $holdBtn.text('Resuming...').prop('disabled', true);
@@ -1566,6 +1571,13 @@
$holdBtn.text('Holding...').prop('disabled', true); $holdBtn.text('Holding...').prop('disabled', true);
} }
console.log('Sending hold toggle request:', {
action: 'twp_toggle_hold',
call_sid: callSid,
hold: !currentHoldState,
nonce: twp_frontend_ajax.nonce
});
$.ajax({ $.ajax({
url: twp_frontend_ajax.ajax_url, url: twp_frontend_ajax.ajax_url,
method: 'POST', method: 'POST',
@@ -1585,13 +1597,20 @@
console.log('Hold state updated to:', isOnHold); console.log('Hold state updated to:', isOnHold);
if (isOnHold) { if (isOnHold) {
console.log('Setting button to Resume state...');
$holdBtn.text('Resume').addClass('btn-active').prop('disabled', false); $holdBtn.text('Resume').addClass('btn-active').prop('disabled', false);
console.log('Button after update - text:', $holdBtn.text(), 'classes:', $holdBtn.attr('class'));
showMessage('Call placed on hold - Click Resume to continue', 'info'); showMessage('Call placed on hold - Click Resume to continue', 'info');
console.log('Button updated to Resume state');
// Verify the button was actually updated
setTimeout(function() {
console.log('Button state after 100ms:', $holdBtn.text(), $holdBtn.hasClass('btn-active'));
}, 100);
} else { } else {
console.log('Setting button to Hold state...');
$holdBtn.text('Hold').removeClass('btn-active').prop('disabled', false); $holdBtn.text('Hold').removeClass('btn-active').prop('disabled', false);
console.log('Button after update - text:', $holdBtn.text(), 'classes:', $holdBtn.attr('class'));
showMessage('Call resumed', 'info'); showMessage('Call resumed', 'info');
console.log('Button updated to Hold state');
} }
} else { } else {
console.error('Hold toggle failed:', response); console.error('Hold toggle failed:', response);