Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
402 changes: 128 additions & 274 deletions abovevttServices/app.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions abovevttServices/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "abovevttServices",
"version": "1.0.0",
"description": "Various HTTP Services",
"main": "src/app.js",
"main": "app.js",
"author": "Daniele Martini",
"license": "AGPLv3",
"dependencies": {
"aws-sdk": "^2.690.0"
"@aws-sdk/client-dynamodb": "^3",
"@aws-sdk/lib-dynamodb": "^3"
}
}
10 changes: 5 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ChatAppStack extends Stack {
code: new AssetCode("./abovevttServices"),
architecture: Architecture.X86_64,
handler: "app.handler",
runtime: Runtime.NODEJS_12_X,
runtime: Runtime.NODEJS_22_X,
timeout: Duration.seconds(30),
memorySize: 256,
environment: {
Expand All @@ -98,7 +98,7 @@ class ChatAppStack extends Stack {
const connectFunc = new Function(this, "connect-lambda", {
code: new AssetCode("./onconnect"),
handler: "app.handler",
runtime: Runtime.NODEJS_12_X,
runtime: Runtime.NODEJS_22_X,
timeout: Duration.seconds(30),
memorySize: 256,
environment: {
Expand All @@ -110,7 +110,7 @@ class ChatAppStack extends Stack {
const disconnectFunc = new Function(this, "disconnect-lambda", {
code: new AssetCode("./ondisconnect"),
handler: "app.handler",
runtime: Runtime.NODEJS_12_X,
runtime: Runtime.NODEJS_22_X,
timeout: Duration.seconds(30),
memorySize: 256,
environment: {
Expand All @@ -122,15 +122,15 @@ class ChatAppStack extends Stack {
const keepaliveFunc = new Function(this, "keepalive-lambda", {
code: new AssetCode("./keepalive"),
handler: "app.handler",
runtime: Runtime.NODEJS_12_X,
runtime: Runtime.NODEJS_22_X,
timeout: Duration.seconds(2),
memorySize: 128,
});

const messageFunc = new Function(this, "message-lambda", {
code: new AssetCode("./sendmessage"),
handler: "app.handler",
runtime: Runtime.NODEJS_12_X,
runtime: Runtime.NODEJS_22_X,
timeout: Duration.seconds(30),
memorySize: 256,
initialPolicy: [
Expand Down
2 changes: 0 additions & 2 deletions keepalive/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const AWS = require('aws-sdk');

exports.handler = async event => {
return { statusCode: 200, body: 'Connected.' };
};
7 changes: 2 additions & 5 deletions keepalive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "keepalive",
"version": "1.0.0",
"description": "AboveVTT Keepalive",
"main": "src/app.js",
"main": "app.js",
"author": "Daniele Martini",
"license": "AGPLv3",
"dependencies": {
"aws-sdk": "^2.690.0"
}
"license": "AGPLv3"
}
31 changes: 11 additions & 20 deletions onconnect/app.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
const { DynamoDBDocumentClient, PutCommand } = require('@aws-sdk/lib-dynamodb');

const AWS = require('aws-sdk');

const ddb = new AWS.DynamoDB.DocumentClient({ apiVersion: '2012-08-10', region: process.env.AWS_REGION });
const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({ region: process.env.AWS_REGION }));

exports.handler = async event => {
const campaignId = event.queryStringParameters ? event.queryStringParameters.campaign : "";
const isDM = event.queryStringParameters && event.queryStringParameters.DM;

const campaignId=event.queryStringParameters?event.queryStringParameters.campaign:"";

const isDM=event.queryStringParameters && event.queryStringParameters.DM;
const objectId = isDM
? "conn#DM#" + event.requestContext.connectionId
: "conn#PLAYERS#" + event.requestContext.connectionId;

console.log("Adding " + objectId + " to " + campaignId);

let objectid="";
if(isDM){
objectId="conn#DM#"+event.requestContext.connectionId;
}
else{
objectId="conn#PLAYERS#"+event.requestContext.connectionId;
}
console.log("Adding "+objectId +" to "+campaignId);
const putParams = {
TableName: process.env.TABLE_NAME,
Item: {
campaignId: campaignId,
objectId: objectId,
connectionId: event.requestContext.connectionId,
timestamp: Date.now(),
}
},
};

try {
let result = await ddb.put(putParams).promise();
console.log("done?");
console.log(result);
await ddb.send(new PutCommand(putParams));
} catch (err) {
return { statusCode: 500, body: 'Failed to connect: ' + JSON.stringify(err) };
}
Expand Down
5 changes: 3 additions & 2 deletions onconnect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "on-connect",
"version": "1.0.0",
"description": "AboveVTT on Player Connected",
"main": "src/app.js",
"main": "app.js",
"author": "Daniele Martini",
"license": "AGPLv3",
"dependencies": {
"aws-sdk": "^2.690.0"
"@aws-sdk/client-dynamodb": "^3",
"@aws-sdk/lib-dynamodb": "^3"
}
}
33 changes: 14 additions & 19 deletions ondisconnect/app.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

// https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-route-keys-connect-disconnect.html
// The $disconnect route is executed after the connection is closed.
// The connection can be closed by the server or by the client. As the connection is already closed when it is executed,
// $disconnect is a best-effort event.
// The connection can be closed by the server or by the client. As the connection is already closed when it is executed,
// $disconnect is a best-effort event.
// API Gateway will try its best to deliver the $disconnect event to your integration, but it cannot guarantee delivery.

const AWS = require('aws-sdk');
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
const { DynamoDBDocumentClient, QueryCommand, DeleteCommand } = require('@aws-sdk/lib-dynamodb');

const ddb = new AWS.DynamoDB.DocumentClient({ apiVersion: '2012-08-10', region: process.env.AWS_REGION });
const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({ region: process.env.AWS_REGION }));

exports.handler = async event => {
console.log("trying to delete "+event.requestContext.connectionId);
console.log("trying to delete " + event.requestContext.connectionId);

const queryParams = {
TableName: process.env.TABLE_NAME,
IndexName: 'connectionIds',
KeyConditionExpression: "connectionId = :connectionId",
ExpressionAttributeValues: {
":connectionId": event.requestContext.connectionId
":connectionId": event.requestContext.connectionId,
},
};

let toDelete = await ddb.query(queryParams).promise();
const toDelete = await ddb.send(new QueryCommand(queryParams));

const deleting=toDelete.Items.map(async ({ campaignId,objectId }) => {
const deleteParams={
const deleting = toDelete.Items.map(async ({ campaignId, objectId }) => {
console.log("Deleting campaignId: " + campaignId + " objectId: " + objectId);
return ddb.send(new DeleteCommand({
TableName: process.env.TABLE_NAME,
Key: {
campaignId: campaignId,
objectId: objectId,
}
};
console.log("Deleting campaignId: "+campaignId+" objectId: "+objectId);
return ddb.delete(deleteParams).promise();
Key: { campaignId, objectId },
}));
});

try {
Expand Down
5 changes: 3 additions & 2 deletions ondisconnect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "on-disconnect",
"version": "1.0.0",
"description": "AboveVTT",
"main": "src/app.js",
"main": "app.js",
"author": "Daniele Martini",
"license": "AGPLv3",
"dependencies": {
"aws-sdk": "^2.690.0"
"@aws-sdk/client-dynamodb": "^3",
"@aws-sdk/lib-dynamodb": "^3"
}
}
Loading