Skip to content

Commit

Permalink
Updates (#116)
Browse files Browse the repository at this point in the history
* override @supabase/auth-js dependency from v2.64.2 to v2.61.0 to resolve supabase/supabase-js#936

* update two way binding in profile visibility to work with angular 18

* redirect to /join if player is not authenticated within the game

* remove logs

* update console messages
  • Loading branch information
rileythomp authored Jul 16, 2024
1 parent 3a11f1c commit b8e6768
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 43 deletions.
21 changes: 0 additions & 21 deletions be-jeopardy/internal/jeopardy/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,8 @@ func (g *Game) processMessages() {
log.Errorf("Error processing message: %s", err.Error())
}
case player := <-g.disconnectChan:
log.Infof("Stopping game %s", g.Name)
g.disconnectPlayer(player)
case <-g.restartChan:
log.Infof("Restarting game %s", g.Name)
g.restartGame(context.Background())
}
}
Expand Down Expand Up @@ -239,21 +237,17 @@ func (g *Game) disconnectPlayer(player GamePlayer) {
func (g *Game) processMsg(ctx context.Context, msg Message) error {
player := msg.Player
if g.State != msg.State {
log.Infof("Ignoring message from player %s because it is not for the current game state", player.name())
return nil
}
if g.Paused {
if msg.Pause == -1 {
log.Infof("Player %s resumed the game", player.name())
g.startGame()
g.messageAllPlayers("Player %s resumed the game", player.name())
return nil
}
log.Infof("Ignoring message from player %s because game is paused", player.name())
return nil
}
if msg.Pause == 1 {
log.Infof("Player %s paused the game", player.name())
g.pauseGame()
g.messageAllPlayers("Player %s paused the game", player.name())
return nil
Expand All @@ -262,34 +256,19 @@ func (g *Game) processMsg(ctx context.Context, msg Message) error {
switch g.State {
case RecvPick:
if msg.InitDispute {
log.Infof("Player %s disputed the previous question", player.name())
err = g.initDispute(player)
} else {
log.Debugf("Player %s picked", player.name())
err = g.processPick(player, msg.CatIdx, msg.ValIdx)
}
case RecvBuzz:
action := "buzzed"
if msg.IsPass {
action = "passed"
}
log.Debugf("Player %s %s", player.name(), action)
err = g.processBuzz(ctx, player, msg.IsPass)
case RecvAns:
log.Debugf("Player %s answered", player.name())
err = g.processAnswer(ctx, player, msg.Answer)
case RecvWager:
log.Debugf("Player %s wagered", player.name())
err = g.processWager(player, msg.Wager)
case RecvDispute:
action := "confirmed"
if !msg.Dispute {
action = "disputed"
}
log.Debugf("Player %s %s the question", player.name(), action)
err = g.processDispute(ctx, player, msg.Dispute)
case PostGame:
log.Debugf("Player %s protested", player.name())
err = g.processProtest(player, msg.ProtestFor)
case PreGame:
err = fmt.Errorf("received unexpected message")
Expand Down
4 changes: 1 addition & 3 deletions be-jeopardy/internal/jeopardy/reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ func (p *Player) processReactions(reactChan chan Reaction) {
if err != nil {
log.Errorf("Error reading reaction message from player %s: %s", p.Name, err.Error())
if websocket.IsCloseError(err, 1001) {
log.Infof("Player %s closed chat connection", p.Name)
log.Infof("Player %s closed reaction connection", p.Name)
}
return
}
var msg Reaction
if err := json.Unmarshal(message, &msg); err != nil {
log.Errorf("Error parsing reaction message: %s", err.Error())
}
log.Infof("Received reaction from player %s: %+v", p.Name, msg)
msg.PlayerName = p.Name
msg.TimeStamp = time.Now().Unix()
msg.RandPos = getRandPos(10, 150)
Expand Down Expand Up @@ -89,7 +88,6 @@ func (p *Player) readReaction() ([]byte, error) {
}

func (p *Player) sendReaction(msg Reaction) error {
log.Infof("Sending reaction to player %s: %+v", p.Name, msg)
if p.ReactionConn == nil {
log.Errorf("Error sending reaction to player %s because connection is nil", p.Name)
return fmt.Errorf("player has no reaction connection")
Expand Down
6 changes: 3 additions & 3 deletions fe-jeopardy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fe-jeopardy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"overrides": {
"@supabase/supabase-js": {
"@supabase/gotrue-js": "2.61.0"
"@supabase/auth-js": "2.61.0"
}
}
}
4 changes: 1 addition & 3 deletions fe-jeopardy/src/app/game/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ChatComponent implements OnInit, AfterViewChecked {
let resp = JSON.parse(event.data)

if (resp.code >= 4400) {
console.log(resp.message)
console.error(resp.message)
this.messages.push({
username: 'Jeopardy System',
message: resp.message,
Expand All @@ -47,8 +47,6 @@ export class ChatComponent implements OnInit, AfterViewChecked {
return
}

console.log(resp)

this.messages.push({
username: resp.name,
message: resp.message,
Expand Down
13 changes: 10 additions & 3 deletions fe-jeopardy/src/app/game/game.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { animate, state, style, transition, trigger } from '@angular/animations'
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { GameState, Ping, Player } from '../model/model'
import { GameStateService } from '../services/game-state.service'
import { JwtService } from '../services/jwt.service'
Expand All @@ -20,7 +21,7 @@ import { WebsocketService } from '../services/websocket.service'
})
export class GameComponent implements OnInit {
private countdownInterval: NodeJS.Timeout
protected gameLink: string
protected joinPath: string
protected gameMessage: string
protected questionAnswer: string
protected wagerAmt: string
Expand All @@ -38,9 +39,15 @@ export class GameComponent implements OnInit {
protected game: GameStateService,
protected player: PlayerService,
private modal: ModalService,
private router: Router,
private route: ActivatedRoute,
) { }

ngOnInit(): void {
this.route.paramMap.subscribe(params => {
let joinCode = params.get('joinCode')
this.joinPath = joinCode ? `/join/${joinCode}` : '/'
})
let showJeopardyMusicInfo = localStorage.getItem('showJeopardyMusicInfo')
if (showJeopardyMusicInfo === null) {
this.showMusicInfo = true
Expand Down Expand Up @@ -74,6 +81,8 @@ export class GameComponent implements OnInit {
if (resp.code >= 4400) {
switch (resp.code) {
case 4400:
this.router.navigate([this.joinPath])
break
case 4401:
case 4500:
this.modal.displayMessage(resp.message)
Expand All @@ -92,8 +101,6 @@ export class GameComponent implements OnInit {
this.player.updatePlayer(resp.curPlayer)
this.gameMessage = resp.message

console.log(resp)

if (resp.code == 4100) {
this.modal.displayMessage(resp.message)
return
Expand Down
3 changes: 1 addition & 2 deletions fe-jeopardy/src/app/game/post-game/post-game.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class PostGameComponent {
playAgain() {
return this.api.PlayAgain().subscribe({
next: (resp: any) => {
console.log(resp)
},
error: (err: any) => {
let msg = err.status != 0 ? err.error.message : ServerUnavailableMsg;
Expand All @@ -53,7 +52,7 @@ export class PostGameComponent {
},
error: (err: any) => {
let msg = err.status != 0 ? err.error.message : ServerUnavailableMsg;
console.log(msg)
console.error(msg)
this.router.navigate(['/'])
},
})
Expand Down
4 changes: 2 additions & 2 deletions fe-jeopardy/src/app/profile/profile.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<div><p>{{ profileUser.email }}</p></div>
<div><p>Date joined: {{ profileUser.dateJoined }}</p></div>
<div *ngIf='user.email == profileUser.email'>
<input id='private-profile' type="checkbox" [(ngModel)]="!user.public" (change)="updateProfileVisibility(false)">
<input id='private-profile' type="checkbox" [(ngModel)]="privateProfile" (change)="updateProfileVisibility(false)">
<label for="private-profile" style="margin-right: 1em;">Private</label>
<input id='public-profile' type="checkbox" [(ngModel)]="user.public" (change)="updateProfileVisibility(true)">
<input id='public-profile' type="checkbox" [(ngModel)]="publicProfile" (change)="updateProfileVisibility(true)">
<label for="public-profile">Public</label>
</div>
<div *ngIf='user.email == profileUser.email'>
Expand Down
16 changes: 16 additions & 0 deletions fe-jeopardy/src/app/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,20 @@ export class ProfileComponent implements OnInit {
}
await this.auth.GetUser()
}

protected get publicProfile(): boolean {
return this.user.public
}

protected get privateProfile(): boolean {
return !this.user.public
}

protected set publicProfile(value: boolean) {
this.user.public = value
}

protected set privateProfile(value: boolean) {
this.user.public = !value
}
}
6 changes: 1 addition & 5 deletions fe-jeopardy/src/app/reactions/reactions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ export class ReactionsComponent {

this.reactions.OnOpen(() => {
this.reactions.Send({ token: this.jwt.GetJWT() })
console.log('Connected to reactions service')
})

this.reactions.OnMessage((event: { data: string }) => {
let resp = JSON.parse(event.data)
console.log('Received reaction:', resp)

if (resp.code >= 4400) {
console.log(resp.reaction)
console.error(resp.reaction)
this.reactionsList.push({
username: 'Jeopardy System',
reaction: resp.reaction,
Expand All @@ -60,8 +58,6 @@ export class ReactionsComponent {
return
}

console.log(resp)

this.reactionsList.push({
username: resp.name,
reaction: resp.reaction,
Expand Down

0 comments on commit b8e6768

Please sign in to comment.