Spaces:
Runtime error

Dhurgh commited on
Commit
4f7f881
Β·
1 Parent(s): 43c7d49

Fix calls fully: preserve early ICE, relay fallback, desktop call window UI (v2.8.1)

Browse files
Files changed (3) hide show
  1. client.js +51 -1
  2. index.html +50 -16
  3. package.json +1 -1
client.js CHANGED
@@ -31,6 +31,8 @@ let activeIceServers = [];
31
  let callIceFailureCount = 0;
32
  let forceRelayOnly = false;
33
  let pendingIceRecoveryTimer = null;
 
 
34
  let hasUserInteractedWithPage = false;
35
  let activeRoomSubscription = null;
36
  let roomMessages = JSON.parse(localStorage.getItem('roomMessages') || '{}');
@@ -2822,7 +2824,13 @@ async function flushQueuedIceCandidates() {
2822
  }
2823
 
2824
  async function addOrQueueIceCandidate(candidateData) {
2825
- if (!peerConnection || !candidateData) return;
 
 
 
 
 
 
2826
 
2827
  const candidate = new RTCIceCandidate(candidateData);
2828
  const hasRemoteDescription = Boolean(peerConnection.remoteDescription && peerConnection.remoteDescription.type);
@@ -6238,6 +6246,17 @@ function createPeerConnection(peerId) {
6238
  peerConnection.addTransceiver('video', { direction: 'recvonly' });
6239
  }
6240
 
 
 
 
 
 
 
 
 
 
 
 
6241
  peerConnection.onicecandidate = (event) => {
6242
  if (event.candidate && socket && socket.connected) {
6243
  socket.emit('video signal', {
@@ -6320,9 +6339,33 @@ function createPeerConnection(peerId) {
6320
  clearTimeout(pendingIceRecoveryTimer);
6321
  pendingIceRecoveryTimer = null;
6322
  }
 
 
 
 
6323
  return;
6324
  }
6325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6326
  if (peerConnection.iceConnectionState === 'disconnected') {
6327
  if (pendingIceRecoveryTimer) {
6328
  clearTimeout(pendingIceRecoveryTimer);
@@ -6392,6 +6435,7 @@ function openCallDialog(peerName) {
6392
  // Use the new full-screen call overlay instead of a custom dialog
6393
  const overlay = document.getElementById('callOverlay');
6394
  if (overlay) {
 
6395
  document.getElementById('callOverlayPeerName').textContent = `πŸ“ž ${peerName}`;
6396
  document.getElementById('callTimerLabel').textContent = '00:00:00';
6397
  const muteBtn = document.getElementById('muteBtn');
@@ -6415,6 +6459,7 @@ async function startCallSession(peerName, peerId, isCaller) {
6415
  currentCallPeerName = peerName;
6416
  callIceFailureCount = 0;
6417
  forceRelayOnly = rtcRuntimeConfig?.iceTransportPolicy === 'relay';
 
6418
 
6419
  openCallDialog(peerName);
6420
  // Start timer from session start to avoid "stuck at 00:00" perception on unstable networks.
@@ -6627,6 +6672,11 @@ function cleanupCallSession(keepDialogOpen = false) {
6627
  clearTimeout(pendingIceRecoveryTimer);
6628
  pendingIceRecoveryTimer = null;
6629
  }
 
 
 
 
 
6630
 
6631
  if (localCallStream) {
6632
  localCallStream.getTracks().forEach((track) => track.stop());
 
31
  let callIceFailureCount = 0;
32
  let forceRelayOnly = false;
33
  let pendingIceRecoveryTimer = null;
34
+ let pendingRelayFallbackTimer = null;
35
+ let pendingRemoteIceCandidates = [];
36
  let hasUserInteractedWithPage = false;
37
  let activeRoomSubscription = null;
38
  let roomMessages = JSON.parse(localStorage.getItem('roomMessages') || '{}');
 
2824
  }
2825
 
2826
  async function addOrQueueIceCandidate(candidateData) {
2827
+ if (!candidateData) return;
2828
+
2829
+ // Candidate can arrive before peerConnection exists; keep it for later.
2830
+ if (!peerConnection) {
2831
+ pendingRemoteIceCandidates.push(candidateData);
2832
+ return;
2833
+ }
2834
 
2835
  const candidate = new RTCIceCandidate(candidateData);
2836
  const hasRemoteDescription = Boolean(peerConnection.remoteDescription && peerConnection.remoteDescription.type);
 
6246
  peerConnection.addTransceiver('video', { direction: 'recvonly' });
6247
  }
6248
 
6249
+ // Apply candidates that arrived before peer connection was created.
6250
+ if (pendingRemoteIceCandidates.length) {
6251
+ const earlyCandidates = [...pendingRemoteIceCandidates];
6252
+ pendingRemoteIceCandidates = [];
6253
+ earlyCandidates.forEach((candidateData) => {
6254
+ addOrQueueIceCandidate(candidateData).catch((error) => {
6255
+ console.warn('Failed to apply early ICE candidate:', error);
6256
+ });
6257
+ });
6258
+ }
6259
+
6260
  peerConnection.onicecandidate = (event) => {
6261
  if (event.candidate && socket && socket.connected) {
6262
  socket.emit('video signal', {
 
6339
  clearTimeout(pendingIceRecoveryTimer);
6340
  pendingIceRecoveryTimer = null;
6341
  }
6342
+ if (pendingRelayFallbackTimer) {
6343
+ clearTimeout(pendingRelayFallbackTimer);
6344
+ pendingRelayFallbackTimer = null;
6345
+ }
6346
  return;
6347
  }
6348
 
6349
+ if (peerConnection.iceConnectionState === 'checking' && forceRelayOnly && !pendingRelayFallbackTimer) {
6350
+ // If relay-only stalls, fall back to mixed ICE so STUN/P2P can connect.
6351
+ pendingRelayFallbackTimer = setTimeout(() => {
6352
+ pendingRelayFallbackTimer = null;
6353
+ if (!peerConnection) return;
6354
+ if (peerConnection.iceConnectionState !== 'checking') return;
6355
+ try {
6356
+ forceRelayOnly = false;
6357
+ peerConnection.setConfiguration({
6358
+ iceServers: activeIceServers,
6359
+ iceTransportPolicy: 'all'
6360
+ });
6361
+ showToast('Retrying call with mixed network mode...', 'warning');
6362
+ attemptIceRecovery(peerId);
6363
+ } catch (fallbackError) {
6364
+ console.warn('Relay fallback failed:', fallbackError);
6365
+ }
6366
+ }, 10000);
6367
+ }
6368
+
6369
  if (peerConnection.iceConnectionState === 'disconnected') {
6370
  if (pendingIceRecoveryTimer) {
6371
  clearTimeout(pendingIceRecoveryTimer);
 
6435
  // Use the new full-screen call overlay instead of a custom dialog
6436
  const overlay = document.getElementById('callOverlay');
6437
  if (overlay) {
6438
+ overlay.classList.toggle('desktop-window', window.innerWidth > 700);
6439
  document.getElementById('callOverlayPeerName').textContent = `πŸ“ž ${peerName}`;
6440
  document.getElementById('callTimerLabel').textContent = '00:00:00';
6441
  const muteBtn = document.getElementById('muteBtn');
 
6459
  currentCallPeerName = peerName;
6460
  callIceFailureCount = 0;
6461
  forceRelayOnly = rtcRuntimeConfig?.iceTransportPolicy === 'relay';
6462
+ pendingRemoteIceCandidates = [];
6463
 
6464
  openCallDialog(peerName);
6465
  // Start timer from session start to avoid "stuck at 00:00" perception on unstable networks.
 
6672
  clearTimeout(pendingIceRecoveryTimer);
6673
  pendingIceRecoveryTimer = null;
6674
  }
6675
+ if (pendingRelayFallbackTimer) {
6676
+ clearTimeout(pendingRelayFallbackTimer);
6677
+ pendingRelayFallbackTimer = null;
6678
+ }
6679
+ pendingRemoteIceCandidates = [];
6680
 
6681
  if (localCallStream) {
6682
  localCallStream.getTracks().forEach((track) => track.stop());
index.html CHANGED
@@ -941,10 +941,30 @@
941
  z-index: 9999; /* Ensure it's on top of everything */
942
  display: none;
943
  touch-action: manipulation; /* Prevents double-tap zoom delay */
 
944
  }
945
  #callOverlay.active {
946
  display: flex;
947
- flex-direction: column;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
948
  }
949
  #remoteCallVideo, #localCallVideo, #localCallVideoOld {
950
  display: block;
@@ -1008,6 +1028,18 @@
1008
  -webkit-tap-highlight-color: transparent;
1009
  }
1010
  .call-end-btn:hover { background: #c0392b; transform: scale(1.1); }
 
 
 
 
 
 
 
 
 
 
 
 
1011
  #callDebugPanel {
1012
  position: absolute;
1013
  top: 80px; right: 10px;
@@ -3066,7 +3098,7 @@
3066
  <div class="chat-header-title" id="chatTitle">πŸ’¬ Select a friend to chat</div>
3067
  </div>
3068
  <div class="chat-header-actions">
3069
- <span class="build-badge mobile-essential" id="buildVersionBadge" title="Frontend build version">v2.8.0</span>
3070
  <button class="header-btn mobile-essential" onclick="toggleArchiveChat()" title="Archive chat">
3071
  <i class="fas fa-archive"></i>
3072
  </button>
@@ -3647,23 +3679,25 @@
3647
 
3648
  <!-- ========== FULL-SCREEN CALL OVERLAY ========== -->
3649
  <div id="callOverlay">
3650
- <video id="remoteCallVideo" autoplay playsinline style="position:absolute; inset:0; width:100%; height:100%; object-fit:cover; z-index:0;"></video>
3651
- <video id="localCallVideo" autoplay muted playsinline style="position:absolute; bottom:110px; right:14px; width:110px; height:150px; border-radius:12px; border:2px solid rgba(255,255,255,0.6); object-fit:cover; z-index:2;"></video>
 
3652
 
3653
- <div class="call-overlay-header">
3654
- <div>
3655
- <div id="callOverlayPeerName" style="color:#fff; font-size:18px; font-weight:700;"></div>
3656
- <div id="callTimerLabel" style="color:rgba(255,255,255,0.7); font-size:13px; margin-top:4px;">00:00:00</div>
 
 
3657
  </div>
3658
- <button onclick="toggleCallDebug()" style="background:rgba(255,255,255,0.18); border:none; color:white; padding:7px 13px; border-radius:8px; cursor:pointer; font-size:12px; font-weight:600;">πŸ”§ Debug</button>
3659
- </div>
3660
 
3661
- <div id="callDebugPanel"></div>
3662
 
3663
- <div class="call-overlay-controls">
3664
- <button id="muteBtn" class="call-ctrl-btn" onclick="toggleLocalMute()" title="Mute/Unmute">🎀</button>
3665
- <button id="cameraBtn" class="call-ctrl-btn" onclick="toggleCallCamera()" title="Camera on/off">πŸ“·</button>
3666
- <button class="call-end-btn" onclick="endVideoCall()" title="End Call">πŸ“΅</button>
 
3667
  </div>
3668
  </div>
3669
 
@@ -3683,7 +3717,7 @@
3683
 
3684
  <script src="/socket.io/socket.io.js"></script>
3685
  <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
3686
- <script src="client.js?v=2.8.0"></script>
3687
  </body>
3688
  </html>
3689
 
 
941
  z-index: 9999; /* Ensure it's on top of everything */
942
  display: none;
943
  touch-action: manipulation; /* Prevents double-tap zoom delay */
944
+ background: rgba(0,0,0,0.55);
945
  }
946
  #callOverlay.active {
947
  display: flex;
948
+ align-items: center;
949
+ justify-content: center;
950
+ padding: 16px;
951
+ }
952
+ .call-overlay-stage {
953
+ position: relative;
954
+ width: min(920px, 100%);
955
+ height: min(84vh, 720px);
956
+ border-radius: 18px;
957
+ overflow: hidden;
958
+ background: #0f1116;
959
+ box-shadow: 0 28px 80px rgba(0,0,0,0.55);
960
+ border: 1px solid rgba(255,255,255,0.12);
961
+ }
962
+ #callOverlay:not(.desktop-window) .call-overlay-stage {
963
+ width: 100%;
964
+ height: 100%;
965
+ border-radius: 0;
966
+ border: none;
967
+ box-shadow: none;
968
  }
969
  #remoteCallVideo, #localCallVideo, #localCallVideoOld {
970
  display: block;
 
1028
  -webkit-tap-highlight-color: transparent;
1029
  }
1030
  .call-end-btn:hover { background: #c0392b; transform: scale(1.1); }
1031
+ @media (max-width: 700px) {
1032
+ #callOverlay.active {
1033
+ padding: 0;
1034
+ }
1035
+ .call-overlay-stage {
1036
+ width: 100%;
1037
+ height: 100%;
1038
+ border-radius: 0;
1039
+ border: none;
1040
+ box-shadow: none;
1041
+ }
1042
+ }
1043
  #callDebugPanel {
1044
  position: absolute;
1045
  top: 80px; right: 10px;
 
3098
  <div class="chat-header-title" id="chatTitle">πŸ’¬ Select a friend to chat</div>
3099
  </div>
3100
  <div class="chat-header-actions">
3101
+ <span class="build-badge mobile-essential" id="buildVersionBadge" title="Frontend build version">v2.8.1</span>
3102
  <button class="header-btn mobile-essential" onclick="toggleArchiveChat()" title="Archive chat">
3103
  <i class="fas fa-archive"></i>
3104
  </button>
 
3679
 
3680
  <!-- ========== FULL-SCREEN CALL OVERLAY ========== -->
3681
  <div id="callOverlay">
3682
+ <div class="call-overlay-stage">
3683
+ <video id="remoteCallVideo" autoplay playsinline style="position:absolute; inset:0; width:100%; height:100%; object-fit:cover; z-index:0;"></video>
3684
+ <video id="localCallVideo" autoplay muted playsinline style="position:absolute; bottom:110px; right:14px; width:110px; height:150px; border-radius:12px; border:2px solid rgba(255,255,255,0.6); object-fit:cover; z-index:2;"></video>
3685
 
3686
+ <div class="call-overlay-header">
3687
+ <div>
3688
+ <div id="callOverlayPeerName" style="color:#fff; font-size:18px; font-weight:700;"></div>
3689
+ <div id="callTimerLabel" style="color:rgba(255,255,255,0.7); font-size:13px; margin-top:4px;">00:00:00</div>
3690
+ </div>
3691
+ <button onclick="toggleCallDebug()" style="background:rgba(255,255,255,0.18); border:none; color:white; padding:7px 13px; border-radius:8px; cursor:pointer; font-size:12px; font-weight:600;">πŸ”§ Debug</button>
3692
  </div>
 
 
3693
 
3694
+ <div id="callDebugPanel"></div>
3695
 
3696
+ <div class="call-overlay-controls">
3697
+ <button id="muteBtn" class="call-ctrl-btn" onclick="toggleLocalMute()" title="Mute/Unmute">🎀</button>
3698
+ <button id="cameraBtn" class="call-ctrl-btn" onclick="toggleCallCamera()" title="Camera on/off">πŸ“·</button>
3699
+ <button class="call-end-btn" onclick="endVideoCall()" title="End Call">πŸ“΅</button>
3700
+ </div>
3701
  </div>
3702
  </div>
3703
 
 
3717
 
3718
  <script src="/socket.io/socket.io.js"></script>
3719
  <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
3720
+ <script src="client.js?v=2.8.1"></script>
3721
  </body>
3722
  </html>
3723
 
package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "discord-like-app",
3
- "version": "2.8.0",
4
  "main": "server.js",
5
  "scripts": {
6
  "dev": "nodemon server.js",
 
1
  {
2
  "name": "discord-like-app",
3
+ "version": "2.8.1",
4
  "main": "server.js",
5
  "scripts": {
6
  "dev": "nodemon server.js",