-
Notifications
You must be signed in to change notification settings - Fork 0
Session 3 : Websockets #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: session-3-v2
Are you sure you want to change the base?
Conversation
@@ -14,18 +15,49 @@ export const createConnection = async ( | |||
endpoint: string, | |||
): Promise<void> => { | |||
// TODO insert a connection in the DynamoDB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu peux enlever ça du coup
@@ -14,18 +15,49 @@ export const createConnection = async ( | |||
endpoint: string, | |||
): Promise<void> => { | |||
// TODO insert a connection in the DynamoDB | |||
await documentClient | |||
.put({ | |||
TableName: 'dojo-serverless-table', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu peux mettre ça dans une constante
endpoint, | ||
}, | ||
}) | ||
.promise(); | ||
}; | ||
|
||
export const deleteConnection = async (connectionId: string): Promise<void> => { | ||
// TODO delete a connection from the DynamoDB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
@@ -7,11 +7,38 @@ import { Item } from '@libs/types'; | |||
import { Virus } from '../virus/types'; | |||
|
|||
const sendMessageToEachConnection = async (message: any): Promise<void> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pas une bonne pratique de typer en any
const sendMessageToEachConnection = async (message: any): Promise<void> => { | ||
// TODO use sendMessageToConnection for each connection | ||
// TODO use sendMessageToConnection for each connection | ||
const connections = await getAllConnections(); | ||
await Promise.all( | ||
connections.map(async ({ connectionId, endpoint }): Promise<void> => { | ||
await sendMessageToConnection({ connectionId, endpoint, message }); | ||
}), | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu peux sortir ça du handler du coup :)
const addVirus = async () => { | ||
const response = await fetch( | ||
`${process.env.REACT_APP_API_BASE_URL}/virus`, | ||
{ method: 'POST' }, | ||
); | ||
const { id } = await response.json(); | ||
setViruses((prevViruses) => prevViruses.concat(getRandomVirus(id))); | ||
// const response = | ||
await fetch(`${process.env.REACT_APP_API_BASE_URL}/virus`, { | ||
method: 'POST', | ||
}); | ||
// const { id } = await response.json(); | ||
// setViruses((prevViruses) => prevViruses.concat(getRandomVirus(id))); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu peux faire du ménage ici ;)
method: 'POST', | ||
}); | ||
// const { id } = await response.json(); | ||
// setViruses((prevViruses) => prevViruses.concat(getRandomVirus(id))); | ||
}; | ||
|
||
const killVirus = async (virusId: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que tu peux sortir ces fonctions de ta page (et je t'ai déjà fait le retour ;) )
Tu peux ignorer les changement liés aux alarmes, j'ai oublié de checkout sur une autre branche pour le faire