@colyseus/sdk 0.17.13 → 0.17.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/build/3rd_party/discord.cjs +1 -1
  2. package/build/3rd_party/discord.mjs +1 -1
  3. package/build/Auth.cjs +1 -1
  4. package/build/Auth.mjs +1 -1
  5. package/build/Client.cjs +3 -2
  6. package/build/Client.cjs.map +1 -1
  7. package/build/Client.d.ts +1 -1
  8. package/build/Client.mjs +3 -2
  9. package/build/Client.mjs.map +1 -1
  10. package/build/Connection.cjs +30 -1
  11. package/build/Connection.cjs.map +1 -1
  12. package/build/Connection.d.ts +1 -0
  13. package/build/Connection.mjs +27 -1
  14. package/build/Connection.mjs.map +1 -1
  15. package/build/HTTP.cjs +1 -1
  16. package/build/HTTP.mjs +1 -1
  17. package/build/Protocol.cjs +1 -1
  18. package/build/Protocol.mjs +1 -1
  19. package/build/Room.cjs +17 -14
  20. package/build/Room.cjs.map +1 -1
  21. package/build/Room.mjs +12 -9
  22. package/build/Room.mjs.map +1 -1
  23. package/build/Storage.cjs +1 -1
  24. package/build/Storage.mjs +1 -1
  25. package/build/core/nanoevents.cjs +1 -1
  26. package/build/core/nanoevents.mjs +1 -1
  27. package/build/core/signal.cjs +1 -1
  28. package/build/core/signal.mjs +1 -1
  29. package/build/core/utils.cjs +1 -1
  30. package/build/core/utils.mjs +1 -1
  31. package/build/debug.cjs +226 -113
  32. package/build/debug.cjs.map +1 -1
  33. package/build/debug.mjs +226 -113
  34. package/build/debug.mjs.map +1 -1
  35. package/build/errors/Errors.cjs +1 -12
  36. package/build/errors/Errors.cjs.map +1 -1
  37. package/build/errors/Errors.d.ts +0 -10
  38. package/build/errors/Errors.mjs +2 -13
  39. package/build/errors/Errors.mjs.map +1 -1
  40. package/build/index.cjs +11 -11
  41. package/build/index.cjs.map +1 -1
  42. package/build/index.d.ts +2 -2
  43. package/build/index.mjs +3 -3
  44. package/build/index.mjs.map +1 -1
  45. package/build/legacy.cjs +1 -1
  46. package/build/legacy.mjs +1 -1
  47. package/build/serializer/NoneSerializer.cjs +1 -1
  48. package/build/serializer/NoneSerializer.mjs +1 -1
  49. package/build/serializer/SchemaSerializer.cjs +1 -1
  50. package/build/serializer/SchemaSerializer.mjs +1 -1
  51. package/build/serializer/Serializer.cjs +1 -1
  52. package/build/serializer/Serializer.mjs +1 -1
  53. package/build/transport/H3Transport.cjs +1 -1
  54. package/build/transport/H3Transport.mjs +1 -1
  55. package/build/transport/WebSocketTransport.cjs +16 -5
  56. package/build/transport/WebSocketTransport.cjs.map +1 -1
  57. package/build/transport/WebSocketTransport.mjs +16 -5
  58. package/build/transport/WebSocketTransport.mjs.map +1 -1
  59. package/dist/colyseus-cocos-creator.js +118 -49
  60. package/dist/colyseus-cocos-creator.js.map +1 -1
  61. package/dist/colyseus.js +118 -49
  62. package/dist/colyseus.js.map +1 -1
  63. package/dist/debug.js +284 -143
  64. package/dist/debug.js.map +1 -1
  65. package/package.json +4 -4
  66. package/src/Client.ts +2 -2
  67. package/src/Connection.ts +30 -0
  68. package/src/Room.ts +13 -10
  69. package/src/debug.ts +246 -111
  70. package/src/errors/Errors.ts +0 -11
  71. package/src/index.ts +2 -2
  72. package/src/transport/WebSocketTransport.ts +16 -4
package/build/debug.cjs CHANGED
@@ -3,10 +3,11 @@
3
3
  // This software is released under the MIT License.
4
4
  // https://opensource.org/license/MIT
5
5
  //
