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

allow websocket connection to remain open #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 15 additions & 4 deletions chromote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,27 @@ def __init__(self, id, title, url, websocketURL):
self._url = url
self._websocketURL = websocketURL
self._message_id = 0
self._ws = websocket.WebSocket()

def _send(self, request):
self._message_id += 1
request['id'] = self._message_id
ws = websocket.create_connection(self.websocketURL)
ws.send(json.dumps(request))
res = ws.recv()
ws.close()
close_after = False
if not self._ws.connected:
self._ws.connect(self.websocketURL)
close_after = True
self._ws.send(json.dumps(request))
res = self._ws.recv()
if close_after:
self._ws.close()
return res

def connect_websocket(self):
self._ws.connect(self.websocketURL)

def close_websocket(self):
self._ws.close()

@property
def title(self):
return self._title
Expand Down