Пример #1
0
def load_chat(request):
    key = request.GET.get('id')
    # request.session['chat_id'] = key
    try:
        # lookup            = (Ticket.objects.select_related('author').get(id = key))
        lookup = Ticket.objects.get(id = key)
        lookup.online = True
        t = lookup.save()
        if lookup.status != '4':
            if 'chat_id' not in request.session or not request.session['chat_id']:
                request.session['chat_id'] = [key]
            else:
                save_list = request.session['chat_id']
                if key not in save_list:
                    save_list.append(key)
                else:
                    pass
                request.session['chat_id'] = save_list
        else:
            del request.session['chat_id']

        resp = {'status': True, 'msg': 'success', 'key':lookup.id, 'message_info': '', }
        # broadcast_channel(lookup.id, channel="channel-"+str(lookup.assigned.user.id))
        data = {"agent": str(lookup.assigned.user), "id": lookup.id}
        broadcast_channel(data, channel="channel-"+str(lookup.assigned.user.id)) #broadcast / send message into agent channel
    except Exception, err:
        resp = {'status': False, 'msg': unicode(err), 'key':''}
Пример #2
0
def create(request, name):
    """
    Handles post from the "Add room" form, and
    redirects to the new room.
    """
    if request.user.username == name:
        c = {}
        c.update(csrf(request))
        if request.method == 'POST': # If the form has been submitted...
            id = request.POST.get("name")
	    usertocall = UserSocialAuth.objects.get(uid=id, provider='facebook') #Searching for the user to chat in db
	    if usertocall.user_id < request.user.id:
		x = usertocall.user_id
		y = request.user.id
	    else:
		x = request.user.id
		y = usertocall.user_id
	    date = re.sub("\D","",str(datetime.date.today()))
	    chatroomname = str(x)+"_"+str(y)+"_"+str(date)
            room, created = Call.objects.get_or_create(name=chatroomname)
            if created:
                print 'Room created :' 
                print room
            try:
            	if UserSocialAuth.objects.get(user__username=request.user.username, provider='facebook').uid == id:
            		print 'User joining'
            	else:
		    message = {"action": "gotoroom", "name": request.user.first_name+" "+request.user.last_name, "message": chatroomname}
                    broadcast_channel(message, channel='user-'+str(usertocall.user_id))
                    print message
            except NoSocket, e:
                print e
            return HttpResponseRedirect('/'+request.user.username+'/'+room.slug+'/')
        else:
            return HttpResponseRedirect('/')
Пример #3
0
def updateClientsData():
	print('updateClientsData()')
	try:
		broadcast_channel(prepareData(), channel='terminal')
		print('successfully send message !')
	except:
		getException(printout=True)
Пример #4
0
def testing2(request, socket, context, channel):
	to_send = {
		'id':socket.session.session_id, 
		'type':"connection"
	}

	print "someone connected"
	broadcast_channel(to_send, channel=channel)
Пример #5
0
def testing(reqest, socket, context, message):
	to_send = {
		"id" : socket.session.session_id,
		"type" : "new_object",
		"object" : message['object'],
		"channel" : message['room']
	}

	broadcast_channel(to_send, channel=message['room'])
Пример #6
0
def broadcast(request):
	global cells
	if len(cells) > 0:
		fd_id = request.POST["id"]
		remove_list = request.POST["remove"]

		shape = cells[int(fd_id)]
		try:
			broadcast_channel({ 'fd_id': fd_id, 'shape': shape.path, 'colour': shape.colour, 'transform': shape.transformation_matrix, "remove": remove_list } , "shapes")
		except NoSocket:
			logger.error("No subscribers on channel shapes")
	return HttpResponse()
Пример #7
0
def system_message(request, template="system_message.html"):
    context = {"rooms": ChatRoom.objects.all()}
    if request.method == "POST":
        room = request.POST["room"]
        data = {"action": "system", "message": request.POST["message"]}
        try:
            if room:
                broadcast_channel(data, channel="room-" + room)
            else:
                broadcast(data)
        except NoSocket, e:
            context["message"] = e
        else:
            context["message"] = "Message sent"
