Metadata-Version: 2.4
Name: pyjssocket
Version: 1.0.4
Summary: A Python library that lets you communicate through JavaScript WebSocket client
Author-email: Dmytro Terekhov <terekhov160997@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/dododo25/pyjssocket
Project-URL: Issues, https://github.com/dododo25/pyjssocket/issues
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENCE
Dynamic: license-file

# PyJSSocket
This is a Python library that lets you communicate through JavaScript WebSocket client.

## Installation
To install this library run `pip install pyjssocket` in your terminal.

## Example
Here is an example of a server that can handle multiple calls from a different JS clients
```
import json
import jsserver
import socketserver

import threading
import time

class MyJsRequestHandler(jsserver.JSBaseRequestHandler):

    def on_handshake(self, host: str, url: str, seqKey: str):
        def target():
            while True:
                self.send_response(json.dumps({'success': True, 'time': time.time()}))
                time.sleep(1)

        super().on_handshake(host, url, seqKey)

        thread = threading.Thread(target=target, daemon=True)
        thread.start()

    def on_message(self, data: bytes):
        self.send_response(json.dumps({'success': True, 'time': time.time()}))

    def on_error(self, value: str):
        self.send_response(json.dumps({'success': False, 'message': value}))

if __name__ == '__main__':
    with socketserver.ThreadingTCPServer(('0.0.0.0', 451), MyJsRequestHandler) as tcpServer:
        tcpServer.serve_forever()
```
