Giter Site home page Giter Site logo

aiosignalrcore's Introduction

SignalR core client (async fork)

Pypi

This is asyncio version of the original SignalR Core library.
The main difference is that websocket library is replaced with asyncio-compatabile websockets.
All future changes in the original repo will be merged to this fork inheriting the major and minor version number.

Installation

pip install aiosignalrcore

Usage

Check out the docs of the original library.
The names of all modules, classes, and methods are preserved.

Async example

import asyncio
import logging
from aiosignalrcore.hub_connection_builder import HubConnectionBuilder
from aiosignalrcore.messages.completion_message import CompletionMessage
from aiosignalrcore.transport.websockets.connection import ConnectionState


hub_connection = (
    HubConnectionBuilder()
        .with_url('%URL%')
        .with_automatic_reconnect(
            {
                "type": "raw",
                "keep_alive_interval": 10,
                "reconnect_interval": 5,
                "max_attempts": 5,
            }
        )
        .build()
)


async def on_connect():
    logging.info('Connected to the server')
    
    while hub_connection.transport.state != ConnectionState.connected:
        await asyncio.sleep(0.1)

    await hub_connection.send("SendMessage", [])


async def on_message(message):
    pass


def on_error(self, message: CompletionMessage):
    raise Exception(message.error)


hub_connection.on_open(on_connect)
hub_connection.on_error(on_error)
hub_connection.on("Message", on_message)

await hub_connection.start()

try:
    while hub_connection.transport.state == ConnectionState.connected:
        await asyncio.sleep(1)
except KeyboardInterrupt:
    pass
finally:
    await hub_connection.stop()

aiosignalrcore's People

Contributors

anbaalo avatar bmc-msft avatar droserasprout avatar fernanortega avatar georgik avatar lhotamir avatar m-kus avatar mandrewcito avatar miracle2k avatar smiddle avatar synapticarbors avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.