in backend/sendchatlayer/index.js [94:143]
async function getData(msg) {
let connectionData;
let parms;
switch (msg.action) {
case 'chat':
//deprecated
break;
case 'liveadmin':
// send the received question to all in the gametable
const lapk = msg.gameId +'#'+msg.playerName;
parms = {
TableName: playersTableName,
ProjectionExpression: 'connectionId',
KeyConditionExpression: '#f1 = :v1 and begins_with(#f2, :v2)',
ExpressionAttributeValues: { ':v1': lapk, ':v2': 'PLAYER' },
ExpressionAttributeNames: { '#f1': 'pk', '#f2': 'sk' },
ConsistentRead: true,
};
try {
connectionData = await ddb.query(parms).promise();
} catch (e) {
console.error(`Error getting liveadmin connection data ${JSON.stringify(e)}`);
return { statusCode: 500, body: 'Error getting live connection data' };
}
break;
case 'liveplayer':
// send only to host
const lppk = msg.gameId + '#' + msg.hostname;
parms = {
TableName: playersTableName,
ProjectionExpression: 'connectionId',
KeyConditionExpression: '#f1 = :v1 and begins_with(#f2, :v2)',
ExpressionAttributeValues: { ':v1': lppk, ':v2': 'HOST' },
ExpressionAttributeNames: { '#f1': 'pk', '#f2': 'sk' },
ConsistentRead: true,
};
try {
connectionData = await ddb.query(parms).promise();
} catch (e) {
console.error(`Error getting liveplayer connection data ${JSON.stringify(e)}`);
return { statusCode: 500, body: 'Error getting liveplayer connection data' };
}
break;
default:
console.error(`Case not defined for ${msg.action}`);
break;
}
return connectionData;
}