Skip to content

Commit

Permalink
Revert "feat/real-time-overhaul with screenshare, bugfixes, improveme…
Browse files Browse the repository at this point in the history
…nts (#23)"

This reverts commit 68bb787.
  • Loading branch information
andreido committed Jun 28, 2024
1 parent 68bb787 commit f871a14
Show file tree
Hide file tree
Showing 417 changed files with 20,494 additions and 51,341 deletions.
113 changes: 29 additions & 84 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions THIRD-PARTY-LICENSES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The Amazon IVS UGC Web Demo includes the following third-party software/licensin
* web-ui/src/assets/icons/expand-screen.svg
* web-ui/src/assets/icons/fact-check.svg
* web-ui/src/assets/icons/favorite.svg
* web-ui/src/assets/icons/feed.svg
* web-ui/src/assets/icons/fullscreen-exit.svg
* web-ui/src/assets/icons/fullscreen.svg
* web-ui/src/assets/icons/home.svg
Expand Down
19 changes: 9 additions & 10 deletions cdk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ RESET := \033[0m

.PHONY: help app install bootstrap deploy destroy clean

AWS_PROFILE_FLAG = --profile $(AWS_PROFILE)
STAGE ?= dev
PUBLISH ?= false
STACK ?= UGC-$(STAGE)
COGNITO_CLEANUP_SCHEDULE ?= rate(48 hours)
STAGE_CLEANUP_SCHEDULE ?= rate(24 hours)
CDK_OPTIONS = $(if $(AWS_PROFILE),$(AWS_PROFILE_FLAG)) -c stage=$(STAGE) -c publish=$(PUBLISH) -c stackName=$(STACK) -c cognitoCleanupScheduleExp="$(strip $(COGNITO_CLEANUP_SCHEDULE))" -c stageCleanupScheduleExp="$(strip $(STAGE_CLEANUP_SCHEDULE))"
FE_DEPLOYMENT_STACK = UGC-Frontend-Deployment-$(STAGE)
SEED_COUNT ?= 50
OFFLINE_SESSION_COUNT ?= 1
AWS_PROFILE_FLAG = --profile $(AWS_PROFILE)
STAGE ?= dev
PUBLISH ?= false
STACK ?= UGC-$(STAGE)
SCHEDULE ?= rate(48 hours)
CDK_OPTIONS = $(if $(AWS_PROFILE),$(AWS_PROFILE_FLAG)) -c stage=$(STAGE) -c publish=$(PUBLISH) -c stackName=$(STACK) -c scheduleExp="$(strip $(SCHEDULE))"
FE_DEPLOYMENT_STACK = UGC-Frontend-Deployment-$(STAGE)
SEED_COUNT ?= 50
OFFLINE_SESSION_COUNT ?= 1

help: ## Shows this help message
@echo "\n$$(tput bold)Available Rules:$$(tput sgr0)\n"
Expand Down
48 changes: 1 addition & 47 deletions cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The outcome of the seed command above is 50 new channels and streams, 20 of thes
make seed JSON=./seed.example.json
```

***NOTE:** Please refer to the [seed.example.json file](./seed.example.json) so that you may create data that the DynamoDB client can use. Incorrect JSON data will lead to errors when seeding.*
**\*NOTE:** Please refer to the [seed.example.json file](./seed.example.json) so that you may create data that the DynamoDB client can use. Incorrect JSON data will lead to errors when seeding.\*

All the environment variables can be used together to generate mock data that suites your needs:

Expand Down Expand Up @@ -82,49 +82,3 @@ When the postStreamEvents function receives an event with a `session created` ev
When a `session ended` event is received, the corresponding stream record is grabbed and updated by removing the `isOpen` attribute.

You can find the Stream events API code in the `/streamEventsApi` folder.

## Scheduled resource cleanup AWS Lambdas

The scheduled resource cleanup lambdas are created when the stack is deployed. No additional steps are necessary to set up and trigger these functions. The lambda functions exist in the `cdk/lambdas` folder. The schedule can be customized in the `cdk/Makefile`. AWS Lambda supports standard rate and cron expressions for frequencies of up to once per minute. Read more about [schedule expressions using rate or cron](https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents-expressions.html).

### Amazon IVS idle stages cleanup

The cleanup lambda function follows these steps:
1. It retrieves a list of all stages
2. The `getIdleStageArn` helper function is employed to filter out idle stages that have been in existence for at least 1 hour
3. Subsequently, the filtered idle stages are deleted.

### Amazon Cognito unverified users cleanup

The cleanup lambda function follows these steps:
1. It retrieves a list of users with a `UNCONFIRMED` status
2. Within the unconfirmed users, we filter for users that have existed for at least 24 hours
3. Finally, the filtered unverified and expired users are deleted both from the Cognito user pool and AWS DynamoDB channels table.


## Amazon IVS Real-time host disconnect event handler

Amazon IVS host disconnect event cleanup is designed to delete active stages for which hosts have been disconnected from the session for at least 3 minutes. Upon a host's disconnection from a stage, the responsible endpoint follows these steps:
1. Extracts the host's channel ID from the request body, accommodating both object and JSON string formats
2. It retrieves the corresponding host details, including the stage and session, and formats them into a message body
3. This structured data is sent to an Amazon SQS queue for additional processing. It's important to highlight that the message comes with a 3-minute delay, allowing the host sufficient time to rejoin if they choose to
4. After 3-minute wait time, SQS triggers deleteStage lambda function.

### Amazon IVS Real-time host disconnect event cleanup triggers

This flow is triggered by:
1. Beacon API [Beacon API documention](https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API)
2. Stage participantConnectionChangedEvent event [STAGE_CONNECTION_STATE_CHANGED](https://aws.github.io/amazon-ivs-web-broadcast/docs/sdk-reference/enums/StageEvents#stage_connection_state_changed)
3. EventBridge
4. SQS [Amazon FIFO SQS](#amazon-fifo-sqs)

### Amazon IVS real-time host disconnect event lamnda cleanup

The cleanup lambda function follows these steps:
1. Lambda receives a message from the SQS queue
2. Checks if the host is present in the stage for potential reconnection
3. If the host is not detected in the stage, deletes the stage
4. Updates the channel table to reflect changes such as the removal/nullification of the stageId and stageCreationDate fields.

### Amazon FIFO SQS
A FIFO queue using content body for message deduplication and a 3-minute delayed delivery, allowing the host sufficient time to rejoin if they choose to.
46 changes: 0 additions & 46 deletions cdk/api/__mocks__/userInfo.json

This file was deleted.

3 changes: 0 additions & 3 deletions cdk/api/buildServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import channelRouters from './channel';
import channelsRouters from './channels';
import metricsRouter from './metrics/';
import productsRouters from './product';
import stagesRouter from './stages';

import configureRoute from './shared/hooks/configureRoute';
import { MAX_SERVER_PARAM_LENGTH } from './shared/constants';
Expand Down Expand Up @@ -50,8 +49,6 @@ const buildServer = () => {
// Create /products authenticated resources
server.register(productsRouters, { prefix: 'products' });
}

server.register(stagesRouter, { prefix: 'stages' });
}

if (['all', 'metrics'].includes(serviceName)) {
Expand Down
4 changes: 4 additions & 0 deletions cdk/api/channel/authRouter/__tests__/banUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {
GetItemCommandOutput,
UpdateItemCommand
} from '@aws-sdk/client-dynamodb';
import {
DisconnectUserCommand,
SendEventCommand
} from '@aws-sdk/client-ivschat';
import { mockClient } from 'aws-sdk-client-mock';

import buildServer from '../../../buildServer';
Expand Down
2 changes: 1 addition & 1 deletion cdk/api/channel/authRouter/addToFollowingList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getChannelId
} from '../../shared/helpers';
import { getUser, getUserByUsername } from '../helpers';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';

export const getFollowingChannelArn = async ({
reply,
Expand Down
21 changes: 16 additions & 5 deletions cdk/api/channel/authRouter/banUser.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { FastifyReply, FastifyRequest } from 'fastify';
import { convertToAttr, unmarshall } from '@aws-sdk/util-dynamodb';
import {
DisconnectUserCommand,
SendEventCommand
} from '@aws-sdk/client-ivschat';
import { UpdateItemCommand } from '@aws-sdk/client-dynamodb';

import { dynamoDbClient, getUserByChannelArn } from '../../shared/helpers';
import {
dynamoDbClient,
getUserByChannelArn,
isIvsChatError,
ivsChatClient
} from '../../shared/helpers';
import { getUser } from '../helpers';
import {
UNEXPECTED_EXCEPTION,
BAN_USER_EXCEPTION,
USER_NOT_FOUND_EXCEPTION
} from '../../shared/constants';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';

type BanUserRequestBody = { bannedChannelArn?: string };

Expand All @@ -21,7 +30,7 @@ const handler = async (
'user'
) as UserContext;
const { bannedChannelArn } = request.body;
let chatRoomOwnerChannelArn;
let chatRoomArn, chatRoomOwnerChannelArn, bannedUsername;

// Check input
if (!bannedChannelArn) {
Expand All @@ -37,7 +46,8 @@ const handler = async (
// Retrieve the chat room data for the requester's channel
try {
const { Item: UserItem = {} } = await getUser(sub);
({ channelArn: chatRoomOwnerChannelArn } = unmarshall(UserItem));
({ chatRoomArn, channelArn: chatRoomOwnerChannelArn } =
unmarshall(UserItem));

// Disallow users from banning themselves from their own channel
if (bannedChannelArn === chatRoomOwnerChannelArn) {
Expand Down Expand Up @@ -73,7 +83,8 @@ const handler = async (
}

// Add the bannedUserSub to the bannedUserSubs set in the user table
const { id: bannedUserSub } = unmarshall(BannedUserItems[0]);
const { id: bannedUserSub, username } = unmarshall(BannedUserItems[0]);
bannedUsername = username;

await dynamoDbClient.send(
new UpdateItemCommand({
Expand Down
2 changes: 1 addition & 1 deletion cdk/api/channel/authRouter/changeUserPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FastifyReply, FastifyRequest } from 'fastify';
import { CHANGE_USER_PREFERENCES_EXCEPTION } from '../../shared/constants';
import { updateDynamoItemAttributes } from '../../shared/helpers';
import { processAssetPreference, Preference } from '../helpers';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';

interface ChangeUserPreferencesRequestBody {
[key: string]: Preference;
Expand Down
2 changes: 1 addition & 1 deletion cdk/api/channel/authRouter/changeUsername.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ResponseBody,
updateDynamoItemAttributes
} from '../../shared/helpers';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';

type ChangeUsernameRequestBody = { newUsername: string | undefined };

Expand Down
17 changes: 3 additions & 14 deletions cdk/api/channel/authRouter/createResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import { CreateRoomCommand } from '@aws-sdk/client-ivschat';
import { FastifyReply, FastifyRequest } from 'fastify';

import { generateDeterministicId, getUser } from '../helpers';
import {
CHANNELS_TABLE_STAGE_FIELDS,
UNEXPECTED_EXCEPTION
} from '../../shared/constants';
import { UNEXPECTED_EXCEPTION } from '../../shared/constants';
import {
ivsChatClient,
ivsClient,
updateDynamoItemAttributes,
getChannelId
} from '../../shared/helpers';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';

type CreateResourcesRequestBody = { email: string | undefined };

Expand Down Expand Up @@ -101,15 +98,7 @@ const handler = async (
{ key: 'playbackUrl', value: playbackUrl },
{ key: 'streamKeyArn', value: streamKeyArn },
{ key: 'streamKeyValue', value: streamKeyValue },
{ key: 'trackingId', value: trackingId },
{
key: CHANNELS_TABLE_STAGE_FIELDS.USER_STAGE_ID,
value: null
},
{
key: CHANNELS_TABLE_STAGE_FIELDS.STAGE_CREATION_DATE,
value: null
}
{ key: 'trackingId', value: trackingId }
],
primaryKey: { key: 'id', value: sub },
tableName: process.env.CHANNELS_TABLE_NAME as string
Expand Down
2 changes: 1 addition & 1 deletion cdk/api/channel/authRouter/deleteChannelAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { deleteS3Object, getUser } from '../helpers';
import { dynamoDbClient } from '../../shared/helpers';
import { UpdateItemCommand } from '@aws-sdk/client-dynamodb';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';

interface DeleteChannelAssetRequestBody {
assetType: string;
Expand Down
2 changes: 1 addition & 1 deletion cdk/api/channel/authRouter/deleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { unmarshall } from '@aws-sdk/util-dynamodb';
import { ACCOUNT_DELETION_EXCEPTION } from '../../shared/constants';
import { cognitoClient, ivsChatClient, ivsClient } from '../../shared/helpers';
import { deleteS3ObjectsWithPrefix, deleteUser, getUser } from '../helpers';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';

const handler = async (request: FastifyRequest, reply: FastifyReply) => {
const { sub, username } = request.requestContext.get('user') as UserContext;
Expand Down
2 changes: 1 addition & 1 deletion cdk/api/channel/authRouter/generateImagePresignedPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UNEXPECTED_EXCEPTION
} from '../../shared/constants';
import { generatePresignedPost, getUser } from '../helpers';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';

type ASSET_TYPE = (typeof ALLOWED_CHANNEL_ASSET_TYPES)[number];
type CONTENT_TYPE = (typeof ALLOWED_IMAGE_CONTENT_TYPES)[number];
Expand Down
10 changes: 3 additions & 7 deletions cdk/api/channel/authRouter/getFollowingChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
StreamSessionDbRecord
} from '../../shared/helpers';
import { UNEXPECTED_EXCEPTION } from '../../shared/constants';
import { UserContext } from '../../shared/authorizer';
import { UserContext } from '../authorizer';
import { getUser } from '../helpers';
import { buildChannelArn } from '../../metrics/helpers';
import { convertToAttr, unmarshall } from '@aws-sdk/util-dynamodb';
Expand Down Expand Up @@ -162,13 +162,9 @@ const handler = async (request: FastifyRequest, reply: FastifyReply) => {
responseBody.channels = unmarshalledFollowingChannelItems.reduce<
ChannelData[]
>((acc, channel) => {
const { avatar, color, username, channelAssets, isLive, stageId } =
channel;
const { avatar, color, username, channelAssets, isLive } = channel;
const channelAssetUrls = getChannelAssetUrls(channelAssets);
return [
...acc,
{ avatar, color, username, channelAssetUrls, isLive, stageId }
];
return [...acc, { avatar, color, username, channelAssetUrls, isLive }];
}, []);
}
} catch (error) {
Expand Down
51 changes: 0 additions & 51 deletions cdk/api/channel/authRouter/getLiveStatus.ts

This file was deleted.

Loading

0 comments on commit f871a14

Please sign in to comment.