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
<!DOCTYPE html> | |
<html> | |
<style> | |
.default { | |
--primary-color: #f00; | |
--secondary-color: #000; | |
--background-default: #efefef; | |
--background-paper: #fff; | |
} | |
.dark { |
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
import Collapse from '@material-ui/core/Collapse'; | |
import FormControlLabel from '@material-ui/core/FormControlLabel'; | |
import IconButton from '@material-ui/core/IconButton'; | |
import { createStyles, withStyles, WithStyles } from '@material-ui/core/styles'; | |
import DownArrow from '@material-ui/icons/KeyboardArrowDown'; | |
import UpArrow from '@material-ui/icons/KeyboardArrowUp'; | |
import produce from 'immer'; | |
import React from 'react'; | |
import LegoCheckbox from '../Checkbox/Checkbox'; |
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
// APIGatewayWebsocketProxyRequest contains data coming from the API Gateway proxy | |
type APIGatewayWebsocketProxyRequest struct { | |
MethodArn string `json:"methodArn"` | |
Resource string `json:"resource"` // The resource path defined in API Gateway | |
Path string `json:"path"` // The url path for the caller | |
HTTPMethod string `json:"httpMethod"` | |
Headers map[string]string `json:"headers"` | |
MultiValueHeaders map[string][]string `json:"multiValueHeaders"` | |
QueryStringParameters map[string]string `json:"queryStringParameters"` | |
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"` |
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
type MessageAction struct { | |
Type string `json:"type"` | |
Payload MessagePayload `json:"payload"` | |
} | |
// MessagePayload .. | |
type MessagePayload struct { | |
Message MessageWithInfo `json:"message"` | |
} |
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
// Handler is the base handler that will receive all web socket request | |
func Handler(request APIGatewayWebsocketProxyRequest) (interface{}, error) { | |
switch request.RequestContext.RouteKey { | |
case "$connect": | |
return Connect(request) | |
case "$disconnect": | |
return Disconnect(request) | |
default: | |
return Default(request) | |
} |
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
// Disconnect will receive the $disconnect requests | |
func Disconnect(request APIGatewayWebsocketProxyRequest) (interface{}, error) { | |
id := request.RequestContext.Authorizer.(map[string]interface{})["cognito:username"].(string) | |
connectionID := request.RequestContext.ConnectionID | |
RemoveSocket(id, connectionID) | |
return events.APIGatewayProxyResponse{ | |
StatusCode: 200, | |
}, nil | |
} |
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
// Connect will receive the $connect request | |
// It will handle the authorization also | |
func Connect(request APIGatewayWebsocketProxyRequest) (interface{}, error) { | |
if request.RequestContext.Authorizer == nil { | |
return Authorizer(request) | |
} | |
id := request.RequestContext.Authorizer.(map[string]interface{})["cognito:username"].(string) | |
connectionID := request.RequestContext.ConnectionID | |
StoreSocket(id, connectionID) |
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
import Amplify, { Auth } from 'aws-amplify'; | |
Amplify.configure({ | |
Auth: { | |
region: 'us-east-1', | |
userPoolId: '**********', | |
userPoolWebClientId: '******************', | |
} | |
}); |
NewerOlder