Exemplo n.º 1
0
def catch_up_new_member(data):
    print("[SOCKET.IO] received request to catch up new member", request.sid)
    room = data['channel']
    if room in all_clients_by_room and len(all_clients_by_room[room]) > 0:
        help_replica = None
        for replica in all_clients_by_room[room]:
            if replica != request.sid:
                help_replica = replica
                break

        def join_update_claimed_tracks_callback(data):
            print("[SOCKET.IO] found replica to catch up on claimed tracks:",
                  data)
            for user, track_id in data.items():
                if user:
                    print("[SOCKET.IO] > updating user:"******", track:",
                          track_id)
                    socketio.emit('updateClaimedTracks', {
                        'track_id': track_id,
                        'claimed_by': user
                    },
                                  room=request.sid)

        if help_replica != None:
            socketio.emit('retrieveCurrentClaimedTracks',
                          room=help_replica,
                          callback=join_update_claimed_tracks_callback)
Exemplo n.º 2
0
def immediate_group_stop(data):
    user = data["user"]
    room = data["channel"]
    print(
        f"[SOCKET.IO] received request to immediately stop from {user} to {room}"
    )
    print("[SOCKET.IO] emit group stop")
    socketio.emit('beginGroupStop', {'stopped_by': user}, to=room)
Exemplo n.º 3
0
def get_current_online_users(data):
    room = data['channel']
    user_list = []
    for user_id in all_clients_by_room[room]:
        user_list.append(client_names[user_id])
    print("[SOCKET.IO] emit online users: " + str(user_list))
    user_list.sort()
    socketio.emit('updateOnlineUsers', {'user_list': user_list},
                  room=request.sid)
Exemplo n.º 4
0
def broadcast_update_claimed_tracks(data):
    room = data["channel"]
    track_id = data["track_id"]
    claimed_by = data["claimed_by"]
    print(f"[SOCKET.IO] broadcast update claimed tracks for {room}")
    socketio.emit('updateClaimedTracks', {
        'track_id': track_id,
        'claimed_by': claimed_by
    },
                  to=room,
                  include_self=False)
Exemplo n.º 5
0
def immediate_group_record(data):
    print('[SOCKET.IO] received request to immediately group record: ' +
          str(data))
    room = data['channel']
    if room in prepared_record_by_room and prepared_record_by_room[
            room] == all_clients_by_room[room]:
        del prepared_record_by_room[room]
        print("[SOCKET.IO] emit group record")
        socketio.emit('beginGroupRecord', to=room)
        return
    print('[SOCKET.IO] insufficiently prepared clients: ' +
          str(prepared_record_by_room[room]))
Exemplo n.º 6
0
 def join_update_claimed_tracks_callback(data):
     print("[SOCKET.IO] found replica to catch up on claimed tracks:",
           data)
     for user, track_id in data.items():
         if user:
             print("[SOCKET.IO] > updating user:"******", track:",
                   track_id)
             socketio.emit('updateClaimedTracks', {
                 'track_id': track_id,
                 'claimed_by': user
             },
                           room=request.sid)
Exemplo n.º 7
0
def disconnected():
    print('[SOCKET.IO] client disconnected', request.sid)
    for room in list(prepared_play_by_room):
        if request.sid in prepared_play_by_room[room]:
            print("[SOCKET.IO] > removing client from prepared play | room",
                  room)
            prepared_play_by_room[room].remove(request.sid)
            socketio.emit('updateNumPrepared', {
                'num_prepared': len(prepared_play_by_room[room]),
                'action': "play"
            },
                          to=room)
        if len(prepared_play_by_room[room]) == 0:
            del prepared_play_by_room[room]

    for room in list(prepared_record_by_room):
        if request.sid in prepared_record_by_room[room]:
            print("[SOCKET.IO] > removing client from prepared record | room",
                  room)
            prepared_record_by_room[room].remove(request.sid)
            socketio.emit('updateNumPrepared', {
                'num_prepared': len(prepared_record_by_room[room]),
                'action': "record"
            },
                          to=room)
        if len(prepared_record_by_room[room]) == 0:
            del prepared_record_by_room[room]

    client_name_exists = request.sid in client_names
    for room in list(all_clients_by_room):
        if request.sid in all_clients_by_room[room]:
            print("[SOCKET.IO] > removing client from all | room", room)
            all_clients_by_room[room].remove(request.sid)
            if client_name_exists:
                socketio.emit('updateClaimedTracks', {
                    'track_id': None,
                    'claimed_by': client_names[request.sid]
                },
                              to=room,
                              include_self=False)

        user_list = []
        for user_id in all_clients_by_room[room]:
            user_list.append(client_names[user_id])
        print("[SOCKET.IO] emit online users: " + str(user_list))
        user_list.sort()
        socketio.emit('updateOnlineUsers', {'user_list': user_list}, to=room)
        print('[SOCKET.IO] all clients left:' + str(all_clients_by_room))

        # reset memoizing of room if no more clients left
        if len(all_clients_by_room[room]) == 0:
            del all_clients_by_room[room]

    if client_name_exists:
        del client_names[request.sid]
