Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated websocket library and fixed bugs due to reconnects #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
msgpack==1.0.2
requests>=2.22.0
websocket-client==1.0.0
websocket-client==1.4.2
31 changes: 12 additions & 19 deletions signalrcore/transport/websockets/websocket_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from .reconnection import ConnectionStateChecker
from .connection import ConnectionState
from ...messages.ping_message import PingMessage
from ...hub.errors import HubError, HubConnectionError, UnAuthorizedHubError
from ...hub.errors import HubError, UnAuthorizedHubError
from ...protocol.messagepack_protocol import MessagePackHubProtocol
from ...protocol.json_hub_protocol import JsonHubProtocol
from ..base_transport import BaseTransport
from ...helpers import Helpers

Expand All @@ -26,7 +25,6 @@ def __init__(self,
super(WebsocketTransport, self).__init__(**kwargs)
self._ws = None
self.enable_trace = enable_trace
self._thread = None
self.skip_negotiation = skip_negotiation
self.url = url
if headers is None:
Expand All @@ -37,7 +35,6 @@ def __init__(self,
self.token = None # auth
self.state = ConnectionState.disconnected
self.connection_alive = False
self._thread = None
self._ws = None
self.verify_ssl = verify_ssl
self.connection_checker = ConnectionStateChecker(
Expand All @@ -48,16 +45,16 @@ def __init__(self,

if len(self.logger.handlers) > 0:
websocket.enableTrace(self.enable_trace, self.logger.handlers[0])

def is_running(self):
return self.state != ConnectionState.disconnected

def stop(self):
self.connection_checker.stop()
if self.state == ConnectionState.connected:
self.connection_checker.stop()
self._ws.close()
self.state = ConnectionState.disconnected
self.handshake_received = False
self.state = ConnectionState.disconnected
self.handshake_received = False

def start(self):
if not self.skip_negotiation:
Expand All @@ -69,23 +66,19 @@ def start(self):

self.state = ConnectionState.connecting
self.logger.debug("start url:" + self.url)

self._ws = websocket.WebSocketApp(
self.url,
header=self.headers,
on_message=self.on_message,
on_error=self.on_socket_error,
on_close=self.on_close,
on_open=self.on_open,
)

self._thread = threading.Thread(
target=lambda: self._ws.run_forever(
sslopt={"cert_reqs": ssl.CERT_NONE}
if not self.verify_ssl else {}
))
self._thread.daemon = True
self._thread.start()
)

self._ws.run_forever(
sslopt={"cert_reqs": ssl.CERT_NONE} if not self.verify_ssl else {},
)
return True

def negotiate(self):
Expand Down Expand Up @@ -185,7 +178,7 @@ def on_message(self, app, raw_message):
return self._on_message(messages)

return []

return self._on_message(
self.protocol.parse_messages(raw_message))

Expand Down