Skip to content

Commit

Permalink
Adds audible alert for when its your turn
Browse files Browse the repository at this point in the history
  • Loading branch information
skvrahul committed Jun 7, 2020
1 parent 0e8af33 commit ac2cf6f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/turnIndicator.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import React, { Component } from "react";
import "./styles/turnIndicator.css";
const audio = new Audio(
"https://freesound.org/data/previews/320/320654_5260872-lq.mp3"
);
class TurnIndicator extends Component {
state = {
played: false,
};
render() {
const playerID = this.props.playerID;
const currentPlayer = this.props.currentPlayer;
const iAmActive = currentPlayer === playerID;
if (iAmActive && !this.state.played) {
audio.play();
this.setState({ played: true });
}
if (!iAmActive && this.state.played) {
this.setState({ played: false });
}
return (
<div
className={"turn-indicator " + (iAmActive ? "active" : null)}
Expand Down

0 comments on commit ac2cf6f

Please sign in to comment.