generated from cepdnaclk/eYY-3yp-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from lahirumenik/main
all microservices completed -few to be checked
- Loading branch information
Showing
3 changed files
with
168 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | ||
}; | ||
} | ||
}; |