Exemplo n.º 8
0
def leave_project(data):
    username = data['user']
    room = data['channel']
    if room in all_clients_by_room and request.sid in all_clients_by_room[room]:
        print('###############################')
        print(f"[SOCKET.IO] LEAVE: {username} has left the project")
        leave_room(room)
        all_clients_by_room[room].remove(request.sid)
        print('[SOCKET.IO] updated all clients by room: ' +
              str(all_clients_by_room))
        print('###############################')
        user_list = []
        for user_id in all_clients_by_room[room]:
            user_list.append(client_names[user_id])
        print("[SOCKET.IO] emit online users: " + str(user_list))
        user_list.sort()
        socketio.emit('updateOnlineUsers', {'user_list': user_list}, to=room)

        # clean up
        if len(all_clients_by_room[room]) == 0:
            del all_clients_by_room[room]

    if room in prepared_record_by_room and request.sid in prepared_record_by_room[
            room]:
        print("[SOCKET.IO] > removing client from prepared record | room",
              room)
        prepared_record_by_room[room].remove(request.sid)
        socketio.emit('updateNumPrepared', {
            'num_prepared': len(prepared_record_by_room[room]),
            'action': "record"
        },
                      to=room)
        if len(prepared_record_by_room[room]) == 0:
            del prepared_record_by_room[room]

    if room in prepared_play_by_room and request.sid in prepared_play_by_room[
            room]:
        print("[SOCKET.IO] > removing client from prepared play | room", room)
        prepared_play_by_room[room].remove(request.sid)
        socketio.emit('updateNumPrepared', {
            'num_prepared': len(prepared_play_by_room[room]),
            'action': "play"
        },
                      to=room)
        if len(prepared_play_by_room[room]) == 0:
            del prepared_play_by_room[room]

    socketio.emit('updateClaimedTracks', {
        'track_id': None,
        'claimed_by': username
    },
                  to=room,
                  include_self=False)
Exemplo n.º 9
0
def cancel_request(data):
    room = data["channel"]
    print(
        f"[SOCKET.IO] cancelling request for {request.sid} in project {room}")
    if room in prepared_play_by_room and request.sid in prepared_play_by_room[
            room]:
        prepared_play_by_room[room].remove(request.sid)
        socketio.emit('updateNumPrepared', {
            'num_prepared': len(prepared_play_by_room[room]),
            'action': "play"
        },
                      to=room)
    elif room in prepared_record_by_room and request.sid in prepared_record_by_room[
            room]:
        prepared_record_by_room[room].remove(request.sid)
        socketio.emit('updateNumPrepared', {
            'num_prepared': len(prepared_record_by_room[room]),
            'action': "record"
        },
                      to=room)
    return True
Exemplo n.º 10
0
def prepare_group_play(data):
    print('[SOCKET.IO] received request to group play: ' + str(data))
    room = data['channel']
    if room not in prepared_play_by_room:
        prepared_play_by_room[room] = set()
    print('[SOCKET.IO] current prepared clients: ' +
          str(prepared_play_by_room[room]))
    prepared_play_by_room[room].add(request.sid)
    # if all clients are ready to play
    print('[SOCKET.IO] new prepared clients: ' +
          str(prepared_play_by_room[room]))
    print('[SOCKET.IO] all clients: ' + str(all_clients_by_room[room]))
    if prepared_play_by_room[room] == all_clients_by_room[room]:
        del prepared_play_by_room[room]
        print("[SOCKET.IO] emit group play")
        socketio.emit('beginGroupPlay', to=room)
        return True

    print("[SOCKET.IO] not ready to play yet")
    requester = client_names[
        request.sid] if request.sid in client_names else None
    socketio.emit('updateNumPrepared', {
        'num_prepared': len(prepared_play_by_room[room]),
        'action': "play"
    },
                  to=room)
    socketio.emit('notifyWaitingGroupMember', {
        'requester': requester,
        'action': "play",
        'num_prepared': len(prepared_play_by_room[room])
    },
                  to=room,
                  include_self=False)
    return False
Exemplo n.º 11
0
def join_project(data):
    username = data['user']
    room = data['channel']
    client_names[request.sid] = username
    print('###############################')
    print(f"[SOCKET.IO] JOIN: {username} has joined the project")
    join_room(room)
    if not room in all_clients_by_room:
        all_clients_by_room[room] = set()
    all_clients_by_room[room].add(request.sid)
    print('[SOCKET.IO] updated all clients by room:' +
          str(all_clients_by_room))
    print('###############################')
    user_list = []
    for user_id in all_clients_by_room[room]:
        if user_id in client_names:
            user_list.append(client_names[user_id])
    print("[SOCKET.IO] emit online users: " + str(user_list))
    user_list.sort()
    socketio.emit('updateOnlineUsers', {'user_list': user_list}, to=room)

    if room in prepared_record_by_room and len(
            prepared_record_by_room[room]) > 0:
        print("[SOCKET.IO] > update num prepared to client | room", room)
        socketio.emit('updateNumPrepared', {
            'num_prepared': len(prepared_record_by_room[room]),
            'action': "record"
        },
                      to=room)

    if room in prepared_play_by_room and len(prepared_play_by_room[room]) > 0:
        print("[SOCKET.IO] > update num prepared to client | room", room)
        socketio.emit('updateNumPrepared', {
            'num_prepared': len(prepared_play_by_room[room]),
            'action': "play"
        },
                      to=room)
Exemplo n.º 12
0
def broadcast_update_project(data):
    room = data["channel"]
    print(f"[SOCKET.IO] received broadcast update project for {room}")
    print("[SOCKET.IO] emit updateProject for DAW page")
    socketio.emit('updateProject', {'data': ''}, room=room)
Exemplo n.º 13
0
def broadcast_update_projects():
    print('[SOCKET.IO] received broadcast update projects')
    print("[SOCKET.IO] emit updateProjects for Projects page")
    socketio.emit('updateProjects', {'data': ''})
Exemplo n.º 14
0
def broadcast_update_groups():
    print('[SOCKET.IO] received broadcast update groups')
    print("[SOCKET.IO] emit updateGroups for Groups page")
    socketio.emit('updateGroups', {'data': ''})