ashleysommer/sanic-sockjs

SockJS bolt-on feature for Sanic Server

★ 2Forks 1PythonGitHub ↗Compare

README

SockJS server based on Asyncio (PEP 3156)

sanic_sockjs is a SockJS integration for Sanic. SockJS interface is implemented as a Sanic route. Its possible to create any number of different sockjs routes, ie /sockjs/* or /mycustom-sockjs/*. You can provide different session implementation and management for each sockjs route.

Simple Sanic web server is required:

[server:main]
use = egg:gunicorn#main
host = 0.0.0.0
port = 8080
worker = sanic.worker.GunicornWorker

Example of sockjs route:

def main(global_settings, **settings):
    app = Sanic(__main__)
    @app.get('/')
    def index(request):
        ...


    sanic_sockjs.add_endpoint(app, prefix='/sockjs', handler=chatSession)
    app.run("127.0.0.1", 8080)

Client side code:

<script src="//cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.js"></script>
<script>
    var sock = new SockJS('http://localhost:8080/sockjs');

    sock.onopen = function() {
      console.log('open');
    };

    sock.onmessage = function(obj) {
      console.log(obj);
    };

    sock.onclose = function() {
      console.log('close');
    };
</script>

Supported transports

Requirements

Examples

You can find several examples in the sanic_sockjs repository at github.

https://github.com/ashleysommer/sanic-sockjs/tree/master/examples

License

sockjs is offered under the Apache 2 license.

Contributors

fafhrd91pyup-botasvetlovdependabot-preview[bot]pahazrunyagamasellCykoozjettifyjersobhAlgyjoaomoaiceboy233spumertwd2wendall911alefterissobolevnhathawshransomwachimnolgaryvdmkrkdbbigrasashleysommerstroposharik

Issues