Exemplo n.º 1
0
  def __init__(self, udp_port, nick, prefix, chatroom, url = None, protocols = [], debug = False, debugCodePaths = False):
    '''
    Args:
      udp_port (int) : The udp port to listen for WebRTC traffice.
      nick (str) : The nickname for the local user.
      prefix (str) : The prefix for the local user.
      chatroom (str) : The chatroom to join.

    Kwargs:
      url : The url for websocket server
      And other default kwargs of WebSocketServerFactory.

    A roster for the chatroom is maintained here.
    CcnxSocket created for PeetsMessages propagation if NDN.
    '''
    # super can only work with new style classes which inherits from object
    # apparently WebSocketServerFactory is old style class
    WebSocketServerFactory.__init__(self, url = url, protocols = protocols, debug = debug, debugCodePaths = debugCodePaths)
    self.handlers = {'join_room' : self.handle_join, 'send_ice_candidate' : self.handle_ice_candidate, 'send_offer' : self.handle_offer, 'media_ready' : self.handle_media_ready, 'chat_msg': self.handle_chat}
    # keep the list of local clients, first, we deal with the case where there is only one local client
    self.client = None
    # keep the list of remote users
    self.roster = None
    self.listen_port = udp_port
    self.__class__.__logger.debug('UDP-PORT=%s', str(udp_port))
    self.ccnx_socket = CcnxSocket()
    self.ccnx_socket.start()
    self.local_status_callback = lambda status: 0
    self.nick = nick
    self.prefix = prefix
    self.chatroom = chatroom
Exemplo n.º 2
0
 def __init__(self, factory, pipe_size):
   '''
   Args:
     factory (PeetsServerFactory) : the factory that stores necessory information about the local user
     pipe_size (int) : the pipeline size for fetching the remote media stream. Pipelining allows us to minimize impact of the interest-data roundtrip delay.
   '''
   self.factory = factory
   self.pipe_size = pipe_size
   self.factory = factory
   self.factory.set_local_status_callback(self.toggle_scheduler)
   # here we use two sockets, because the pending interests sent by a socket can not be satisified
   # by the content published later by the same socket
   self.ccnx_int_socket = CcnxSocket()
   self.ccnx_int_socket.start()
   self.ccnx_con_socket = CcnxSocket()
   self.ccnx_con_socket.start()
   self.stream_closure = PeetsClosure(msg_callback = self.stream_callback, timeout_callback = self.stream_timeout_callback)
   self.probe_closure = PeetsClosure(msg_callback = self.probe_callback, timeout_callback = self.probe_timeout_callback)
   self.ctrl_probe_closure = PeetsClosure(msg_callback = self.ctrl_probe_callback, timeout_callback = self.ctrl_probe_timeout_callback)
   self.scheduler = None
   self.peets_status = None
Exemplo n.º 3
0
  def __init__(self, chatroom_prefix, msg_callback, get_local_user, *args, **kwargs):
    '''
    Args:
      chatroom_prefix (str): A broadcast prefix for the chatroom; this is used by Chronos for it's sync Interests.
      msg_callbck : The callback function when a Peets Message comes.
      get_local_user : A function that returns the local user information.
    '''

    super(Roster, self).__init__(self.announce, self.reap_callback, *args, **kwargs)
    self.msg_callback = msg_callback
    self.get_local_user = get_local_user
    self.status = self.__class__.Init
    self.session = int(time())
    self.peetsClosure = PeetsClosure(msg_callback = self.process_peets_msg)
    self.ccnx_sock = CcnxSocket()
    self.ccnx_sock.start()
    self.chronos_sock = SimpleChronosSocket(chatroom_prefix, self.fetch_peets_msg)
    # send join after 0.5 second
    self.schedule_next(0.5, self.announce)