예제 #1
0
 def test_auth_configured(self):
     with self.assertRaises(TypeError):
         hub = HubConnectionBuilder()\
                 .with_url(self.server_url,
                 options={
                     "verify_ssl": False,
                     "headers": {
                         "mycustomheader": "mycustomheadervalue"
                     }
                 })
         hub.has_auth_configured = True
         hub.options["access_token_factory"] = ""
         conn = hub.build()
예제 #2
0
 def test_enable_trace(self):
     hub = HubConnectionBuilder()\
         .with_url(self.server_url, options={"verify_ssl":False})\
         .configure_logging(logging.WARNING, socket_trace=True)\
         .with_automatic_reconnect({
             "type": "raw",
             "keep_alive_interval": 10,
             "reconnect_interval": 5,
             "max_attempts": 5
         })\
         .build()
     hub.on_open(self.on_open)
     hub.on_close(self.on_close)
     hub.start()
     self.assertTrue(websocket.isEnabledForDebug())
     websocket.enableTrace(False)
     hub.stop()
예제 #3
0
    def _setUp(self, msgpack=False):
        builder = HubConnectionBuilder()\
            .with_url(self.server_url,
            options={
                "verify_ssl": False,
                "access_token_factory": self.login,
                "headers": {
                    "mycustomheader": "mycustomheadervalue"
                }
            })

        if msgpack:
            builder.with_hub_protocol(MessagePackHubProtocol())

        builder.configure_logging(logging.WARNING)\
            .with_automatic_reconnect({
                "type": "raw",
                "keep_alive_interval": 10,
                "reconnect_interval": 5,
                "max_attempts": 5
            })
        self.connection = builder.build()
        self.connection.on("ReceiveMessage", self.receive_message)
        self.connection.on_open(self.on_open)
        self.connection.on_close(self.on_close)
        self._lock = threading.Lock()
        self.assertTrue(self._lock.acquire(timeout=30))
        self.connection.start()
예제 #4
0
    def get_connection(self, msgpack=False):
        builder = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl":False})\
            .configure_logging(logging.ERROR)\
            .with_automatic_reconnect({
                "type": "raw",
                "keep_alive_interval": 10,
                "reconnect_interval": 5,
                "max_attempts": 5
            })

        if msgpack:
            builder.with_hub_protocol(MessagePackHubProtocol())

        hub = builder.build()
        hub.on_open(self.on_open)
        hub.on_close(self.on_close)
        return hub
예제 #5
0
 def test_bad_auth_function(self):
     with self.assertRaises(TypeError):
         self.connection = HubConnectionBuilder()\
             .with_url(self.server_url,
             options={
                 "verify_ssl": False,
                 "access_token_factory": 1234,
                 "headers": {
                     "mycustomheader": "mycustomheadervalue"
                 }
             })
 def test_reconnect_interval(self):
     connection = HubConnectionBuilder()\
         .with_url(self.server_url, options={"verify_ssl": False})\
         .configure_logging(logging.ERROR)\
         .with_automatic_reconnect({
             "type": "interval",
             "intervals": [1, 2, 4, 45, 6, 7, 8, 9, 10],
             "keep_alive_interval": 3
         })\
         .build()
     self.reconnect_test(connection)
    def test_raw_reconnection(self):
        connection = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl": False})\
            .configure_logging(logging.ERROR)\
            .with_automatic_reconnect({
                "type": "raw",
                "keep_alive_interval": 10,
                "max_attempts": 4
            })\
            .build()

        self.reconnect_test(connection)
예제 #8
0
    def test_start(self):
        connection = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl": False})\
            .configure_logging(logging.ERROR)\
            .build()
        
        _lock = threading.Lock()
        self.assertTrue(_lock.acquire(timeout=30))
        

        connection.on_open(lambda: _lock.release())
        connection.on_close(lambda: _lock.release())
        
        result = connection.start()

        self.assertTrue(result)
        
        self.assertTrue(_lock.acquire(timeout=30))  # Released on open
        
        result = connection.start()

        self.assertFalse(result)

        connection.stop()
    def test_reconnect_interval_config(self):
        connection = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl": False})\
            .configure_logging(logging.ERROR)\
            .with_automatic_reconnect({
                "type": "interval",
                "intervals": [1, 2, 4, 45, 6, 7, 8, 9, 10]
            })\
            .build()
        _lock = threading.Lock()
        connection.on_open(lambda: _lock.release())
        connection.on_close(lambda: _lock.release())

        self.assertTrue(_lock.acquire(timeout=10))

        connection.start()

        self.assertTrue(_lock.acquire(timeout=10))

        connection.stop()

        self.assertTrue(_lock.acquire(timeout=10))

        del _lock
    def _test_send(self, msgpack=False):
        builder = HubConnectionBuilder()\
            .with_url(self.server_url,
            options={
                "verify_ssl": False,
                "access_token_factory": self.login,
            })

        if msgpack:
            builder.with_hub_protocol(MessagePackHubProtocol())

        builder.configure_logging(logging.ERROR)
        self.connection = builder.build()
        self.connection.on_open(self.on_open)
        self.connection.on_close(self.on_close)
        self.assertRaises(requests.exceptions.ConnectionError,
                          lambda: self.connection.start())