6
- // colyseus.js@0.17.13
6
+ // colyseus.js@0.17.15
7
7
  'use strict';
8
8
 
9
9
  var Client = require('./Client.cjs');
10
+ var sharedTypes = require('@colyseus/shared-types');
10
11
 
11
12
  const logoIcon = `<svg viewBox="0 0 488.94 541.2" style="width: 100%; height: 100%;">
12
13
  <g>
@@ -25,6 +26,7 @@ const infoIcon = `<svg stroke="currentColor" fill="currentColor" stroke-width="0
25
26
  const settingsIcon = `<svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" height="200px" width="200px" xmlns="http://www.w3.org/2000/svg"><path d="M12.003 21c-.732 .001 -1.465 -.438 -1.678 -1.317a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c.886 .215 1.325 .957 1.318 1.694"></path><path d="M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"></path><path d="M19.001 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"></path><path d="M19.001 15.5v1.5"></path><path d="M19.001 21v1.5"></path><path d="M22.032 17.25l-1.299 .75"></path><path d="M17.27 20l-1.3 .75"></path><path d="M15.97 17.25l1.3 .75"></path><path d="M20.733 20l1.3 .75"></path></svg>`;
26
27
  const eyeSlashIcon = `<svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>`;
27
28
  const closeIcon = `<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="M400 145.49 366.51 112 256 222.51 145.49 112 112 145.49 222.51 256 112 366.51 145.49 400 256 289.49 366.51 400 400 366.51 289.49 256 400 145.49z"></path></svg>`;
29
+ const disconnectIcon = `<svg fill="currentColor" viewBox="0 0 36 36" height="200px" width="200px"><path fill="currentColor" d="M18 24.42a4 4 0 1 0 4 4a4 4 0 0 0-4-4m0 6a2 2 0 1 1 2-2a2 2 0 0 1-2 2" class="clr-i-outline clr-i-outline-path-1"></path><path fill="currentColor" d="M26.21 21.85a1 1 0 0 0-.23-1.4a13.6 13.6 0 0 0-5-2.23l3.87 3.87a1 1 0 0 0 1.36-.24" class="clr-i-outline clr-i-outline-path-2"></path><path fill="currentColor" d="M18.05 10.72a21 21 0 0 0-4.16.43l1.74 1.74a19 19 0 0 1 2.42-.17A18.76 18.76 0 0 1 28.64 16a1 1 0 0 0 1.12-1.65a20.75 20.75 0 0 0-11.71-3.63" class="clr-i-outline clr-i-outline-path-3"></path><path fill="currentColor" d="M33.55 8.2A28.11 28.11 0 0 0 8.11 5.36l1.58 1.57a26 26 0 0 1 22.76 2.94a1 1 0 0 0 1.1-1.67" class="clr-i-outline clr-i-outline-path-4"></path><path fill="currentColor" d="m1.84 4.75l2.43 2.43c-.62.34-1.23.7-1.83 1.1a1 1 0 1 0 1.12 1.66C4.26 9.47 5 9 5.74 8.65l3.87 3.87a20.6 20.6 0 0 0-3.38 1.88A1 1 0 0 0 7.36 16a18.8 18.8 0 0 1 3.77-2l4.16 4.16A13.5 13.5 0 0 0 10 20.55a1 1 0 0 0 1.18 1.61A11.5 11.5 0 0 1 17 20l10.8 10.8l1.41-1.41l-26-26Z" class="clr-i-outline clr-i-outline-path-5"></path><path fill="none" d="M0 0h36v36H0z"></path></svg>`;
28
30
  // Store debug info per room
29
31
  const roomDebugInfo = new Map();
30
32
  // Single interval for all panels
@@ -1926,12 +1928,16 @@ function hidePanelsForSession() {
1926
1928
  }
1927
1929
  // Helper function to format bytes
1928
1930
  function formatBytes(bytes) {
1929
- if (bytes === 0)
1931
+ if (!bytes) {
1930
1932
  return '0 B';
1933
+ }
1934
+ else if (bytes < 1) {
1935
+ bytes = 1; // avoid visual glitches
1936
+ }
1931
1937
  var k = 1024;
1932
1938
  var sizes = ['B', 'KB', 'MB', 'GB'];
1933
1939
  var i = Math.floor(Math.log(bytes) / Math.log(k));
1934
- return (bytes / Math.pow(k, i)).toFixed(1) + ' ' + sizes[i];
1940
+ return (Math.round(bytes) / Math.pow(k, i)).toFixed(1) + ' ' + sizes[i];
1935
1941
  }
