diff --git a/infra/db/db.sql b/infra/db/db.sql index 98d1705..7910dd9 100644 --- a/infra/db/db.sql +++ b/infra/db/db.sql @@ -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 ('【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; diff --git a/main-web/client/src/App.tsx b/main-web/client/src/App.tsx index b1ffc73..219db51 100644 --- a/main-web/client/src/App.tsx +++ b/main-web/client/src/App.tsx @@ -47,12 +47,20 @@ function App(): JSX.Element {
  • Home
  • +
  • + Players +
  • + { + /* +
  • Players
  • Scoreboard
  • + */ + }
  • Guide
  • diff --git a/main-web/client/src/components/home.tsx b/main-web/client/src/components/home.tsx index 7941481..946a716 100644 --- a/main-web/client/src/components/home.tsx +++ b/main-web/client/src/components/home.tsx @@ -14,17 +14,15 @@ export const Home: FunctionComponent = (props): JSX.Element => { return (
    -
    -
    +
    +
    +
    +   +
    -
     
    -
    ); }; diff --git a/main-web/client/src/web.module.scss b/main-web/client/src/web.module.scss index a2b4c83..abba2aa 100644 --- a/main-web/client/src/web.module.scss +++ b/main-web/client/src/web.module.scss @@ -464,6 +464,14 @@ background-size: contain; 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 { width: 900px; height: 637px; @@ -472,7 +480,19 @@ background-size: contain; 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 { width: 900px; height: 100px; diff --git a/main-web/server/src/index.ts b/main-web/server/src/index.ts index 8cf9dc8..1065b5b 100644 --- a/main-web/server/src/index.ts +++ b/main-web/server/src/index.ts @@ -7,6 +7,7 @@ import dotenv from 'dotenv'; import { v1 } from 'uuid'; import { IJankenSelect, IJankenResult } from './models/message'; +import { IRoom } from './models'; dotenv.config(); const port: number = 8080; @@ -157,13 +158,9 @@ httpServer.listen(port, () => { // Janken Tool -let room: boolean = false; -let playerOne: string = ''; -let playerTwo: string = ''; -let playerOneOption: string = ''; -let playerTwoOption: string = ''; let stages: string[] = []; let currentIndex: number = 0; +let rooms: Record = {}; const defaultStages: string[] = ['cementery', 'prison', 'torture', 'inquisition', 'quadrangle', 'clock', 'spiral', 'empireo', 'cathedral', 'close', 'arrange']; io.on('connection', (socket: socketIo.Socket) => { @@ -174,45 +171,74 @@ io.on('connection', (socket: socketIo.Socket) => { socket.on('exitGame', () => { console.log('exitGame'); io.emit('exitGame'); - room = false; - initRoom(); + rooms = {}; Object.keys(io.sockets.sockets).forEach((s: string) => { io.sockets.sockets[s].disconnect(true); }); }); socket.on('janken', (data: IJankenSelect) => { console.log('janken', data); - if (playerOne === data.userName) { - playerOneOption = data.option; - } else if (playerTwo === data.userName) { - playerTwoOption = data.option; - } - console.log('playerOneOption', playerOneOption); - console.log('playerTwoOption', playerTwoOption); - if (playerOneOption !== '' && playerTwoOption !== '') { - const message: IJankenResult = { - playerOne, - playerOneOption, - playerTwo, - playerTwoOption - }; - io.emit('jankenResult', message); + const currentRoom = rooms[data.room]; + if (currentRoom) { + if (currentRoom.playerOne === data.userName) { + currentRoom.playerOneOption = data.option; + } else if (currentRoom.playerTwo === data.userName) { + currentRoom.playerTwoOption = data.option; + } + console.log('playerOneOption', currentRoom.playerOneOption); + console.log('playerTwoOption', currentRoom.playerTwoOption); + if (currentRoom.playerOneOption !== '' && currentRoom.playerTwoOption !== '') { + const message: IJankenResult = { + playerOne: currentRoom.playerOne, + playerOneOption: currentRoom.playerOneOption, + playerTwo: currentRoom.playerTwo, + 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); - if (playerOne === '') { - playerOne = data; - socket.emit('registerUser', data); - } else if (playerTwo === '') { - playerTwo = data; - socket.emit('registerUser', data); + let currentRoom: IRoom = { + playerOne: '', + playerTwo: '', + playerOneOption: '', + playerTwoOption: '' + }; + 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 = { - playerOne, - playerTwo + playerOne: currentRoom.playerOne, + playerTwo: currentRoom.playerTwo }; - io.emit('login', message); + io.to(data.room).emit('login', message); }); socket.on('moveToStage', () => { console.log('moveToStage'); @@ -227,11 +253,14 @@ io.on('connection', (socket: socketIo.Socket) => { io.emit('updateIndex', currentIndex); } }); - socket.on('againGame', () => { - console.log('againGame'); - io.emit('againGame'); - playerOneOption = ''; - playerTwoOption = ''; + socket.on('againGame', (room: string) => { + const currentRoom = rooms[room]; + if (currentRoom) { + console.log('againGame'); + io.to(room).emit('againGame'); + currentRoom.playerOneOption = ''; + currentRoom.playerTwoOption = ''; + } }); socket.on('previousIndex', () => { console.log('previousIndex'); @@ -240,6 +269,7 @@ io.on('connection', (socket: socketIo.Socket) => { io.emit('updateIndex', currentIndex); } }); + /* if (!room) { // create new room initRoom(); @@ -264,15 +294,14 @@ io.on('connection', (socket: socketIo.Socket) => { socket.emit('stages', message); } } - + */ + const initialmessage = { + playerOne: '', + playerTwo: '', + }; + socket.emit('login', initialmessage); }); const shuffle = (array: string[]): string[] => { return array.sort(() => Math.random() - 0.5); }; -const initRoom = (): void => { - playerOne = ''; - playerTwo = ''; - playerOneOption = ''; - playerTwoOption = ''; -}; diff --git a/main-web/server/src/models/index.ts b/main-web/server/src/models/index.ts index e69de29..ed58fe8 100644 --- a/main-web/server/src/models/index.ts +++ b/main-web/server/src/models/index.ts @@ -0,0 +1,6 @@ +export interface IRoom { + playerOne: string; + playerTwo: string; + playerOneOption: string; + playerTwoOption: string; +} diff --git a/main-web/server/src/models/message.ts b/main-web/server/src/models/message.ts index d020d11..1dc469f 100644 --- a/main-web/server/src/models/message.ts +++ b/main-web/server/src/models/message.ts @@ -16,5 +16,6 @@ export interface ILogin { export interface IJankenSelect { userName: string; + room: string; option: string; } diff --git a/main-web/serverless/go/.gitignore b/main-web/serverless/go/.gitignore new file mode 100644 index 0000000..b2bcbe8 --- /dev/null +++ b/main-web/serverless/go/.gitignore @@ -0,0 +1 @@ +pkg/ \ No newline at end of file diff --git a/main-web/serverless/go/bin/go-outline b/main-web/serverless/go/bin/go-outline new file mode 100644 index 0000000..7ef7e5c Binary files /dev/null and b/main-web/serverless/go/bin/go-outline differ diff --git a/main-web/serverless/go/bin/gopls b/main-web/serverless/go/bin/gopls new file mode 100644 index 0000000..3179d6a Binary files /dev/null and b/main-web/serverless/go/bin/gopls differ diff --git a/main-web/serverless/go/src/catherine-fc-api/.gitignore b/main-web/serverless/go/src/catherine-fc-api/.gitignore new file mode 100644 index 0000000..eea931b --- /dev/null +++ b/main-web/serverless/go/src/catherine-fc-api/.gitignore @@ -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 diff --git a/main-web/serverless/go/src/catherine-fc-api/Gopkg.lock b/main-web/serverless/go/src/catherine-fc-api/Gopkg.lock new file mode 100644 index 0000000..ec69d8d --- /dev/null +++ b/main-web/serverless/go/src/catherine-fc-api/Gopkg.lock @@ -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 diff --git a/main-web/serverless/go/src/catherine-fc-api/Gopkg.toml b/main-web/serverless/go/src/catherine-fc-api/Gopkg.toml new file mode 100644 index 0000000..a844086 --- /dev/null +++ b/main-web/serverless/go/src/catherine-fc-api/Gopkg.toml @@ -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" diff --git a/main-web/serverless/go/src/catherine-fc-api/Makefile b/main-web/serverless/go/src/catherine-fc-api/Makefile new file mode 100644 index 0000000..62f9fc8 --- /dev/null +++ b/main-web/serverless/go/src/catherine-fc-api/Makefile @@ -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 diff --git a/main-web/serverless/go/src/catherine-fc-api/archive/main.go b/main-web/serverless/go/src/catherine-fc-api/archive/main.go new file mode 100644 index 0000000..5874823 --- /dev/null +++ b/main-web/serverless/go/src/catherine-fc-api/archive/main.go @@ -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) +} diff --git a/main-web/serverless/go/src/catherine-fc-api/guide/main.go b/main-web/serverless/go/src/catherine-fc-api/guide/main.go new file mode 100644 index 0000000..2a4d552 --- /dev/null +++ b/main-web/serverless/go/src/catherine-fc-api/guide/main.go @@ -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) +} diff --git a/main-web/serverless/go/src/catherine-fc-api/serverless.yml b/main-web/serverless/go/src/catherine-fc-api/serverless.yml new file mode 100644 index 0000000..ae74468 --- /dev/null +++ b/main-web/serverless/go/src/catherine-fc-api/serverless.yml @@ -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" diff --git a/tools/janken/src/App.tsx b/tools/janken/src/App.tsx index a25071f..f816861 100644 --- a/tools/janken/src/App.tsx +++ b/tools/janken/src/App.tsx @@ -37,7 +37,7 @@ function App(): JSX.Element { } }); sock.on('login', (data: ILoginMessage) => { - console.log(data); + console.log('login', data); setCurrentPlayers(data); }); sock.on('registerUser', (data: string) => { @@ -68,10 +68,11 @@ function App(): JSX.Element { setSocket(sock); } } - const janken = (option: string): void => { + const janken = (option: string, room: string): void => { if (socket && currentUser) { const message: IJankenSelect = { userName: currentUser, + room, option }; socket.emit('janken', message); @@ -82,9 +83,9 @@ function App(): JSX.Element { socket.emit('moveToStage'); } }; - const registerUser = (username: string): void => { + const registerUser = (username: string, room: string): void => { if (socket) { - socket.emit('registerUser', username); + socket.emit('registerUser', { username, room }); } }; const previousIndex = (): void => { @@ -97,9 +98,9 @@ function App(): JSX.Element { socket.emit('nextIndex'); } }; - const againGame = (): void => { + const againGame = (room: string): void => { if (socket) { - socket.emit('againGame'); + socket.emit('againGame', room); } }; const exitGame = (): void => { diff --git a/tools/janken/src/component/janken/Janken.tsx b/tools/janken/src/component/janken/Janken.tsx index b37e5be..0d308ae 100644 --- a/tools/janken/src/component/janken/Janken.tsx +++ b/tools/janken/src/component/janken/Janken.tsx @@ -7,15 +7,16 @@ type ComponentProps = { currentUser: string; currentPlayers: ILoginMessage; jankenResults: IJankenResult | null; - janken: (option: string) => void; - onSubmit: (username: string) => void; + janken: (option: string, room: string) => void; + onSubmit: (username: string, room: string) => void; moveToStage: () => void; - againGame: () => void; + againGame: (room: string) => void; }; export const Janken: FunctionComponent = (props): JSX.Element => { const { currentUser, currentPlayers, jankenResults, janken, onSubmit, moveToStage, againGame } = props; const [userName, setUserName] = useState(''); + const [room, setRoom] = useState(''); const getIcon = (result: string): JSX.Element | undefined => { switch (result) { case 'rock': @@ -33,12 +34,13 @@ export const Janken: FunctionComponent = (props): JSX.Element => ); } else { + /* return ( ); + */ + return (<>); } } if (currentPlayers.playerOne === '' || currentPlayers.playerTwo === '') { @@ -64,9 +68,18 @@ export const Janken: FunctionComponent = (props): JSX.Element => loading={false} onChange={(e): void => setUserName(e.target.value)} /> + + setRoom(e.target.value)} + /> @@ -87,7 +100,7 @@ export const Janken: FunctionComponent = (props): JSX.Element => @@ -95,7 +108,7 @@ export const Janken: FunctionComponent = (props): JSX.Element => @@ -103,7 +116,7 @@ export const Janken: FunctionComponent = (props): JSX.Element => diff --git a/tools/janken/src/model/messages.ts b/tools/janken/src/model/messages.ts index d020d11..1dc469f 100644 --- a/tools/janken/src/model/messages.ts +++ b/tools/janken/src/model/messages.ts @@ -16,5 +16,6 @@ export interface ILogin { export interface IJankenSelect { userName: string; + room: string; option: string; } diff --git a/twitch_chat_reader/twitch-chat/.gitignore b/twitch_chat_reader/twitch-chat/.gitignore new file mode 100644 index 0000000..4d29575 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/.gitignore @@ -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* diff --git a/twitch_chat_reader/twitch-chat/README.md b/twitch_chat_reader/twitch-chat/README.md new file mode 100644 index 0000000..b87cb00 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/README.md @@ -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 can’t go back!** + +If you aren’t 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 you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t 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/). diff --git a/twitch_chat_reader/twitch-chat/package.json b/twitch_chat_reader/twitch-chat/package.json new file mode 100644 index 0000000..9615c13 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/package.json @@ -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" + ] + } +} diff --git a/twitch_chat_reader/twitch-chat/public/favicon.ico b/twitch_chat_reader/twitch-chat/public/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/twitch_chat_reader/twitch-chat/public/favicon.ico differ diff --git a/twitch_chat_reader/twitch-chat/public/index.html b/twitch_chat_reader/twitch-chat/public/index.html new file mode 100644 index 0000000..aa069f2 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
    + + + diff --git a/twitch_chat_reader/twitch-chat/public/logo192.png b/twitch_chat_reader/twitch-chat/public/logo192.png new file mode 100644 index 0000000..fc44b0a Binary files /dev/null and b/twitch_chat_reader/twitch-chat/public/logo192.png differ diff --git a/twitch_chat_reader/twitch-chat/public/logo512.png b/twitch_chat_reader/twitch-chat/public/logo512.png new file mode 100644 index 0000000..a4e47a6 Binary files /dev/null and b/twitch_chat_reader/twitch-chat/public/logo512.png differ diff --git a/twitch_chat_reader/twitch-chat/public/manifest.json b/twitch_chat_reader/twitch-chat/public/manifest.json new file mode 100644 index 0000000..080d6c7 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/public/manifest.json @@ -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" +} diff --git a/twitch_chat_reader/twitch-chat/public/robots.txt b/twitch_chat_reader/twitch-chat/public/robots.txt new file mode 100644 index 0000000..e9e57dc --- /dev/null +++ b/twitch_chat_reader/twitch-chat/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/twitch_chat_reader/twitch-chat/src/App.css b/twitch_chat_reader/twitch-chat/src/App.css new file mode 100644 index 0000000..74b5e05 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/App.css @@ -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); + } +} diff --git a/twitch_chat_reader/twitch-chat/src/App.test.tsx b/twitch_chat_reader/twitch-chat/src/App.test.tsx new file mode 100644 index 0000000..2a68616 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/App.test.tsx @@ -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(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/twitch_chat_reader/twitch-chat/src/App.tsx b/twitch_chat_reader/twitch-chat/src/App.tsx new file mode 100644 index 0000000..9dff7b5 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/App.tsx @@ -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 ( +
    +
    + logo +

    + Edit src/App.tsx and save to reload. +

    + + Learn React + +
    +
    + ); +} + +export default App; diff --git a/twitch_chat_reader/twitch-chat/src/index.css b/twitch_chat_reader/twitch-chat/src/index.css new file mode 100644 index 0000000..ec2585e --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/index.css @@ -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; +} diff --git a/twitch_chat_reader/twitch-chat/src/index.tsx b/twitch_chat_reader/twitch-chat/src/index.tsx new file mode 100644 index 0000000..ef2edf8 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/index.tsx @@ -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( + + + , + 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(); diff --git a/twitch_chat_reader/twitch-chat/src/logo.svg b/twitch_chat_reader/twitch-chat/src/logo.svg new file mode 100644 index 0000000..9dfc1c0 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/twitch_chat_reader/twitch-chat/src/react-app-env.d.ts b/twitch_chat_reader/twitch-chat/src/react-app-env.d.ts new file mode 100644 index 0000000..6431bc5 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/react-app-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/twitch_chat_reader/twitch-chat/src/reportWebVitals.ts b/twitch_chat_reader/twitch-chat/src/reportWebVitals.ts new file mode 100644 index 0000000..49a2a16 --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/reportWebVitals.ts @@ -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; diff --git a/twitch_chat_reader/twitch-chat/src/setupTests.ts b/twitch_chat_reader/twitch-chat/src/setupTests.ts new file mode 100644 index 0000000..8f2609b --- /dev/null +++ b/twitch_chat_reader/twitch-chat/src/setupTests.ts @@ -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'; diff --git a/twitch_chat_reader/twitch-chat/tsconfig.json b/twitch_chat_reader/twitch-chat/tsconfig.json new file mode 100644 index 0000000..a273b0c --- /dev/null +++ b/twitch_chat_reader/twitch-chat/tsconfig.json @@ -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" + ] +}