예제 #11
0
    def _get_client(self) -> BaseHubConnection:
        """Create SignalR client, register message callbacks"""
        if self._client is None:
            self._logger.info('Creating websocket client')
            self._client = (HubConnectionBuilder().with_url(
                self._url + '/v1/events').with_automatic_reconnect({
                    "type":
                    "raw",
                    "keep_alive_interval":
                    10,
                    "reconnect_interval":
                    5,
                    "max_attempts":
                    5,
                })).build()

            self._client.on_open(self._on_connect)
            self._client.on_error(self._on_error)
            self._client.on('operations', self._on_operation_message)
            self._client.on('bigmaps', self._on_big_map_message)

        return self._client
예제 #12
0
def input_with_default(input_text, default_value):
    value = input(input_text.format(default_value))
    return default_value if value is None or value.strip() == "" else value


server_url = input_with_default('Enter your server url(default: {0}): ',
                                "wss://localhost:5001/chatHub")
username = input_with_default('Enter your username (default: {0}): ',
                              "mandrewcito")
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
hub_connection = HubConnectionBuilder()\
    .with_url(server_url, options={"verify_ssl": False}) \
    .configure_logging(logging.DEBUG, socket_trace=True, handler=handler) \
    .with_automatic_reconnect({
            "type": "interval",
            "keep_alive_interval": 10,
            "intervals": [1, 3, 5, 6, 7, 87, 3]
        }).build()

hub_connection.on_open(lambda: print(
    "connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: print("connection closed"))

hub_connection.on("ReceiveMessage", print)
hub_connection.start()
message = None

# Do login

while message != "exit()":
예제 #13
0

server_url = input_with_default('Enter your server url(default: {0}): ',
                                "localhost:7071/api")
username = input_with_default('Enter your username (default: {0}): ',
                              "mandrewcito")
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
hub_connection = HubConnectionBuilder() \
        .with_url("ws://"+server_url, options={
            "verify_ssl": False,
            "skip_negotiation": False,
            "headers": {
            }
        }) \
        .configure_logging(logging.DEBUG, socket_trace=True, handler=handler) \
        .build()

hub_connection.on_open(lambda: print(
    "connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: print("connection closed"))

hub_connection.on("newMessage", print)
hub_connection.start()
message = None

# Do login
예제 #14
0

def input_with_default(input_text, default_value):
    value = input(input_text.format(default_value))
    return default_value if value is None or value.strip() == "" else value


server_url = input_with_default('Enter your server url(default: {0}): ',
                                "wss://localhost:5001/chatHub")

handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
hub_connection = HubConnectionBuilder()\
    .with_url(server_url, options={"verify_ssl": False}) \
    .configure_logging(logging.DEBUG, socket_trace=True, handler=handler) \
    .with_automatic_reconnect({
            "type": "interval",
            "keep_alive_interval": 10,
            "intervals": [1, 3, 5, 6, 7, 87, 3]
        }).build()

hub_connection.on_open(lambda: print(
    "connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: print(
    "connection closed>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<"))
hub_connection.on_error(lambda err: print("errrrrrrrrrrrrrrrrrrr"))

hub_connection.on("ThrowExceptionCall", lambda x: print(f">>>{x}"))
hub_connection.start()
message = None

# Do login
예제 #15
0
import threading
import logging
import sys
import time

sys.path.append("./")

from aiosignalrcore.hub_connection_builder import HubConnectionBuilder

connection = HubConnectionBuilder()\
    .with_url("wss://localhost:5001/chathub", options={"verify_ssl": False})\
    .configure_logging(logging.ERROR)\
    .build()

_lock = threading.Lock()

connection.on_open(lambda: _lock.release())
connection.on_close(lambda: _lock.release())

connection.on("ReceiveMessage", lambda _: _lock.release())

(_lock.acquire(timeout=30))  # Released on open

connection.start()

(_lock.acquire(timeout=30))  # Released on ReOpen

connection.send("DisconnectMe", [])

time.sleep(30)
예제 #16
0
def signalr_core_example_login(url, user, username_password):
    response = requests.post(url, json={"username": user, "password": username_password}, verify=False)
    return response.json()["token"]


login_url = input_with_default('Enter your server login url({0}):', "https://localhost:5001/users/authenticate")
server_url = input_with_default('Enter your server url(default: {0}): ', "wss://localhost:5001/authHub")
username = input_with_default('Enter your username (default: {0}): ', "test")
password = input_with_default('Enter your password (default: {0}): ', "test")

hub_connection = HubConnectionBuilder()\
    .configure_logging(logging_level=logging.DEBUG)\
    .with_url(server_url, options={
        "access_token_factory": lambda: signalr_core_example_login(login_url, username, password),
        "verify_ssl": False
    }).with_automatic_reconnect({
        "type": "interval",
        "keep_alive_interval": 10,
        "intervals": [1, 3, 5, 6, 7, 87, 3]
    })\
    .build()

hub_connection.on_open(lambda: print("connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: print("connection closed"))

hub_connection.on("ReceiveSystemMessage", print)
hub_connection.on("ReceiveChatMessage", print)
hub_connection.on("ReceiveDirectMessage", print)

hub_connection.start()
message = None
예제 #17
0

login_url = input_with_default('Enter your server login url({0}):',
                               "http://*****:*****@mandrewcito.com")
password = input_with_default('Enter your password (default: {0}): ',
                              "Abc123.--123?")

hub_connection = HubConnectionBuilder()\
    .with_url(server_url, options={
        "access_token_factory": lambda: signalr_core_example_login(login_url, username, password)
    }).with_automatic_reconnect({
        "type": "interval",
        "keep_alive_interval": 10,
        "intervals": [1, 3, 5, 6, 7, 87, 3]
    })\
    .build()

hub_connection.on("ReceiveSystemMessage", print_message)
hub_connection.on("ReceiveChatMessage", print_message)
hub_connection.on("ReceiveDirectMessage", print_message)
hub_connection.start()
message = None
while message != "exit()":
    message = raw_input(">> ")
    if message is not None and message is not "" and message is not "exit()":
        hub_connection.send("Send", [message])
hub_connection.stop()
예제 #18
0
    def test_no_reconnect(self):
        connection = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl": False})\
            .configure_logging(logging.ERROR)\
            .build()

        _lock = threading.Lock()

        _lock.acquire(timeout=10)

        connection.on_open(lambda: _lock.release())

        connection.on("ReceiveMessage", lambda _: _lock.release())

        connection.start()

        self.assertTrue(_lock.acquire(timeout=10))  # Released on ReOpen

        connection.send("DisconnectMe", [])

        self.assertTrue(_lock.acquire(timeout=10))

        time.sleep(10)

        self.assertRaises(HubConnectionError,
                          lambda: connection.send("DisconnectMe", []))

        connection.stop()
        del _lock
예제 #19
0
 def test_bad_url(self):
     with self.assertRaises(ValueError):
         self.connection = HubConnectionBuilder()\
             .with_url("")
import time
from aiosignalrcore.hub_connection_builder import HubConnectionBuilder


def input_with_default(input_text, default_value):
    value = input(input_text.format(default_value))
    return default_value if value is None or value.strip() == "" else value


server_url = input_with_default('Enter your server url(default: {0}): ',
                                "ws://localhost:62342/chathub")
username = input_with_default('Enter your username (default: {0}): ',
                              "mandrewcito")

hub_connection = HubConnectionBuilder()\
    .with_url(server_url)\
    .configure_logging(logging.DEBUG)\
    .build()

hub_connection.on_open(lambda: print(
    "connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: reconnect)


def reconnect():
    print("connection closed")
    time.sleep(20)
    print("try reconnect")
    hub_connection.start()


hub_connection.on("ReceiveMessage", print)
예제 #21
0
 def test_bad_options(self):
     with self.assertRaises(TypeError):
         self.connection = HubConnectionBuilder()\
             .with_url(self.server_url,
             options=["ssl", True])
예제 #22
0
from aiosignalrcore.subject import Subject


def input_with_default(input_text, default_value):
    value = input(input_text.format(default_value))
    return default_value if value is None or value.strip() == "" else value


server_url = input_with_default('Enter your server url(default: {0}): ',
                                "wss://localhost:5001/chatHub")

hub_connection = HubConnectionBuilder()\
    .with_url(server_url, options={"verify_ssl": False}) \
    .configure_logging(logging.DEBUG) \
    .with_automatic_reconnect({
            "type": "interval",
            "keep_alive_interval": 10,
            "intervals": [1, 3, 5, 6, 7, 87, 3]
        })\
    .build()
hub_connection.start()
time.sleep(10)


def bye(error, x):
    if error:
        print("error {0}".format(x))
    else:
        print("complete! ")
    global hub_connection
    hub_connection.stop()
예제 #23
0
import sys
sys.path.append("./")
from aiosignalrcore.hub_connection_builder import HubConnectionBuilder
import logging


def input_with_default(input_text, default_value):
    value = input(input_text.format(default_value))
    return default_value if value is None or value.strip() == "" else value


server_url = input_with_default('Enter your server url(default: {0}): ',
                                "wss://localhost:5001/chatHub")

hub_connection = HubConnectionBuilder().with_url(server_url, options={"verify_ssl": False}) \
    .configure_logging(logging.DEBUG, socket_trace=True) \
    .build()
hub_connection.start()
time.sleep(10)

end = False


def bye(error, x):
    global end
    end = True
    if error:
        print("error {0}".format(x))
    else:
        print("complete! ")
    global hub_connection