inital commit

This commit is contained in:
2021-07-24 16:28:35 +09:00
parent aa71a7a3cc
commit c6cf7cc88b
39 changed files with 949 additions and 66 deletions

View File

@@ -150,3 +150,14 @@ CREATE TABLE `catherine_league`.`archive` (
INSERT INTO `catherine_league`.`archive` (`title`, `youtube_id`) VALUES ('格ゲー大好き茜ちゃんと競う『キャサリン・フルボディ』 【VOICEROID紹介動画】', 'oE8Xk6pGtQc'); INSERT INTO `catherine_league`.`archive` (`title`, `youtube_id`) VALUES ('格ゲー大好き茜ちゃんと競う『キャサリン・フルボディ』 【VOICEROID紹介動画】', 'oE8Xk6pGtQc');
INSERT INTO `catherine_league`.`archive` (`title`, `youtube_id`) VALUES ('【PGW.TV】キャサリンフルボディ 「対戦時に使うテクニック紹介など」【はやお】', '7fZk2Agy0S4'); INSERT INTO `catherine_league`.`archive` (`title`, `youtube_id`) VALUES ('【PGW.TV】キャサリンフルボディ 「対戦時に使うテクニック紹介など」【はやお】', '7fZk2Agy0S4');
CREATE TABLE catherine_league.janken (
id BIGINT UNSIGNED auto_increment NOT NULL,
`match` varchar(100) NULL,
`result` json NULL,
created_date DATETIME DEFAULT NOW() NULL,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;

View File

@@ -47,12 +47,20 @@ function App(): JSX.Element {
<li> <li>
<Link to='/'>Home</Link> <Link to='/'>Home</Link>
</li> </li>
<li>
<Link to='/players'>Players</Link>
</li>
{
/*
<li> <li>
<Link to='/tournaments/stray_sheep_0/players'>Players</Link> <Link to='/tournaments/stray_sheep_0/players'>Players</Link>
</li> </li>
<li> <li>
<Link to='/tournaments/stray_sheep_0/scoreboard'>Scoreboard</Link> <Link to='/tournaments/stray_sheep_0/scoreboard'>Scoreboard</Link>
</li> </li>
*/
}
<li> <li>
<Link to='/guide'>Guide</Link> <Link to='/guide'>Guide</Link>
</li> </li>

View File

@@ -14,17 +14,15 @@ export const Home: FunctionComponent<ComponentProps> = (props): JSX.Element => {
return ( return (
<div className={style.mainBody}> <div className={style.mainBody}>
<div className={style.chalice} /> <div className={style.chalice} />
<div className={style.titleImageStrayShip0} /> <div className={style.titleImageStrayShip4} />
<div className={style.players} /> <div className={style.padding} />
<div className={style.tonamel}>
<a href='https://tonamel.com/competition/49WpE' rel='noopener noreferrer' target='_blank'>&nbsp;</a>
</div>
<div className={style.padding} /> <div className={style.padding} />
<div className={style.rule} />
<div className={style.twitchHome}> <div className={style.twitchHome}>
<a href='https://www.twitch.tv/catherine_faito_crab' rel='noopener noreferrer' target='_blank'>&nbsp;</a> <a href='https://www.twitch.tv/catherine_faito_crab' rel='noopener noreferrer' target='_blank'>&nbsp;</a>
</div> </div>
<YouTube
videoId={'oetCaugzOew'}
opts={opts}
/>
</div> </div>
); );
}; };

View File

@@ -464,6 +464,14 @@
background-size: contain; background-size: contain;
background-repeat: none; background-repeat: none;
} }
.titleImageStrayShip4 {
width: 808px;
height: 119px;
margin: auto;
background-image: url('https://static.catherine-fc.com/media/straysheepcup4.png');
background-size: contain;
background-repeat: none;
}
.rule { .rule {
width: 900px; width: 900px;
height: 637px; height: 637px;
@@ -472,7 +480,19 @@
background-size: contain; background-size: contain;
background-repeat: none; background-repeat: none;
} }
.tonamel {
width: 900px;
height: 637px;
margin: auto;
background-image: url('https://static.catherine-fc.com/media/tonamel.png');
background-size: contain;
background-repeat: none;
&> a {
display:block;
width: 900px;
height: 637px;
}
}
.padding { .padding {
width: 900px; width: 900px;
height: 100px; height: 100px;

View File

@@ -7,6 +7,7 @@ import dotenv from 'dotenv';
import { v1 } from 'uuid'; import { v1 } from 'uuid';
import { IJankenSelect, IJankenResult } from './models/message'; import { IJankenSelect, IJankenResult } from './models/message';
import { IRoom } from './models';
dotenv.config(); dotenv.config();
const port: number = 8080; const port: number = 8080;
@@ -157,13 +158,9 @@ httpServer.listen(port, () => {
// Janken Tool // Janken Tool
let room: boolean = false;
let playerOne: string = '';
let playerTwo: string = '';
let playerOneOption: string = '';
let playerTwoOption: string = '';
let stages: string[] = []; let stages: string[] = [];
let currentIndex: number = 0; let currentIndex: number = 0;
let rooms: Record<string, IRoom> = {};
const defaultStages: string[] = ['cementery', 'prison', 'torture', 'inquisition', 'quadrangle', 'clock', 'spiral', 'empireo', 'cathedral', 'close', 'arrange']; const defaultStages: string[] = ['cementery', 'prison', 'torture', 'inquisition', 'quadrangle', 'clock', 'spiral', 'empireo', 'cathedral', 'close', 'arrange'];
io.on('connection', (socket: socketIo.Socket) => { io.on('connection', (socket: socketIo.Socket) => {
@@ -174,45 +171,74 @@ io.on('connection', (socket: socketIo.Socket) => {
socket.on('exitGame', () => { socket.on('exitGame', () => {
console.log('exitGame'); console.log('exitGame');
io.emit('exitGame'); io.emit('exitGame');
room = false; rooms = {};
initRoom();
Object.keys(io.sockets.sockets).forEach((s: string) => { Object.keys(io.sockets.sockets).forEach((s: string) => {
io.sockets.sockets[s].disconnect(true); io.sockets.sockets[s].disconnect(true);
}); });
}); });
socket.on('janken', (data: IJankenSelect) => { socket.on('janken', (data: IJankenSelect) => {
console.log('janken', data); console.log('janken', data);
if (playerOne === data.userName) { const currentRoom = rooms[data.room];
playerOneOption = data.option; if (currentRoom) {
} else if (playerTwo === data.userName) { if (currentRoom.playerOne === data.userName) {
playerTwoOption = data.option; currentRoom.playerOneOption = data.option;
} } else if (currentRoom.playerTwo === data.userName) {
console.log('playerOneOption', playerOneOption); currentRoom.playerTwoOption = data.option;
console.log('playerTwoOption', playerTwoOption); }
if (playerOneOption !== '' && playerTwoOption !== '') { console.log('playerOneOption', currentRoom.playerOneOption);
const message: IJankenResult = { console.log('playerTwoOption', currentRoom.playerTwoOption);
playerOne, if (currentRoom.playerOneOption !== '' && currentRoom.playerTwoOption !== '') {
playerOneOption, const message: IJankenResult = {
playerTwo, playerOne: currentRoom.playerOne,
playerTwoOption playerOneOption: currentRoom.playerOneOption,
}; playerTwo: currentRoom.playerTwo,
io.emit('jankenResult', message); playerTwoOption: currentRoom.playerTwoOption
};
io.to(data.room).emit('jankenResult', message);
const sqlToPrepare = 'INSERT INTO `janken` (`match`, `result`) VALUES(?, ?);';
const sql = mysql.format(sqlToPrepare, [data.room, JSON.stringify(message)]);
connection.query(sql,
(error: mysql.MysqlError | null, results: any) => {
if (error) {
console.error(error);
}
}
);
if (currentRoom.playerOneOption !== currentRoom.playerTwoOption) {
delete rooms[data.room];
}
}
} }
}); });
socket.on('registerUser', (data: string) => { socket.on('registerUser', (data: {username: string, room: string}) => {
console.log('registerUser', data); console.log('registerUser', data);
if (playerOne === '') { let currentRoom: IRoom = {
playerOne = data; playerOne: '',
socket.emit('registerUser', data); playerTwo: '',
} else if (playerTwo === '') { playerOneOption: '',
playerTwo = data; playerTwoOption: ''
socket.emit('registerUser', data); };
if (rooms[data.room]) {
currentRoom = rooms[data.room];
} else {
rooms = {
...rooms,
[data.room]: currentRoom
};
}
socket.join(data.room);
if (currentRoom.playerOne === '') {
currentRoom.playerOne = data.username;
socket.emit('registerUser', data.username);
} else if (currentRoom.playerTwo === '') {
currentRoom.playerTwo = data.username;
socket.emit('registerUser', data.username);
} }
const message = { const message = {
playerOne, playerOne: currentRoom.playerOne,
playerTwo playerTwo: currentRoom.playerTwo
}; };
io.emit('login', message); io.to(data.room).emit('login', message);
}); });
socket.on('moveToStage', () => { socket.on('moveToStage', () => {
console.log('moveToStage'); console.log('moveToStage');
@@ -227,11 +253,14 @@ io.on('connection', (socket: socketIo.Socket) => {
io.emit('updateIndex', currentIndex); io.emit('updateIndex', currentIndex);
} }
}); });
socket.on('againGame', () => { socket.on('againGame', (room: string) => {
console.log('againGame'); const currentRoom = rooms[room];
io.emit('againGame'); if (currentRoom) {
playerOneOption = ''; console.log('againGame');
playerTwoOption = ''; io.to(room).emit('againGame');
currentRoom.playerOneOption = '';
currentRoom.playerTwoOption = '';
}
}); });
socket.on('previousIndex', () => { socket.on('previousIndex', () => {
console.log('previousIndex'); console.log('previousIndex');
@@ -240,6 +269,7 @@ io.on('connection', (socket: socketIo.Socket) => {
io.emit('updateIndex', currentIndex); io.emit('updateIndex', currentIndex);
} }
}); });
/*
if (!room) { if (!room) {
// create new room // create new room
initRoom(); initRoom();
@@ -264,15 +294,14 @@ io.on('connection', (socket: socketIo.Socket) => {
socket.emit('stages', message); socket.emit('stages', message);
} }
} }
*/
const initialmessage = {
playerOne: '',
playerTwo: '',
};
socket.emit('login', initialmessage);
}); });
const shuffle = (array: string[]): string[] => { const shuffle = (array: string[]): string[] => {
return array.sort(() => Math.random() - 0.5); return array.sort(() => Math.random() - 0.5);
}; };
const initRoom = (): void => {
playerOne = '';
playerTwo = '';
playerOneOption = '';
playerTwoOption = '';
};

View File

@@ -0,0 +1,6 @@
export interface IRoom {
playerOne: string;
playerTwo: string;
playerOneOption: string;
playerTwoOption: string;
}

View File

@@ -16,5 +16,6 @@ export interface ILogin {
export interface IJankenSelect { export interface IJankenSelect {
userName: string; userName: string;
room: string;
option: string; option: string;
} }

1
main-web/serverless/go/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
pkg/

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,21 @@
# Serverless directories
.serverless
# golang output binary directory
bin
# golang vendor (dependencies) directory
vendor
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

View File

@@ -0,0 +1,91 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
digest = "1:1f2ee62e40b3b0ca8403e49a07afb9ae8c0980391be1986e9f6c4ac9de1b1a90"
name = "github.com/aws/aws-lambda-go"
packages = [
"events",
"lambda",
"lambda/handlertrace",
"lambda/messages",
"lambdacontext",
]
pruneopts = ""
revision = "55dc88be4cdfaaf4bb4d9f65debd8d4310e0a83c"
version = "v1.19.1"
[[projects]]
digest = "1:913aa8374d300095f235fe6762f74a9ca82bf1fb30d4f830540b2a5dd6f993e4"
name = "github.com/aws/aws-sdk-go"
packages = [
"aws",
"aws/awserr",
"aws/awsutil",
"aws/client",
"aws/client/metadata",
"aws/corehandlers",
"aws/credentials",
"aws/credentials/ec2rolecreds",
"aws/credentials/endpointcreds",
"aws/credentials/processcreds",
"aws/credentials/stscreds",
"aws/csm",
"aws/defaults",
"aws/ec2metadata",
"aws/endpoints",
"aws/request",
"aws/session",
"aws/signer/v4",
"internal/context",
"internal/ini",
"internal/sdkio",
"internal/sdkmath",
"internal/sdkrand",
"internal/sdkuri",
"internal/shareddefaults",
"internal/strings",
"internal/sync/singleflight",
"private/protocol",
"private/protocol/json/jsonutil",
"private/protocol/jsonrpc",
"private/protocol/query",
"private/protocol/query/queryutil",
"private/protocol/rest",
"private/protocol/xml/xmlutil",
"service/ssm",
"service/sts",
"service/sts/stsiface",
]
pruneopts = ""
revision = "2bec4e3ae9cb717c0082a489e75ab9db71c98b23"
version = "v1.34.22"
[[projects]]
digest = "1:a67f9275b42e8bb95ba38f705062175ef65538bcdc107e0771763e6cde80c3c3"
name = "github.com/go-sql-driver/mysql"
packages = ["."]
pruneopts = ""
revision = "17ef3dd9d98b69acec3e85878995ada9533a9370"
version = "v1.5.0"
[[projects]]
digest = "1:13fe471d0ed891e8544eddfeeb0471fd3c9f2015609a1c000aefdedf52a19d40"
name = "github.com/jmespath/go-jmespath"
packages = ["."]
pruneopts = ""
revision = "c2b33e84"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
input-imports = [
"github.com/aws/aws-lambda-go/events",
"github.com/aws/aws-lambda-go/lambda",
"github.com/aws/aws-sdk-go/aws",
"github.com/aws/aws-sdk-go/aws/session",
"github.com/aws/aws-sdk-go/service/ssm",
"github.com/go-sql-driver/mysql",
]
solver-name = "gps-cdcl"
solver-version = 1

View File

@@ -0,0 +1,25 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
[[constraint]]
name = "github.com/aws/aws-lambda-go"
version = "1.x"

View File

@@ -0,0 +1,12 @@
.PHONY: build clean deploy
build:
dep ensure -v
env GOOS=linux go build -ldflags="-s -w" -o bin/archive archive/main.go
env GOOS=linux go build -ldflags="-s -w" -o bin/guide guide/main.go
clean:
rm -rf ./bin ./vendor Gopkg.lock
deploy: clean build
sls deploy --verbose

View File

@@ -0,0 +1,72 @@
package main
import (
"bytes"
"context"
"encoding/json"
_ "github.com/go-sql-driver/mysql"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ssm"
)
// Response is of type APIGatewayProxyResponse since we're leveraging the
// AWS Lambda Proxy Request functionality (default behavior)
//
// https://serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-proxy-integration
type Response events.APIGatewayProxyResponse
// Handler is our lambda handler invoked by the `lambda.Start` function call
func Handler(ctx context.Context) (Response, error) {
svc := ssm.New(session.New(), &aws.Config{
Region: aws.String("ap-northeast-1"),
})
res, _ := svc.GetParameter(&ssm.GetParameterInput{
Name: aws.String("db-endpoint"),
WithDecryption: aws.Bool(true),
})
dbendpoint := *res.Parameter.Value
/*
res, _ = svc.GetParameter(&ssm.GetParameterInput{
Name: aws.String("db-username"),
WithDecryption: aws.Bool(true),
})
dbusername := *res.Parameter.Value
res, _ = svc.GetParameter(&ssm.GetParameterInput{
Name: aws.String("db-password"),
WithDecryption: aws.Bool(true),
})
dbpassword := *res.Parameter.Value
*/
var buf bytes.Buffer
body, err := json.Marshal(map[string]interface{}{
"message": "Okay so your other function also executed successfully!",
"dbendpoint": dbendpoint,
})
if err != nil {
return Response{StatusCode: 404}, err
}
json.HTMLEscape(&buf, body)
resp := Response{
StatusCode: 200,
IsBase64Encoded: false,
Body: buf.String(),
Headers: map[string]string{
"Content-Type": "application/json",
"X-MyCompany-Func-Reply": "world-handler",
},
}
return resp, nil
}
func main() {
lambda.Start(Handler)
}

View File

@@ -0,0 +1,45 @@
package main
import (
"bytes"
"context"
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
// Response is of type APIGatewayProxyResponse since we're leveraging the
// AWS Lambda Proxy Request functionality (default behavior)
//
// https://serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-proxy-integration
type Response events.APIGatewayProxyResponse
// Handler is our lambda handler invoked by the `lambda.Start` function call
func Handler(ctx context.Context) (Response, error) {
var buf bytes.Buffer
body, err := json.Marshal(map[string]interface{}{
"message": "Go Serverless v1.0! Your function executed successfully!",
})
if err != nil {
return Response{StatusCode: 404}, err
}
json.HTMLEscape(&buf, body)
resp := Response{
StatusCode: 200,
IsBase64Encoded: false,
Body: buf.String(),
Headers: map[string]string{
"Content-Type": "application/json",
"X-MyCompany-Func-Reply": "hello-handler",
},
}
return resp, nil
}
func main() {
lambda.Start(Handler)
}

View File

@@ -0,0 +1,152 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: catherine-fc-api
# app and org for use with dashboard.serverless.com
#app: your-app-name
#org: your-org-name
custom:
VpcId:
dev: "vpc-c54553a2"
sqa: "vpc-c54553a2"
int: "vpc-c54553a2"
uat: "vpc-c54553a2"
prd: "vpc-c54553a2"
Subnet1:
dev: "subnet-0d0fdf45"
sqa: "subnet-0d0fdf45"
int: "subnet-0d0fdf45"
uat: "subnet-0d0fdf45"
prd: "subnet-0d0fdf45"
Subnet2:
dev: "subnet-4dcecc16"
sqa: "subnet-4dcecc16"
int: "subnet-4dcecc16"
uat: "subnet-4dcecc16"
prd: "subnet-4dcecc16"
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
frameworkVersion: '>=1.28.0 <=2.0.0'
provider:
name: aws
runtime: go1.x
region: ap-northeast-1
versionFunctions: false
logRetentionInDays: 14
memorySize: 128
deploymentBucket: catherine-fc-serverless-bucket
stage: dev
# you can overwrite defaults here
# stage: dev
# region: us-east-1
iamRoleStatements:
- Effect: "Allow"
Action:
- "lambda:InvokeFunction"
Resource:
- "arn:aws:lambda:*:*:function:*"
- Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource:
- "arn:aws:logs:*:*:*"
- Effect: "Allow"
Action:
- "ssm:GetParameter"
Resource:
- "arn:aws:ssm:*:*:parameter/*"
# you can define service wide environment variables here
# environment:
# variable1: value1
package:
exclude:
- ./**
include:
- ./bin/**
functions:
guideAPI:
handler: bin/guide
timeout: 3
events:
- http:
path: guide
method: get
archiveAPI:
handler: bin/archive
timeout: 3
events:
- http:
path: archive
method: get
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
# events:
# events:
# - http:
# path: users/create
# method: get
# - websocket: $connect
# - s3: ${env:BUCKET}
# - schedule: rate(10 minutes)
# - sns: greeter-topic
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
# - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx
# - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
# - iot:
# sql: "SELECT * FROM 'some_topic'"
# - cloudwatchEvent:
# event:
# source:
# - "aws.ec2"
# detail-type:
# - "EC2 Instance State-change Notification"
# detail:
# state:
# - pending
# - cloudwatchLog: '/aws/lambda/hello'
# - cognitoUserPool:
# pool: MyUserPool
# trigger: PreSignUp
# - alb:
# listenerArn: arn:aws:elasticloadbalancing:us-east-1:XXXXXX:listener/app/my-load-balancer/50dc6c495c0c9188/
# priority: 1
# conditions:
# host: example.com
# path: /hello
# Define function environment variables here
# environment:
# variable2: value2
# you can add CloudFormation resource templates here
#resources:
# Resources:
# NewResource:
# Type: AWS::S3::Bucket
# Properties:
# BucketName: my-new-bucket
# Outputs:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"

View File

@@ -37,7 +37,7 @@ function App(): JSX.Element {
} }
}); });
sock.on('login', (data: ILoginMessage) => { sock.on('login', (data: ILoginMessage) => {
console.log(data); console.log('login', data);
setCurrentPlayers(data); setCurrentPlayers(data);
}); });
sock.on('registerUser', (data: string) => { sock.on('registerUser', (data: string) => {
@@ -68,10 +68,11 @@ function App(): JSX.Element {
setSocket(sock); setSocket(sock);
} }
} }
const janken = (option: string): void => { const janken = (option: string, room: string): void => {
if (socket && currentUser) { if (socket && currentUser) {
const message: IJankenSelect = { const message: IJankenSelect = {
userName: currentUser, userName: currentUser,
room,
option option
}; };
socket.emit('janken', message); socket.emit('janken', message);
@@ -82,9 +83,9 @@ function App(): JSX.Element {
socket.emit('moveToStage'); socket.emit('moveToStage');
} }
}; };
const registerUser = (username: string): void => { const registerUser = (username: string, room: string): void => {
if (socket) { if (socket) {
socket.emit('registerUser', username); socket.emit('registerUser', { username, room });
} }
}; };
const previousIndex = (): void => { const previousIndex = (): void => {
@@ -97,9 +98,9 @@ function App(): JSX.Element {
socket.emit('nextIndex'); socket.emit('nextIndex');
} }
}; };
const againGame = (): void => { const againGame = (room: string): void => {
if (socket) { if (socket) {
socket.emit('againGame'); socket.emit('againGame', room);
} }
}; };
const exitGame = (): void => { const exitGame = (): void => {

View File

@@ -7,15 +7,16 @@ type ComponentProps = {
currentUser: string; currentUser: string;
currentPlayers: ILoginMessage; currentPlayers: ILoginMessage;
jankenResults: IJankenResult | null; jankenResults: IJankenResult | null;
janken: (option: string) => void; janken: (option: string, room: string) => void;
onSubmit: (username: string) => void; onSubmit: (username: string, room: string) => void;
moveToStage: () => void; moveToStage: () => void;
againGame: () => void; againGame: (room: string) => void;
}; };
export const Janken: FunctionComponent<ComponentProps> = (props): JSX.Element => { export const Janken: FunctionComponent<ComponentProps> = (props): JSX.Element => {
const { currentUser, currentPlayers, jankenResults, janken, onSubmit, moveToStage, againGame } = props; const { currentUser, currentPlayers, jankenResults, janken, onSubmit, moveToStage, againGame } = props;
const [userName, setUserName] = useState<string>(''); const [userName, setUserName] = useState<string>('');
const [room, setRoom] = useState<string>('');
const getIcon = (result: string): JSX.Element | undefined => { const getIcon = (result: string): JSX.Element | undefined => {
switch (result) { switch (result) {
case 'rock': case 'rock':
@@ -33,12 +34,13 @@ export const Janken: FunctionComponent<ComponentProps> = (props): JSX.Element =>
<Button <Button
color='pink' color='pink'
size='large' size='large'
onClick={againGame} onClick={(): void => againGame(room)}
> >
Again Again
</Button> </Button>
); );
} else { } else {
/*
return ( return (
<Button <Button
color='pink' color='pink'
@@ -48,6 +50,8 @@ export const Janken: FunctionComponent<ComponentProps> = (props): JSX.Element =>
Stages Stages
</Button> </Button>
); );
*/
return (<></>);
} }
} }
if (currentPlayers.playerOne === '' || currentPlayers.playerTwo === '') { if (currentPlayers.playerOne === '' || currentPlayers.playerTwo === '') {
@@ -64,9 +68,18 @@ export const Janken: FunctionComponent<ComponentProps> = (props): JSX.Element =>
loading={false} loading={false}
onChange={(e): void => setUserName(e.target.value)} onChange={(e): void => setUserName(e.target.value)}
/> />
<Label>
Room Name
</Label>
<Input
value={room}
loading={false}
onChange={(e): void => setRoom(e.target.value)}
/>
</Form.Field> </Form.Field>
<Button <Button
onClick={(): void => onSubmit(userName)} disabled={room.trim() === '' || userName.trim() === ''}
onClick={(): void => onSubmit(userName, room)}
> >
Login Login
</Button> </Button>
@@ -87,7 +100,7 @@ export const Janken: FunctionComponent<ComponentProps> = (props): JSX.Element =>
<Button <Button
color='pink' color='pink'
size='huge' size='huge'
onClick={(): void => janken('rock')} onClick={(): void => janken('rock', room)}
> >
<Icon name='hand rock outline' /> <Icon name='hand rock outline' />
</Button> </Button>
@@ -95,7 +108,7 @@ export const Janken: FunctionComponent<ComponentProps> = (props): JSX.Element =>
<Button <Button
color='pink' color='pink'
size='huge' size='huge'
onClick={(): void => janken('scissors')} onClick={(): void => janken('scissors', room)}
> >
<Icon name='hand scissors outline' /> <Icon name='hand scissors outline' />
</Button> </Button>
@@ -103,7 +116,7 @@ export const Janken: FunctionComponent<ComponentProps> = (props): JSX.Element =>
<Button <Button
color='pink' color='pink'
size='huge' size='huge'
onClick={(): void => janken('paper')} onClick={(): void => janken('paper', room)}
> >
<Icon name='hand paper outline' /> <Icon name='hand paper outline' />
</Button> </Button>

View File

@@ -16,5 +16,6 @@ export interface ILogin {
export interface IJankenSelect { export interface IJankenSelect {
userName: string; userName: string;
room: string;
option: string; option: string;
} }

View File

@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@@ -0,0 +1,46 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).

View File

@@ -0,0 +1,50 @@
{
"name": "twitch-chat",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"typescript": "^4.2.4",
"web-vitals": "^1.1.1",
"socket.io": "^2.3.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.8.3",
"@types/jest": "^26.0.22",
"@types/node": "^12.20.7",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3",
"@types/socket.io": "^1.4.32",
"tslint": "^5.18.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-react": "^4.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@@ -0,0 +1,38 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View File

@@ -0,0 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@@ -0,0 +1,61 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
export const socket = new WebSocket('ws://127.0.0.1:7000', "rust-websocket");
socket.addEventListener('open', (event) => {
console.log(event);
const test = {
action: 'test',
message: 'unchi'
};
socket.send(JSON.stringify(test));
});
socket.addEventListener('message', (event) => {
console.log(event);
const data = event.data;
if (data.indexOf('PING') === 0) {
socket.send('PONG');
socket.send('PRIVMSG #osoma_crawler :オソマ');
}
})
function App() {
/*
const socket = new WebSocket('wss://irc-ws.chat.twitch.tv:443');
socket.addEventListener('open', (event) => {
console.log(event);
socket.send('PASS oauth:xweh94y0e330bo1i9rw0ty6fo02m9w');
socket.send('NICK osoma_bot');
socket.send('JOIN #osoma_crawler');
});
socket.addEventListener('message', (event) => {
console.log(event);
const data = event.data;
if (data.indexOf('PING') === 0) {
socket.send('PONG');
socket.send('PRIVMSG #osoma_crawler :オソマ');
}
})
*/
console.log("test")
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;

View File

@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

View File

@@ -0,0 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -0,0 +1 @@
/// <reference types="react-scripts" />

View File

@@ -0,0 +1,15 @@
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;

View File

@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}