diff --git a/main.py b/main.py index 583d1ad..73efd48 100644 --- a/main.py +++ b/main.py @@ -340,14 +340,12 @@ def finalize_connection(server): if negotiated_protocol is None: negotiated_protocol = server.socket.selected_npn_protocol() - transport_type = None - if negotiated_protocol == "http/1.1": - transport_type = TransportType.HTTP + server.transport_type = TransportType.HTTP elif negotiated_protocol == "h2": - transport_type = TransportType.HTTP2 + server.transport_type = TransportType.HTTP2 - data = server.client.connect(transport_type) + data = server.client.connect(server.transport_type) server.send(data) server.login() diff --git a/matrix/server.py b/matrix/server.py index e653314..7809a84 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -30,6 +30,7 @@ from nio import ( SyncRepsponse, RoomSendResponse, TransportResponse, + TransportType, LocalProtocolError ) @@ -173,6 +174,7 @@ class MatrixServer(object): self.sync_time = None # type: Optional[float] self.socket = None # type: ssl.SSLSocket self.ssl_context = ssl.create_default_context() # type: ssl.SSLContext + self.transport_type = None # type: Optional[nio.TransportType] # Enable http2 negotiation on the ssl context. self.ssl_context.set_alpn_protocols(["h2", "http/1.1"]) @@ -391,6 +393,7 @@ class MatrixServer(object): self.send_buffer = b"" self.current_message = None + self.transport_type = None try: self.client.disconnect() @@ -702,7 +705,8 @@ def matrix_timer_cb(server_name, remaining_calls): return W.WEECHAT_RC_OK if server.sync_time and current_time > (server.sync_time + 2): - server.sync(30000) + timeout = 0 if server.transport_type == TransportType.HTTP else 30000 + server.sync(timeout) while server.send_queue: message = server.send_queue.popleft()