示例#1
0
def on_connect(request, socket, context):
    profile = Profile.objects.get(user__username=request.user.username)
    profile.socketsession = socket.session.session_id
    profile.save()
    print profile.socketsession
    send(socket.session.session_id, {
        "action": "connected",
        "message": profile.user.username
    })
示例#2
0
def message(request, socket, context, message):
    room = get_object_or_404(Room, name=message["room"])
    if room:
        MessageInstEvent.objects.create(room=room,
                                        user_from=request.user,
                                        msg=message["message"],
                                        date_pub=timezone.now())

        message["message"] = strip_tags(message["message"])
        message["name"] = request.user.username
        try:
            socket.send_and_broadcast_channel(message)
        except NoSocket as e:
            send(socket.session.session_id,
                 {"error": "No connected sockets exist"})
    else:
        send(socket.session.session_id, {"error": "Room not exits"})
示例#3
0
def offer(request, socket, context, message):
    room = RoomCall.objects.get(name=message['room'])
    profile = Profile.objects.get(user__username=message["user_to"])

    try:
        print 'Sending offer to: ' + profile.user.username + " " + profile.socketsession
        send(
            profile.socketsession, {
                'action': "offer",
                'offer': message['offer'],
                'user_from': message["user_from"],
                "room": room.name,
            })
    except NoSocket as e:
        send(socket.session.session_id, {
            "action": "error",
            "message": "No connected sockets exist"
        })
示例#4
0
def call(request, socket, context, message):
    profile = Profile.objects.get(user__username=message["user_to"])
    room = RoomCall.objects.get(name=message['room'])

    if profile:
        send(
            profile.socketsession, {
                "action": "call_join_request",
                "user_from": message["user_from"],
                "user_to": message["user_to"],
                'avatar': profile.image.url,
                "room": room.name
            })
    else:
        send(socket.session.session_id, {
            "action": "call_failed",
            "message": "No connected sockets exist"
        })
示例#5
0
def callaccept(request, socket, context, message):
    room = RoomCall.objects.get(name=message['room'])
    serializer = ProfileSerializer(room.users.all(), many=True)
    users = json.dumps(serializer.data)
    profile = Profile.objects.get(user__username=message["user_from"])
    send(
        profile.socketsession, {
            "action": "user_list",
            "room": room.name,
            "user_from": request.user.username,
            "users": users
        })
    for item in room.users.all():

        try:
            print 'Sending begin to: ' + item.user.username + " " + item.socketsession
            send(
                item.socketsession, {
                    "action": "join",
                    "room": room.name,
                    "user_from": message["user_from"],
                    "users": users
                })
        except NoSocket as e:
            send(socket.session.session_id, {
                "action": "error",
                "message": "No connected sockets exist"
            })
示例#6
0
def message(request, socket, context, message):
    print message
    if message['action'] == "message":
        user_from = User.objects.get(username=message["user_from"])
        if request.user.is_authenticated and user_from:

            try:
                profile = Profile.objects.get(
                    user__username=message["user_to"])
                msg = MessageInstEvent.objects.create(user_to=profile.user,
                                                      user_from=user_from,
                                                      msg=message["message"],
                                                      type="message_int_event")
                message["action"] = "message"
                message["user_to"] = profile.user.username
                message["user_from"] = user_from.username
                message["date_pub"] = str(msg.date_pub.isoformat())
                send(profile.socketsession, message)
            except NoSocket as e:
                send(socket.session.session_id, {
                    "action": "error",
                    "message": "No connected sockets exist"
                })
示例#7
0
def subcribe(request, socket, context, channel):
    room = get_object_or_404(Room, name=channel)
    if room:

        try:
            send(socket.session.session_id, {"message": "Welcome"})
            joined = {
                "action": "join",
                "name": request.user.username,
                "id": request.user.id
            }
            socket.send_and_broadcast_channel(joined, channel)
        except NoSocket as e:
            send(socket.session.session_id,
                 {"error": "No connected sockets exist"})
    else:
        send(socket.session.session_id, {"error": "Room not exits"})
示例#8
0
def connection(request, socket, context):
	print "connection made successfully"
	send(socket.session.session_id, "Hello, new connection is established successfully")