Пример #8
0
def system_message(request, template="chat/system_message.html"):
    context = {"rooms": ChatRoom.objects.all()}
    if request.method == "POST":
        room = request.POST["room"]
        data = {"action": "system", "message": request.POST["message"]}
        try:
            if room:
                broadcast_channel(data, channel="room-" + room)
            else:
                broadcast(data)
        except NoSocket, e:
            context["message"] = e
        else:
            context["message"] = "Message sent"
Пример #9
0
def broadcast_activity_handler(sender, **kwargs):
    """ Callback function for addedActivity signal
    It receives the activity newly added and sends it to global chat
    """
    a = kwargs.get('activity', None)
    if not a or not a.public:
        return

    message = u'<strong>%s</strong> %s' % (a.user_from.nickname, a.message)
    msg = dict(room='global', text=message, time=a.timestamp.strftime("%H:%M"), mess_type='activity', action='message')
    try:
        broadcast_channel(msg, 'global')
    except NoSocket:
        pass # fail silently
Пример #10
0
def ticket_resp(request):
    user = str(request.user)
    ticket_id = request.GET.get('id')

    if request.is_agent:
    	# assigned = AssignedUser.objects.create(user = request.user, timestamp = datetime.now())
    	get_ticket = Ticket.objects.get(id = ticket_id)
    	# get_ticket.assigned = assigned
        # get_ticket.status = '6'
    	# get_ticket.save()


    message = 'has ben joined chat'
    data = {"user": user, "message": message}
    broadcast_channel(data, channel="room-" + ticket_id)
    return HttpResponse('ok')
Пример #11
0
def system_message(request, template="system_message.html"):
    context = {"warehouses": Warehouse.objects.all()}
    if request.method == "POST":
        warehouse = request.POST["warehouse"]
        data = {"action": "system", "message": request.POST["message"]}
        try:
            if warehouse:
                broadcast_channel(data, channel="warehouse-" + warehouse)
                print "sending data" + data
                #arduino=ArduinoControl(data)
                #arduino.run()
            else:
                broadcast(data)
        except NoSocket, e:
            context["message"] = e
        else:
            context["message"] = "Message sent"
Пример #12
0
def printMessage(msg, eventType):
    text = "#{0} msg received: [{1}] => {2}/{3}\n{4}\n{5}\n{6}\n{7}".format(
        msg.getElement("EVENT_TIME") if msg.hasElement("EVENT_TIME") else "",
        ", ".join(map(str, msg.correlationIds())),
        EVENT_TYPE_NAMES[eventType],
        msg.messageType(),
        msg.numElements(),
        msg.getElement("MKTDATA_EVENT_TYPE") if msg.hasElement("MKTDATA_EVENT_TYPE") else "",
        msg.getElement("MKTDATA_EVENT_SUBTYPE") if msg.hasElement("MKTDATA_EVENT_SUBTYPE") else "",
        msg)
    print strftime("%H:%M:%S",gmtime()), msg.getElement("EVENT_TIME") if msg.hasElement("EVENT_TIME") else ""
    room = "1"
    data = {"room" : room,"action": "message", "message": text}

    try:
        broadcast_channel(data, channel="room-"+room)
    except NoSocket, e:
        print "NO SOCKET: " + room, e
Пример #13
0
def broadcast(request):
    global cells
    if len(cells) > 0:
        fd_id = request.POST["id"]
        remove_list = request.POST["remove"]

        shape = cells[int(fd_id)]
        try:
            broadcast_channel(
                {
                    "fd_id": fd_id,
                    "shape": shape.path,
                    "colour": shape.colour,
                    "transform": shape.transformation_matrix,
                    "remove": remove_list,
                },
                "shapes",
            )
        except NoSocket:
            logger.error("No subscribers on channel shapes")
    return HttpResponse()
Пример #14
0
def chat_api(data, channel):
    broadcast_channel(data, channel)
Пример #15
0
def my_chat_handler(request, socket, context, message):
  django_socketio.broadcast_channel(message, 'lobby')