Browse Source

try websocket and only fall back on long polling
default was to first start long polling and then upgrade to websocket
which is hurting performance and produces errors in edge cases

Rodja Trappe 2 năm trước cách đây
mục cha
commit
ad60420b95
1 tập tin đã thay đổi với 2 bổ sung1 xóa
  1. 2 1
      nicegui/templates/index.html

+ 2 - 1
nicegui/templates/index.html

@@ -155,8 +155,9 @@
           const query = { client_id: "{{ client_id }}" };
           const query = { client_id: "{{ client_id }}" };
           const url = window.location.protocol === 'https:' ? 'wss://' : 'ws://' + window.location.host;
           const url = window.location.protocol === 'https:' ? 'wss://' : 'ws://' + window.location.host;
           const extraHeaders = {{ socket_io_js_extra_headers | safe }};
           const extraHeaders = {{ socket_io_js_extra_headers | safe }};
+          const transports = ['websocket', 'polling'];
           window.path_prefix = "{{ prefix | safe }}";
           window.path_prefix = "{{ prefix | safe }}";
-          window.socket = io(url, { path: "{{ prefix | safe }}/_nicegui_ws/socket.io", query, extraHeaders });
+          window.socket = io(url, { path: "{{ prefix | safe }}/_nicegui_ws/socket.io", query, extraHeaders, transports });
           window.socket.on("connect", () => {
           window.socket.on("connect", () => {
             window.socket.emit("handshake", (ok) => {
             window.socket.emit("handshake", (ok) => {
               if (!ok) window.location.reload();
               if (!ok) window.location.reload();