-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
34 lines (26 loc) · 887 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { LambdaActions } from 'lambda-actions';
import { $connect, $disconnect, setName, sendPublic, sendPrivate } from './actions';
export const handler = async (event, context) => {
if (!event.requestContext) {
return {};
}
try {
const connectionId = event.requestContext.connectionId;
const routeKey = event.requestContext.routeKey;
const body = JSON.parse(event.body || '{}');
const lambdaActions = new LambdaActions();
lambdaActions.action('$connect', $connect);
lambdaActions.action('$disconnect', $disconnect);
lambdaActions.action('setName', setName);
lambdaActions.action('sendPublic', sendPublic);
lambdaActions.action('sendPrivate', sendPrivate);
await lambdaActions.fire({
action: routeKey,
payload: body,
meta: { connectionId },
});
} catch (err) {
console.error(err);
}
return {};
};