1936
1942
  // Helper function to create debug panel for a room
1937
1943
  function createDebugPanel(uniquePanelId, debugInfo) {
@@ -1963,15 +1969,16 @@ function createDebugPanel(uniquePanelId, debugInfo) {
1963
1969
  title.style.paddingBottom = '4px';
1964
1970
  title.style.display = 'flex';
1965
1971
  title.style.alignItems = 'center';
1966
- title.style.gap = '4px';
1972
+ title.style.justifyContent = 'space-between';
1973
+ title.style.gap = '8px';
1967
1974
  title.style.position = 'relative';
1968
- title.innerHTML = '<span style="display: inline-flex; align-items: center;"></span><span id="debug-title-text-' + uniquePanelId + '"></span><span id="debug-message-icon-' + uniquePanelId + '" style="display: none; align-items: center; margin-left: auto; cursor: pointer; opacity: 0.6; transition: opacity 0.2s; margin-right: 4px; width: 16px; height: 16px;">' + messageIcon.replace('height="200px" width="200px"', 'height="16" width="16"') + '</span><span id="debug-hamburger-icon-' + uniquePanelId + '" style="display: inline-flex; align-items: center; cursor: pointer; opacity: 0.6; transition: opacity 0.2s; margin-right: 4px; width: 16px; height: 16px;">' + treeViewIcon.replace('height="200px" width="200px"', 'height="16" width="16"') + '</span><span id="debug-info-icon-' + uniquePanelId + '" style="display: inline-flex; align-items: center; cursor: pointer; opacity: 0.6; transition: opacity 0.2s; width: 16px; height: 16px;">' + infoIcon + '</span>';
1969
- // Create tooltip for info icon
1975
+ title.innerHTML = '<span id="debug-title-text-' + uniquePanelId + '"><span class="debug-room-name"></span><span class="debug-info-icon" style="display: inline-flex; align-items: center; margin-left: 4px; cursor: pointer; opacity: 0.6; vertical-align: middle;">' + infoIcon.replace('height="200px" width="200px"', 'height="10" width="10"') + '</span></span><span id="debug-ping-' + uniquePanelId + '" style="font-size: 10px; font-weight: normal; color: #888;" title="Ping time">--</span>';
1976
+ // Create tooltip for info button (will be shown on hover)
1970
1977
  var tooltip = document.createElement('div');
1971
1978
  tooltip.id = 'debug-tooltip-' + uniquePanelId;
1972
1979
  tooltip.style.position = 'absolute';
1973
1980
  tooltip.style.top = '100%';
1974
- tooltip.style.right = '0';
1981
+ tooltip.style.left = '0';
1975
1982
  tooltip.style.marginTop = '4px';
1976
1983
  tooltip.style.padding = '6px 8px';
1977
1984
  tooltip.style.backgroundColor = 'rgba(0, 0, 0, 0.95)';
@@ -1983,60 +1990,149 @@ function createDebugPanel(uniquePanelId, debugInfo) {
1983
1990
  tooltip.style.display = 'none';
1984
1991
  tooltip.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.5)';
1985
1992
  tooltip.style.lineHeight = '1.4';
1986
- tooltip.innerHTML = '<div><strong>Room ID:</strong> ' + debugInfo.roomId + '</div><div><strong>Session ID:</strong> N/A</div><div><strong>Host:</strong> N/A</div>';
1987
- title.appendChild(tooltip);
1988
- // Add hover handlers - use a small delay to ensure element exists
1989
- setTimeout(function () {
1990
- var infoIconElement = document.getElementById('debug-info-icon-' + uniquePanelId);
1991
- if (infoIconElement) {
1992
- var showTooltip = function () {
1993
- tooltip.style.display = 'block';
1994
- infoIconElement.style.opacity = '1';
1995
- };
1996
- var hideTooltip = function () {
1997
- tooltip.style.display = 'none';
1998
- infoIconElement.style.opacity = '0.6';
1999
- };
2000
- infoIconElement.addEventListener('mouseenter', showTooltip);
2001
- infoIconElement.addEventListener('mouseleave', hideTooltip);
2002
- // Also handle tooltip hover to keep it visible
2003
- tooltip.style.pointerEvents = 'auto';
2004
- tooltip.addEventListener('mouseenter', showTooltip);
2005
- tooltip.addEventListener('mouseleave', hideTooltip);
2006
- }
2007
- // Add click handler for hamburger icon
2008
- var hamburgerIconElement = document.getElementById('debug-hamburger-icon-' + uniquePanelId);
2009
- if (hamburgerIconElement) {
2010
- hamburgerIconElement.addEventListener('mouseenter', function () {
2011
- hamburgerIconElement.style.opacity = '1';
2012
- });
2013
- hamburgerIconElement.addEventListener('mouseleave', function () {
2014
- hamburgerIconElement.style.opacity = '0.6';
2015
- });
2016
- hamburgerIconElement.addEventListener('click', function (e) {
2017
- e.stopPropagation();
2018
- openStateInspectorModal(uniquePanelId);
2019
- });
2020
- }
2021
- // Add click handler for message icon
2022
- var messageIconElement = document.getElementById('debug-message-icon-' + uniquePanelId);
2023
- if (messageIconElement) {
2024
- messageIconElement.addEventListener('mouseenter', function () {
2025
- messageIconElement.style.opacity = '1';
2026
- });
2027
- messageIconElement.addEventListener('mouseleave', function () {
2028
- messageIconElement.style.opacity = '0.6';
2029
- });
2030
- messageIconElement.addEventListener('click', function (e) {
2031
- e.stopPropagation();
2032
- openSendMessagesModal(uniquePanelId);
2033
- });
2034
- }
2035
- }, 0);
1993
+ tooltip.innerHTML = '<div><strong>Room ID:</strong> ' + debugInfo.roomId + '</div><div><strong>Session ID:</strong> N/A</div>';
2036
1994
  var content = document.createElement('div');
2037
1995
  content.id = 'debug-content-' + uniquePanelId;
1996
+ // Create action buttons container at the bottom
1997
+ var actionsContainer = document.createElement('div');
1998
+ actionsContainer.id = 'debug-actions-' + uniquePanelId;
1999
+ actionsContainer.style.display = 'flex';
2000
+ actionsContainer.style.gap = '4px';
2001
+ actionsContainer.style.marginTop = '8px';
2002
+ actionsContainer.style.paddingTop = '6px';
2003
+ actionsContainer.style.borderTop = '1px solid rgba(255, 255, 255, 0.15)';
2004
+ actionsContainer.style.position = 'relative';
2005
+ // Helper function to create action button
2006
+ function createActionButton(id, icon, label, onClick) {
2007
+ var btn = document.createElement('button');
2008
+ btn.id = id;
2009
+ btn.style.display = 'flex';
2010
+ btn.style.alignItems = 'center';
2011
+ btn.style.gap = '4px';
2012
+ btn.style.padding = '4px 8px';
2013
+ btn.style.border = '1px solid rgba(255, 255, 255, 0.2)';
2014
+ btn.style.borderRadius = '4px';
2015
+ btn.style.background = 'rgba(255, 255, 255, 0.05)';
2016
+ btn.style.color = '#fff';
2017
+ btn.style.fontSize = '9px';
2018
+ btn.style.cursor = 'pointer';
2019
+ btn.style.transition = 'background 0.2s, border-color 0.2s';
2020
+ btn.innerHTML = '<span style="display: inline-flex; align-items: center; width: 12px; height: 12px;">' + icon + '</span><span>' + label + '</span>';
2021
+ btn.addEventListener('mouseenter', function () {
2022
+ btn.style.background = 'rgba(255, 255, 255, 0.15)';
2023
+ btn.style.borderColor = 'rgba(255, 255, 255, 0.3)';
2024
+ });
2025
+ btn.addEventListener('mouseleave', function () {
2026
+ btn.style.background = 'rgba(255, 255, 255, 0.05)';
2027
+ btn.style.borderColor = 'rgba(255, 255, 255, 0.2)';
2028
+ });
2029
+ btn.addEventListener('click', function (e) {
2030
+ e.stopPropagation();
2031
+ onClick();
2032
+ });
2033
+ return btn;
2034
+ }
2035
+ // Create action buttons
2036
+ var stateBtn = createActionButton('debug-state-btn-' + uniquePanelId, treeViewIcon.replace('height="200px" width="200px"', 'height="12" width="12"'), 'State', function () { openStateInspectorModal(uniquePanelId); });
2037
+ var messageBtn = createActionButton('debug-message-btn-' + uniquePanelId, messageIcon.replace('height="200px" width="200px"', 'height="12" width="12"'), 'Send', function () { openSendMessagesModal(uniquePanelId); });
2038
+ messageBtn.style.display = 'none'; // Hidden by default, shown when message types available
2039
+ // Create disconnect button (red, simulates abnormal websocket close)
2040
+ var disconnectBtn = createActionButton('debug-disconnect-btn-' + uniquePanelId, disconnectIcon.replace('height="200px" width="200px"', 'height="12" width="12"'), 'Drop', function () {
2041
+ var info = roomDebugInfo.get(uniquePanelId);
2042
+ if (info && info.room && info.room.connection) {
2043
+ // Simulate connection closure
2044
+ info.room.connection.close(sharedTypes.CloseCode.MAY_TRY_RECONNECT);
2045
+ }
2046
+ });
2047
+ // Track button state for hover effects
2048
+ var isReconnecting = false;
2049
+ // Helper to apply normal (red) button style
2050
+ function applyNormalStyle() {
2051
+ disconnectBtn.style.background = 'rgba(239, 68, 68, 0.2)';
2052
+ disconnectBtn.style.borderColor = 'rgba(239, 68, 68, 0.5)';
2053
+ disconnectBtn.style.color = '#ef4444';
2054
+ disconnectBtn.style.animation = '';
2055
+ disconnectBtn.style.pointerEvents = 'auto';
2056
+ disconnectBtn.style.opacity = '1';
2057
+ var labelSpan = disconnectBtn.querySelector('span:last-child');
2058
+ if (labelSpan)
2059
+ labelSpan.textContent = 'Drop';
2060
+ }
2061
+ // Helper to apply reconnecting (orange/pulsing) button style
2062
+ function applyReconnectingStyle() {
2063
+ disconnectBtn.style.background = 'rgba(251, 146, 60, 0.3)';
2064
+ disconnectBtn.style.borderColor = 'rgba(251, 146, 60, 0.6)';
2065
+ disconnectBtn.style.color = '#fb923c';
2066
+ disconnectBtn.style.animation = 'debug-pulse 1.5s ease-in-out infinite';
2067
+ disconnectBtn.style.pointerEvents = 'none';
2068
+ disconnectBtn.style.opacity = '0.8';
2069
+ var labelSpan = disconnectBtn.querySelector('span:last-child');
2070
+ if (labelSpan)
2071
+ labelSpan.textContent = 'Reconnecting...';
2072
+ }
2073
+ // Inject CSS animation if not already present
2074
+ if (!document.getElementById('debug-pulse-animation')) {
2075
+ var style = document.createElement('style');
2076
+ style.id = 'debug-pulse-animation';
2077
+ style.textContent = '@keyframes debug-pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }';
2078
+ document.head.appendChild(style);
2079
+ }
2080
+ // Apply initial style
2081
+ applyNormalStyle();
2082
+ // Register onDrop callback to show reconnecting state
2083
+ if (debugInfo.room) {
2084
+ debugInfo.room.onDrop(function () {
2085
+ isReconnecting = true;
2086
+ applyReconnectingStyle();
2087
+ });
2088
+ // Register onReconnect callback to restore normal state
2089
+ debugInfo.room.onReconnect(function () {
2090
+ isReconnecting = false;
2091
+ applyNormalStyle();
2092
+ });
2093
+ }
2094
+ // Hover effects (only when not reconnecting)
2095
+ disconnectBtn.addEventListener('mouseenter', function () {
2096
+ if (!isReconnecting) {
2097
+ disconnectBtn.style.background = 'rgba(239, 68, 68, 0.35)';
2098
+ disconnectBtn.style.borderColor = 'rgba(239, 68, 68, 0.7)';
2099
+ }
2100
+ });
2101
+ disconnectBtn.addEventListener('mouseleave', function () {
2102
+ if (!isReconnecting) {
2103
+ disconnectBtn.style.background = 'rgba(239, 68, 68, 0.2)';
2104
+ disconnectBtn.style.borderColor = 'rgba(239, 68, 68, 0.5)';
2105
+ }
2106
+ });
2107
+ // Add tooltip hover handlers to info icon in title
2108
+ title.appendChild(tooltip);
2109
+ var infoIconEl = title.querySelector('.debug-info-icon');
2110
+ var tooltipTimeout = null;
2111
+ var showTooltip = function () {
2112
+ if (tooltipTimeout) {
2113
+ clearTimeout(tooltipTimeout);
2114
+ tooltipTimeout = null;
2115
+ }
2116
+ tooltip.style.display = 'block';
2117
+ };
2118
+ var hideTooltip = function () {
2119
+ tooltipTimeout = setTimeout(function () {
2120
+ tooltip.style.display = 'none';
2121
+ }, 100);
2122
+ };
2123
+ if (infoIconEl) {
2124
+ infoIconEl.addEventListener('mouseenter', showTooltip);
2125
+ infoIconEl.addEventListener('mouseleave', hideTooltip);
2126
+ }
2127
+ tooltip.style.pointerEvents = 'auto';
2128
+ tooltip.addEventListener('mouseenter', showTooltip);
2129
+ tooltip.addEventListener('mouseleave', hideTooltip);
2130
+ actionsContainer.appendChild(stateBtn);
2131
+ actionsContainer.appendChild(messageBtn);
2132
+ actionsContainer.appendChild(disconnectBtn);
2038
2133
  panel.appendChild(title);
2039
2134
  panel.appendChild(content);
2135
+ panel.appendChild(actionsContainer);
2040
2136
  // Prepend panel to body so new panels appear first
2041
2137
  if (document.body.firstChild) {
2042
2138
  document.body.insertBefore(panel, document.body.firstChild);
@@ -2111,16 +2207,27 @@ function updateDebugPanel(uniquePanelId, debugInfo) {
2111
2207
  title = document.getElementById(titleId);
2112
2208
  }
2113
2209
  }
2114
- // Update title with room name only (roomId, sessionId, and Host are in tooltip)
2115
- document.getElementById('debug-title-text-' + uniquePanelId).textContent = debugInfo.roomName;
2116
- document.getElementById('debug-tooltip-' + uniquePanelId).innerHTML = '<div><strong>Room ID:</strong> ' + debugInfo.roomId + '</div><div><strong>Session ID:</strong> ' + debugInfo.sessionId + '</div><div><strong>Host:</strong> ' + debugInfo.host + '</div>';
2210
+ // Update title with room name only (roomId and sessionId are in tooltip)
2211
+ var titleTextEl = document.getElementById('debug-title-text-' + uniquePanelId);
2212
+ var roomNameEl = titleTextEl === null || titleTextEl === void 0 ? void 0 : titleTextEl.querySelector('.debug-room-name');
2213
+ if (roomNameEl)
2214
+ roomNameEl.textContent = debugInfo.roomName;
2215
+ document.getElementById('debug-tooltip-' + uniquePanelId).innerHTML = '<div><strong>Room ID:</strong> ' + debugInfo.roomId + '</div><div><strong>Session ID:</strong> ' + debugInfo.sessionId + '</div>';
2216
+ // Update ping in header
2217
+ var pingDisplay = debugInfo.pingMs !== null ? debugInfo.pingMs + 'ms' : '--';
2218
+ var pingColor = debugInfo.pingMs !== null ? (debugInfo.pingMs < 100 ? '#22c55e' : debugInfo.pingMs < 200 ? '#eab308' : '#ef4444') : '#888';
2219
+ var pingElement = document.getElementById('debug-ping-' + uniquePanelId);
2220
+ if (pingElement) {
2221
+ pingElement.textContent = pingDisplay;
2222
+ pingElement.style.color = pingColor;
2223
+ }
2117
2224
  var html = '<div style="line-height: 1.3;">';
2118
2225
  html += '<div style="font-size: 10px; display: flex; gap: 8px;">';
2119
2226
  html += '<div style="flex: 1;">';
2120
2227
  html += '<div style="margin-bottom: 4px;"><div style="display: flex; align-items: center; gap: 6px;"><span style="display: inline-flex; align-items: center; width: 18px; height: 18px; color: #FF9800;">' + envelopeUp + '</span><span style="color: #FF9800;">' + formatBytes(debugInfo.bytesSentPerSec) + '/s</span></div><div style="margin-left: 24px; opacity: 0.7; font-size: 9px;">' + debugInfo.messagesSentPerSec.toFixed(0) + ' messages</div></div>';
2121
2228
  html += '<div><div style="display: flex; align-items: center; gap: 6px;"><span style="display: inline-flex; align-items: center; width: 18px; height: 18px; color: #2196F3;">' + envelopeDown + '</span><span style="color: #2196F3;">' + formatBytes(debugInfo.bytesReceivedPerSec) + '/s</span></div><div style="margin-left: 24px; opacity: 0.7; font-size: 9px;">' + debugInfo.messagesReceivedPerSec.toFixed(0) + ' messages</div></div>';
2122
2229
  html += '</div>';
2123
- html += '<div style="display: flex; flex-direction: column; gap: 4px;">';
2230
+ html += '<div style="display: flex; flex-direction: column; gap: 4px; align-items: flex-end;">';
2124
2231
  html += '<canvas id="graph-sent-' + uniquePanelId + '" width="80" height="30" style="display: block;"></canvas>';
2125
2232
  html += '<canvas id="graph-received-' + uniquePanelId + '" width="80" height="30" style="display: block;"></canvas>';
2126
2233
  html += '</div>';
@@ -2277,16 +2384,28 @@ function applyMonkeyPatches() {
2277
2384
  bytesReceivedHistory: [],
2278
2385
  // historyTimestamps: [],
2279
2386
  maxHistoryLength: 60, // Keep last 60 data points (1 minute at 1 second intervals)
2280
- messageTypes: null // Will store message types from __playground_message_types
2387
+ messageTypes: null, // Will store message types from __playground_message_types
2388
+ pingMs: null, // Current ping value in milliseconds
2389
+ pingInterval: null // Interval for pinging the room
2281
2390
  };
2282
2391
  roomDebugInfo.set(uniquePanelId, debugInfo);
2392
+ // Start ping interval (every 2 seconds)
2393
+ debugInfo.pingInterval = setInterval(() => {
2394
+ room.ping((ms) => {
2395
+ debugInfo.pingMs = ms;
2396
+ });
2397
+ }, 2000);
2398
+ // Initial ping
2399
+ room.ping((ms) => {
2400
+ debugInfo.pingMs = ms;
2401
+ });
2283
2402
  // Listen for __playground_message_types message
2284
2403
  room.onMessage('__playground_message_types', (messageTypes) => {
2285
2404
  debugInfo.messageTypes = messageTypes;
2286
- // Show/hide message icon based on message types availability
2287
- var messageIconElement = document.getElementById('debug-message-icon-' + uniquePanelId);
2288
- if (messageIconElement) {
2289
- messageIconElement.style.display = messageTypes ? 'inline-flex' : 'none';
2405
+ // Show/hide message button based on message types availability
2406
+ var messageBtnElement = document.getElementById('debug-message-btn-' + uniquePanelId);
2407
+ if (messageBtnElement) {
2408
+ messageBtnElement.style.display = messageTypes ? 'flex' : 'none';
2290
2409
  }
2291
2410
  });
2292
2411
  // Helper function to track received message/bytes
@@ -2334,41 +2453,38 @@ function applyMonkeyPatches() {
2334
2453
  debugInfo.bytesSent += data.length;
2335
2454
  debugInfo.bytesSentDelta += data.length;
2336
2455
  }
2337
- // Monkey-patch: WebSocket transport
2338
- if (transport.ws) {
2339
- const originalOnMessage = transport.ws.onmessage;
2340
- const ws = transport.ws;
2341
- transport.ws.onmessage = function (event) {
2342
- // Clone event data to avoid issues with delayed processing
2343
- var eventData = event.data;
2344
- if (eventData instanceof Blob) {
2345
- eventData = eventData.slice();
2346
- }
2347
- else if (eventData instanceof ArrayBuffer) {
2348
- eventData = eventData.slice(0);
2349
- }
2350
- else if (typeof eventData === 'string') {
2351
- eventData = eventData;
2352
- }
2353
- trackReceivedMessage(eventData);
2354
- // Apply latency simulation for received messages
2355
- if (preferences.latencySimulation.enabled && preferences.latencySimulation.delay > 0) {
2356
- setTimeout(function () {
2357
- // Create a synthetic event-like object
2358
- var syntheticEvent = {
2359
- data: eventData,
2360
- target: ws,
2361
- currentTarget: ws,
2362
- type: 'message'
2363
- };
2364
- originalOnMessage.call(ws, syntheticEvent);
2365
- }, preferences.latencySimulation.delay);
2366
- }
2367
- else {
2368
- return originalOnMessage.apply(this, arguments);
2369
- }
2370
- };
2371
- }
2456
+ // Monkey-patch: track received messages through onmessage event
2457
+ const originalOnMessage = transport.events.onmessage;
2458
+ transport.events.onmessage = function (event) {
2459
+ // Clone event data to avoid issues with delayed processing
2460
+ var eventData = event.data;
2461
+ if (eventData instanceof Blob) {
2462
+ eventData = eventData.slice();
2463
+ }
2464
+ else if (eventData instanceof ArrayBuffer) {
2465
+ eventData = eventData.slice(0);
2466
+ }
2467
+ else if (typeof eventData === 'string') {
2468
+ eventData = eventData;
2469
+ }
2470
+ trackReceivedMessage(eventData);
2471
+ // Apply latency simulation for received messages
2472
+ if (preferences.latencySimulation.enabled && preferences.latencySimulation.delay > 0) {
2473
+ setTimeout(function () {
2474
+ // Create a synthetic event-like object
2475
+ var syntheticEvent = {
2476
+ data: eventData,
2477
+ target: event.target,
2478
+ currentTarget: event.currentTarget,
2479
+ type: 'message'
2480
+ };
2481
+ originalOnMessage.call(event.target, syntheticEvent);
2482
+ }, preferences.latencySimulation.delay);
2483
+ }
2484
+ else {
2485
+ return originalOnMessage.apply(this, arguments);
2486
+ }
2487
+ };
2372
2488
  // Monkey-patch: sending messages through room connection
2373
2489
  const originalSend = room.connection.send.bind(room.connection);
2374
2490
  room.connection.send = function (data) {
@@ -2398,6 +2514,11 @@ function applyMonkeyPatches() {
2398
2514
  ensureGlobalUpdateInterval();
2399
2515
  // Clean up on room leave
2400
2516
  room.onLeave.once(() => {
2517
+ // Clear ping interval
2518
+ if (debugInfo.pingInterval !== null) {
2519
+ clearInterval(debugInfo.pingInterval);
2520
+ debugInfo.pingInterval = null;
2521
+ }
2401
2522
  roomDebugInfo.delete(uniquePanelId);
2402
2523
  var panel = document.getElementById('debug-panel-' + uniquePanelId);
2403
2524
  if (panel) {
@@ -2420,31 +2541,23 @@ function applyMonkeyPatches() {
2420
2541
  // Patch joinOrCreate
2421
2542
  Client.Client.prototype.joinOrCreate = function () {
2422
2543
  var promise = originalJoinOrCreate.apply(this, arguments);
2423
- return promise.then(function (room) {
2424
- return patchRoom(room);
2425
- });
2544
+ return promise.then((room) => patchRoom(room));
2426
2545
  };
2427
2546
  // Patch join
2428
2547
  Client.Client.prototype.join = function () {
2429
2548
  var promise = originalJoin.apply(this, arguments);
2430
- return promise.then(function (room) {
2431
- return patchRoom(room);
2432
- });
2549
+ return promise.then((room) => patchRoom(room));
2433
2550
  };
2434
2551
  // Patch create
2435
2552
  Client.Client.prototype.create = function () {
2436
2553
  var promise = originalCreate.apply(this, arguments);
2437
- return promise.then(function (room) {
2438
- return patchRoom(room);
2439
- });
2554
+ return promise.then((room) => patchRoom(room));
2440
2555
  };
2441
2556
  // Patch reconnect
2442
2557
  if (originalReconnect) {
2443
2558
  Client.Client.prototype.reconnect = function () {
2444
2559
  var promise = originalReconnect.apply(this, arguments);
2445
- return promise.then(function (room) {
2446
- return patchRoom(room);
2447
- });
2560
+ return promise.then((room) => patchRoom(room));
2448
2561
  };
2449
2562
  }
2450
2563
  }