Exemple #1
0
def lambda_handler(event, context):
    connection_id = ws.get_connection_id(event)
    clients_table.add(connection_id)
    logger.info('Connected: %s', connection_id)
    return {
        'statusCode': 200,
        'body': 'Success',
    }
def lambda_handler(event, context):
    connection_id = ws.get_connection_id(event)
    room_name = clients_table.clear_room(connection_id)
    if room_name is not None:
        logger.info('Client left room: connection_id=%s room_name=%s', connection_id, room_name)
        rooms_table.leave_room(room_name, connection_id)
    return {
        'statusCode': 200,
        'body': 'Success',
    }
def lambda_handler(event, context):
    connection_id = ws.get_connection_id(event)
    body = event['body']
    logger.info('Unknown message type from \'%s\': %s', connection_id, body)
    ws.send_message(connection_id, 'error', {
        'reason': f'Message body of \'{body}\' is invalid or contains an unknown message type'
    })
    return {
        'statusCode': 400,
        'body': 'Unknown message type',
    }
def lambda_handler(event, context):
    connection_id = ws.get_connection_id(event)
    room_name = clients_table.get_room(connection_id)

    if room_name is not None:
        payload = ws.get_message_payload(event)
        step = payload['step']

        new_state = jump_to(room_name, step)
        if new_state is not None:
            new_state = utils.replace_decimals(new_state)
            for room_connection_id in rooms_table.get_connection_ids(room_name):
                ws.send_message(room_connection_id, 'state', new_state)
    return {
        'statusCode': 200,
        'body': 'Success',
    }
Exemple #5
0
def lambda_handler(event, context):
    connection_id = ws.get_connection_id(event)
    payload = ws.get_message_payload(event)
    room_name = payload['room_name']

    old_room_name = clients_table.set_room(connection_id, room_name)
    if old_room_name is not None:
        logger.info('Client left room: connection_id=%s room_name=%s',
                    connection_id, old_room_name)
        rooms_table.leave_room(old_room_name, connection_id)

    room_state = rooms_table.join_room(room_name, connection_id)
    room_state = utils.replace_decimals(room_state)
    logger.info('Client joined room: connection_id=%s room_name=%s',
                connection_id, room_name)

    ws.send_message(connection_id, 'state', room_state)

    return {
        'statusCode': 200,
        'body': 'Success',
    }