Skip to content

Commit

Permalink
Merge pull request #140 from lahirumenik/main
Browse files Browse the repository at this point in the history
all microservices completed -few to be checked
  • Loading branch information
lahirumenik authored Jan 28, 2024
2 parents 2e42e39 + a8245b0 commit 6eeff38
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 5 deletions.
72 changes: 72 additions & 0 deletions backend/serverless/Lambda/firesocket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const { ApiGatewayManagementApiClient, PostToConnectionCommand } = require("@aws-sdk/client-apigatewaymanagementapi");
const { DynamoDBClient, GetItemCommand } = require("@aws-sdk/client-dynamodb");
const dbclient = new DynamoDBClient()

const ENDPOINT = 'https://9c0zh8p4oj.execute-api.ap-southeast-1.amazonaws.com/beta/';

const client = new ApiGatewayManagementApiClient({ endpoint: ENDPOINT });

exports.handler = async (event, context) => {
try {
const fireresult = event;


const gyroy = fireresult.fire;
const gunid = fireresult.gunid;


const playerParams = {
"TableName": 'arcombat-gunid',
"Key": {
"gunid": {"S": gunid},

}
};


const commandPlayer = new GetItemCommand(playerParams);

const playerResponse = await dbclient.send(commandPlayer);
const email = playerResponse.Item.email.S;
// const email = "[email protected]"

const playerIdParams = {
"TableName": 'Arcombat-socket',
"Key": {
"email": {"S": email},

}
};

const commandplayerId = new GetItemCommand(playerIdParams);
const responseplayerId = await dbclient.send(commandplayerId);
const playerId = responseplayerId.Item.connectionid.S;





// console.log(event);
const Msg = {
// Data : hitsocketmsg,
Data: "fire",
ConnectionId: playerId
};




const commandSend = new PostToConnectionCommand(Msg);
await client.send(commandSend);


return "success"
} catch (error) {
console.error('Error:', error);

return {
statusCode: 500,
body: JSON.stringify('Error starting connectio.')
};
}
};
10 changes: 5 additions & 5 deletions backend/serverless/Lambda/gunsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const client = new ApiGatewayManagementApiClient({ endpoint: ENDPOINT });
exports.handler = async (event, context) => {
try {
const gunresult = event;
const screenshot = gunresult.screenshot;
const gyrox = gunresult.gyrox;


//horzontal cumulative roll -- need to be fixed
//const gyrox = gunresult.gyrox;

const gyroy = gunresult.gyroy;
const gunid = gunresult.gunid;
console.log(event)
Expand All @@ -23,9 +26,6 @@ exports.handler = async (event, context) => {

}
};





const commandPlayer = new GetItemCommand(playerParams);
Expand Down
91 changes: 91 additions & 0 deletions backend/serverless/Lambda/healthammo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const { ApiGatewayManagementApiClient, PostToConnectionCommand } = require("@aws-sdk/client-apigatewaymanagementapi");
const { DynamoDBClient, GetItemCommand } = require("@aws-sdk/client-dynamodb");
const { IoTDataPlaneClient, PublishCommand } = require("@aws-sdk/client-iot-data-plane");
const dbclient = new DynamoDBClient()
const iotclient = new IoTDataPlaneClient();

const ENDPOINT = 'https://9c0zh8p4oj.execute-api.ap-southeast-1.amazonaws.com/beta/';

const client = new ApiGatewayManagementApiClient({ endpoint: ENDPOINT });

exports.handler = async (event, context) => {
try {
const result = event;
const ammo = result.ammo;
const health = result.health;
const gunid = fireresult.ssid;

var numericPart = gunid[3];
var topic = "gun/"+numericPart+"/healthammo";


const msg =JSON.stringify({
"health":health,
'ammo':ammo
})

const input = { // PublishRequest
topic: topic,

payload: msg,

};


const command = new PublishCommand(input);
const response = await client.send(command)

const playerParams = {
"TableName": 'arcombat-gunid',
"Key": {
"gunid": {"S": gunid},

}
};


const commandPlayer = new GetItemCommand(playerParams);

const playerResponse = await dbclient.send(commandPlayer);
const email = playerResponse.Item.email.S;
// const email = "[email protected]"

const playerIdParams = {
"TableName": 'Arcombat-socket',
"Key": {
"email": {"S": email},

}
};

const commandplayerId = new GetItemCommand(playerIdParams);
const responseplayerId = await dbclient.send(commandplayerId);
const playerId = responseplayerId.Item.connectionid.S;




// console.log(event);
const Msg = {
// Data : hitsocketmsg,
Data: msg,
ConnectionId: playerId
};




const commandSend = new PostToConnectionCommand(Msg);
await client.send(commandSend);


return "success"
} catch (error) {
console.error('Error:', error);

return {
statusCode: 500,
body: JSON.stringify('Error starting connectio.')
};
}
};

0 comments on commit 6eeff38

Please sign in to comment.