def __init__(self, room, nick=None, **kwargs): self.room = room self.nick = nick self.account = kwargs.get('account') self.password = kwargs.get('password') self.room_pass = kwargs.get('room_pass') self.proxy = kwargs.get('proxy', None) self.users = Users() self.state = RoomState() self.console = Console(self.room, log_path=config.CONFIG_PATH, chat_logging=config.CHAT_LOGGING, use_colors=config.CONSOLE_COLORS) self._connect_args = None self._ws = None self._is_connected = False self._req = 1 captcha.MAX_TRIES = kwargs.get('captcha_tries', 11) captcha.CAPTCHA_TIMEOUT = kwargs.get('captcha_timeout', 5) if self.nick is None or self.nick == '': self.nick = string_util.create_random_string(3, 20)
def send_join_msg(self): """ The initial connect message to the room. The client sends this after the websocket handshake has been established. :return: Returns True if the connect message has been sent, else False. :rtype: bool """ if not self.nickname: self.nickname = string_util.create_random_string(3, 20) rtc_version = apis.tinychat.rtc_version(self.room_name) log.info('tinychat rtc version: %s' % rtc_version) if rtc_version is None: rtc_version = config.FALLBACK_RTC_VERSION log.info('failed to parse rtc version, using fallback: %s' % config.FALLBACK_RTC_VERSION) token = apis.tinychat.get_connect_token(self.room_name)['token'] if token is not None: # opera/chrome user-agent: tinychat-client-webrtc-chrome_win32-2.0.9-255 payload = { 'tc': 'join', 'req': self._req, 'useragent': 'tinychat-client-webrtc-undefined_win32-' + rtc_version, 'token': token, 'room': self.room_name, 'nick': self.nickname } self.send(payload) return True else: self.console_write(COLOR['bright_red'], 'Token request failed, token=%s' % token) return False
async def send_join_msg(self): """ The initial connect message to the room. The client sends this after the websocket handshake has been established. :return: Returns True if the connect message has been sent, else False. :rtype: bool """ if not self.nickname: self.nickname = string_util.create_random_string(3, 20) rtc_version = await apis.tinychat.rtc_version(self.room_name) log.info(f"tinychat rtc version: {rtc_version}") if rtc_version is None: rtc_version = config.FALLBACK_RTC_VERSION log.info( f"failed to parse rtc version, using fallback: {config.FALLBACK_RTC_VERSION}" ) token = self.connect_info["result"] if token is not None: payload = { "tc": "join", "useragent": f"tinychat-client-webrtc-undefined_win32-{rtc_version}", "token": token, "room": self.room_name, "nick": self.nickname, } await self.send(payload) return True else: log.info(f"Token request failed\ntoken={token}") return False
def connect(self): """ Connect to the remote server. """ _error = None if not self.users.client.nick.strip(): self.users.client.nick = string_util.create_random_string( 6, 25) # adjust length try: params = ezcapechat.Params(self.room_name, self.users.client.nick, n_key=self._pub_n_key, proxy=self.proxy) self.connection = rtmp.RtmpClient( ip=params.ip, port=params.port, tc_url=params.tc_url, app=params.app, swf_url=params.swf_url, page_url=params.page_url, proxy=self.proxy, is_win=True # delete/set to false if not on windows ) self.connection.connect([ u'connect', # application connect string? u'', # ? params.t1, # t1 params.t2, # t2 0, # ? u'', # ? u'', # ? u'', # ? self.room_name, # room name # value of guid (Local Shared Object) u'A62E0786-7113-2F6F-9C14-6602B02F1872-A7F34D64-C322-314C-642F-B045CF448907', # ? u'68F234E8-4070-59B7-0D9A-CAE4A8D33539-1BFE74C1-C98E-2834-3A85-BFA16CF4C032', u'0.33', # protocol version u'', # room password u'', # ? False # disabled(flash_vars[0]) ? ]) except Exception as e: log.critical(e, exc_info=True) _error = e finally: if _error is not None: print('connect error: %s' % _error) else: self.is_connected = True self.__callback()