def __init__(self, sock, sip_type = None, headers = None, body = None, home_domain = HOME_DOMAIN, protocol = PROTOCOL, first_line = None): self.sock = sock self.headers = SIPRequestHeaders(sip_type = sip_type, home_domain = home_domain, protocol = protocol, headers = headers, first_line = first_line) self.body = to_byte_str(body)
def i_send_msg(user, to_uri, msg, debug = True): conversations = user.get_conversations() if to_uri in conversations: conv = conversations[to_uri] if conv.listen_thread and not conv.listen_thread.isFinished(): sock = conv.sock else: start_chat(user, to_uri, debug = debug) res_obj = get_sock_for_send_msg(user, to_uri, debug = debug) if res_obj: sock = conv.sock else: conv = conversations[to_uri] conv.sock = user.get_sock() sock = conv.sock else: conv = conversations[to_uri] conv.sock = user.get_sock() sock = conv.sock call_id = str(user.get_global_call_id()) from_sid = user.sid sip_type = SIP(SIP.MESSAGE) sip_event = SIPEvent(SIPEvent.CAT_MESSAGE) headers = { "F" : from_sid, "I" : call_id, "Q" : "%d %s" % (DEFAULT_SIP_SEQUENCE, str(sip_type)), "N" : str(sip_event), "T" : to_uri, "C" : "text/plain", "K" : "SaveHistory", } body = to_byte_str(msg) sip_conn = SIPConnection(sock, sip_type = sip_type, headers = headers, body = body) """TODO: we should add this msg into unack_msg_list, traversal un-ack message list in 20s interval, pop up a send message failed warning for no un-ack message. """ unack_msg = { "send_ts" : int(time.time()), "call_id" : call_id, "to_uri" : to_uri, "content" : msg, } user.append_to_unack_msg_list(unack_msg) sip_conn.send(recv = False, debug = debug)
def __init__(self, sock, sip_type=None, headers=None, body=None, home_domain=HOME_DOMAIN, protocol=PROTOCOL, first_line=None): self.sock = sock self.headers = SIPRequestHeaders(sip_type=sip_type, home_domain=home_domain, protocol=protocol, headers=headers, first_line=first_line) self.body = to_byte_str(body)