Exemplo n.º 1
0
def send_message(request):
    if not EM_INTERFACE.is_connected:
        success, err_msg = EM_INTERFACE.connect(request.user.username)
        if not success:
            Comet.push_message('Error connecting to event manager: ' + err_msg)
    
    if request.GET.has_key('message'):
        message = request.GET['message']
    else:
        logging.warning('Couldnt find message value in GET request')


    builder = EventMessageBuilder()
    
    builder.event_type = EventType.EVENT
    builder.event_name = EventList.TEXT_MESSAGE
    builder.client_name = request.user.username
    
    #Get robot name from database based on the username above
    # builder.event_destination = Database.getRobotNameFromUser(builder.client_name)
    builder.event_destination = 'client1'
    
    builder.event_content = EventMessage.MSG_ARG_DELIM + message + EventMessage.MSG_ARG_DELIM

    success, err_msg = EM_INTERFACE.send_raw_string(builder.build().toString())
    
    if not success:
        # Send error message to client!
        Comet.push_message('Error sending message: ' + err_msg)
    else:
        return HttpResponse("OK")
def xhr(request):
    # see what message has been sent
    if request.GET.has_key('message'):
        message = request.GET['message']
    else:
        logging.warning('Couldnt find message value in GET request')

    # push the data to all clients.
    Comet.push_message(message)

    # That's it, thread's not locked
    return HttpResponse("OK")
def em_test(request):
    #We are viewing the em page.. make sure we are connected
    #Note.. we may want to do this in a bg thread and show the user
    #some kind of dialog
    if not EM_INTERFACE.is_connected:
        success, err_msg = EM_INTERFACE.connect()
        if not success:
            Comet.push_message('Error connecting to event manager: ' + err_msg)
    
    template_file = 'testing/em_interface_test.html' 
    mappings = {'stomp_host' :   STOMP_HOST,
                'stomp_port' :   STOMP_PORT,
                'orbited_host' : ORBITED_HOST,
                'orbited_port' : ORBITED_PORT,
                'server_host' :  request.get_host()}
    return render_to_response(template_file,mappings, context_instance=RequestContext(request))
 def run(self):        
     while True:       
         try:
             data = self.socket.recv(self.MAX_LENGTH)
             msg = repr(data)            
             logging.info('Received a Message: ' + msg)
             msg = msg.strip("'")
             if not msg.startswith(EventMessage.MSG_HEAD_TOKEN):
                 Comet.push_message(msg)
         except socket.error, e:
             sys.stderr.write('Error whilst listening for events: ' + e.__str__() + '\n')
             sys.stderr.write('Exiting event listener thread\n')
             
             logging.error(e.__str__())
             logging.error('Exiting event listener thread')
             break
def send_message(request):
    if request.GET.has_key('message'):
        message = request.GET['message']
    else:
        logging.warning('Couldnt find message value in GET request')


    builder = EventMessageBuilder()
    
    builder.event_type = EventType.EVENT
    builder.event_name = EventList.TEXT_MESSAGE
    builder.client_name = 'tux'
    builder.event_destination = 'client1'
    builder.event_content = EventMessage.MSG_ARG_DELIM + message + EventMessage.MSG_ARG_DELIM

    success, err_msg = EM_INTERFACE.send_raw_string(builder.build().toString())
    
    if not success:
        # Send error message to client!
        Comet.push_message('Error sending message: ' + err_msg)
    else:
        return HttpResponse("OK")