-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from tanishqmanuja/feat/mobile
Support for Mobile Client
- Loading branch information
Showing
4 changed files
with
157 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,44 @@ | ||
import json | ||
import logging | ||
from websocket_server import WebsocketServer | ||
|
||
from src.constants import version | ||
|
||
logging.getLogger('websocket_server.websocket_server').disabled = True | ||
|
||
# websocket.enableTrace(True) | ||
|
||
class Server: | ||
def __init__(self, log, Error): | ||
self.Error = Error | ||
self.log = log | ||
self.lastMessage = "" | ||
self.lastMessages = {} | ||
|
||
def start_server(self): | ||
try: | ||
# print(self.lastMessage) | ||
with open('config.json', "r") as conf: | ||
with open("config.json", "r") as conf: | ||
port = json.load(conf)["port"] | ||
self.server = WebsocketServer(host='127.0.0.1', port=port) | ||
self.server = WebsocketServer(host="0.0.0.0", port=port) | ||
# server = websocket.WebSocketApp("wss://localhost:1100", on_open=on_open, on_message=on_message, on_close=on_close) | ||
self.server.set_fn_new_client(self.handle_new_client) | ||
self.server.run_forever(threaded=True) | ||
except Exception as e: | ||
self.Error.PortError(port) | ||
|
||
def handle_new_client(self, client, server): | ||
if self.lastMessage != "": | ||
self.send_message(self.lastMessage) | ||
|
||
self.send_payload("version",{ | ||
"core": version | ||
}) | ||
for key in self.lastMessages: | ||
if key not in ["chat","version"]: | ||
self.send_message(self.lastMessages[key]) | ||
|
||
def send_message(self, message): | ||
self.lastMessage = message | ||
self.server.send_message_to_all(message) | ||
|
||
def send_payload(self, type, payload): | ||
payload["type"] = type | ||
msg_str = json.dumps(payload) | ||
self.lastMessages[type] = msg_str | ||
self.server.send_message_to_all(msg_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters