def handle(self, *args, **options):
        if options['ssl_cert'] is not None:
            ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
            ssl_context.load_cert_chain(options['ssl_cert'])
        else:
            ssl_context = None
        

        if hasattr(asyncio, "ensure_future"):
            ensure_future = asyncio.ensure_future 
        else:
            ensure_future = getattr(asyncio, "async")

        ensure_future(
            websockets.serve(
                handlers.main_handler,
                settings.CHAT_WS_SERVER_HOST,
                settings.CHAT_WS_SERVER_PORT,
                ssl=ssl_context
            )
        )

        logger.info('Chat server started')

        ensure_future(handlers.new_messages_handler(channels.new_messages))
        ensure_future(handlers.users_changed_handler(channels.users_changed))
Esempio n. 2
0
    def handle(self, *args, **options):
        if options['ssl_cert'] is not None:
            if sys.version_info >= (3, 6):
                protocol = ssl.PROTOCOL_TLS_SERVER
            elif sys.version_info >= (3, 4):
                protocol = ssl.PROTOCOL_TLSv1
            else:
                v = str(sys.version_info.major) + '.' + str(
                    sys.version_info.minor)
                version_s = 'Version %s is not supported for wss!' % v
                raise Exception(version_s)
            ssl_context = ssl.SSLContext(protocol)
            ssl_context.load_cert_chain(options['ssl_cert'])
        else:
            ssl_context = None

        asyncio. async (websockets.serve(handlers.main_handler,
                                         settings.CHAT_WS_SERVER_HOST,
                                         settings.CHAT_WS_SERVER_PORT,
                                         ssl=ssl_context))

        logger.info('Chat server started')
        asyncio. async (handlers.new_messages_handler(channels.new_messages))
        asyncio. async (handlers.users_changed_handler(channels.users_changed))
        asyncio. async (handlers.gone_online(channels.online))
        asyncio. async (handlers.check_online(channels.check_online))
        asyncio. async (handlers.gone_offline(channels.offline))
        asyncio. async (handlers.is_typing_handler(channels.is_typing))
        asyncio. async (handlers.read_message_handler(channels.read_unread))
        loop = asyncio.get_event_loop()
        loop.run_forever()
Esempio n. 3
0
    def handle(self, *args, **options):
        if options['ssl_cert'] is not None:
            ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
            ssl_context.load_cert_chain(options['ssl_cert'])
        else:
            ssl_context = None

        if hasattr(asyncio, "ensure_future"):
            ensure_future = asyncio.ensure_future
        else:
            ensure_future = getattr(asyncio, "async")

        ensure_future(
            websockets.serve(handlers.main_handler,
                             settings.CHAT_WS_SERVER_HOST,
                             settings.CHAT_WS_SERVER_PORT,
                             ssl=ssl_context))

        logger.info(
            'Chat server uvloop started, Listen in [{}://{}:{}]'.format(
                settings.CHAT_WS_SERVER_PROTOCOL, settings.CHAT_WS_SERVER_HOST,
                settings.CHAT_WS_SERVER_PORT))
        ensure_future(handlers.new_messages_handler(channels.new_messages))
        ensure_future(handlers.users_changed_handler(channels.users_changed))
        ensure_future(handlers.gone_online(channels.online))
        ensure_future(handlers.check_online(channels.check_online))
        ensure_future(handlers.gone_offline(channels.offline))
        ensure_future(handlers.is_typing_handler(channels.is_typing))
        ensure_future(handlers.read_message_handler(channels.read_unread))
        loop = asyncio.get_event_loop()
        loop.run_forever()
    def handle(self, *args, **options):
        if options['ssl_cert'] is not None:
            ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
            ssl_context.load_cert_chain(options['ssl_cert'])
        else:
            ssl_context = None

        asyncio.async(
            websockets.serve(
                handlers.main_handler,
                settings.CHAT_WS_SERVER_HOST,
                settings.CHAT_WS_SERVER_PORT,
                ssl=ssl_context
            )
        )

        logger.info('Chat server started')
        asyncio.async(handlers.new_messages_handler(channels.new_messages))
        asyncio.async(handlers.users_changed_handler(channels.users_changed))
        asyncio.async(handlers.gone_online(channels.online))
        asyncio.async(handlers.check_online(channels.check_online))
        asyncio.async(handlers.gone_offline(channels.offline))
        asyncio.async(handlers.is_typing_handler(channels.is_typing))
        asyncio.async(handlers.read_message_handler(channels.read_unread))
        loop = asyncio.get_event_loop()
        loop.run_forever()
Esempio n. 5
0
    def handle(self, *args, **options):
        asyncio. async (websockets.serve(handlers.main_handler,
                                         settings.CHAT_WS_SERVER_HOST,
                                         settings.CHAT_WS_SERVER_PORT))

        asyncio. async (handlers.new_messages_handler(channels.new_messages))
        asyncio. async (handlers.users_changed_handler(channels.users_changed))
        asyncio. async (handlers.gone_online(channels.online))
        asyncio. async (handlers.check_online(channels.check_online))
        asyncio. async (handlers.is_typing_handler(channels.is_typing))
        asyncio. async (handlers.list_check_online(channels.list_check_online))
        loop = asyncio.get_event_loop()
        loop.run_forever()
Esempio n. 6
0
 def handle(self, *args, **options):
     asyncio. async (websockets.serve(handlers.main_handler,
                                      settings.CHAT_WS_SERVER_HOST,
                                      settings.CHAT_WS_SERVER_PORT))
     logger.info('Chat server started')
     asyncio. async (handlers.handshaking_handler(channels.handshaking))
     asyncio. async (handlers.new_messages_handler(channels.new_messages))
     asyncio. async (handlers.users_changed_handler(channels.users_changed))
     asyncio. async (handlers.gone_online(channels.online))
     asyncio. async (handlers.check_online(channels.check_online))
     asyncio. async (handlers.gone_offline(channels.offline))
     asyncio. async (handlers.is_typing_handler(channels.is_typing))
     asyncio. async (handlers.read_message_handler(channels.read_unread))
     loop = asyncio.get_event_loop()
     loop.run_forever()