-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from HyeokjinKang/socket.io
feat: socket.io
- Loading branch information
Showing
20 changed files
with
331 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
.achievementOverlay { | ||
letter-spacing: 0px; | ||
z-index: 999; | ||
position: fixed; | ||
width: 100vw; | ||
height: 10vh; | ||
left: 0; | ||
bottom: 0; | ||
pointer-events: none; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
animation: achievementOverlay 4s cubic-bezier(0.75, 0, 0.25, 1) forwards; | ||
transition-duration: 0.8s; | ||
transition-timing-function: cubic-bezier(0.65, 0, 0.35, 1); | ||
} | ||
|
||
@keyframes achievementOverlay { | ||
0% { | ||
opacity: 0; | ||
transform: translateY(10vh); | ||
} | ||
20% { | ||
opacity: 1; | ||
transform: translateY(0vh); | ||
} | ||
80% { | ||
opacity: 1; | ||
} | ||
100% { | ||
opacity: 0; | ||
} | ||
} | ||
|
||
.achievementInner { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 0vh 1.3vw; | ||
background-color: rgba(0, 0, 0, 0.7); | ||
border-radius: 0.7vh; | ||
height: 6vh; | ||
box-shadow: 0 0.5vh 2vh 1vh rgba(0, 0, 0, 0.3); | ||
} | ||
|
||
.achievementInner::before { | ||
content: ""; | ||
width: auto; | ||
height: auto; | ||
filter: blur(4px); | ||
} | ||
|
||
.achievementInnerLeft { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.achievementMedal { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
border: 1px solid white; | ||
border-radius: 100vw; | ||
padding: 2px 0.4vw; | ||
margin-right: 0.7vw; | ||
} | ||
|
||
.achievementMedal > img { | ||
height: 1.5vh; | ||
} | ||
|
||
.achievementContentVertical { | ||
color: white; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
justify-content: center; | ||
} | ||
|
||
.achievementContentTitle { | ||
font-size: 1.4vh; | ||
font-weight: 600; | ||
} | ||
|
||
.achievementContentDesc { | ||
margin-top: 0.2vh; | ||
font-size: 1.1vh; | ||
font-weight: 300; | ||
} | ||
|
||
.achievementLine { | ||
width: 1px; | ||
height: 2vh; | ||
background-color: white; | ||
margin-left: 2vw; | ||
margin-right: 0.7vw; | ||
} | ||
|
||
.achievementInnerRight { | ||
color: white; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.achievementRewardTitle { | ||
font-size: 1vh; | ||
font-weight: 300; | ||
} | ||
|
||
.achievementRewardDesc { | ||
margin-top: 0.4vh; | ||
font-size: 1.1vh; | ||
font-weight: 500; | ||
} |
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
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
const body = document.querySelector("body"); | ||
let isErrorOccured = false; | ||
let achievementCount = 0; | ||
const socket = io(game, { | ||
withCredentials: true, | ||
}); | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
const img = new Image(); | ||
img.src = "/images/parts/icons/medal-solid.svg"; | ||
const div = document.createElement("div"); | ||
div.id = "achievementsContainer"; | ||
body.appendChild(div); | ||
}); | ||
|
||
socket.on("connect", () => { | ||
console.log("[Socket.IO] Connected to server"); | ||
if (isErrorOccured) { | ||
iziToast.success({ | ||
title: "Connected", | ||
message: socketi18n.connected, | ||
timeout: 2000, | ||
layout: 2, | ||
transitionIn: "fadeInLeft", | ||
}); | ||
} | ||
}); | ||
|
||
socket.on("disconnect", (reason) => { | ||
if (reason === "io server disconnect") { | ||
alert(socketi18n.error); | ||
window.location.href = `${api}/auth/logout?redirect=true`; // Session error, need to relogin | ||
} else if (reason === "io client disconnect") return; | ||
console.error("[Socket.IO] Disconnected from server"); | ||
iziToast.warning({ | ||
title: "Disconnected", | ||
message: socketi18n.reconnecting, | ||
timeout: 2000, | ||
layout: 2, | ||
transitionIn: "fadeInLeft", | ||
}); | ||
isErrorOccured = true; | ||
}); | ||
|
||
socket.on("connect_error", () => { | ||
console.error("[Socket.IO] Cannot connect to server"); | ||
iziToast.error({ | ||
title: "Connection error", | ||
message: socketi18n.reconnecting, | ||
timeout: 2000, | ||
layout: 2, | ||
transitionIn: "fadeInLeft", | ||
}); | ||
setTimeout(() => { | ||
socket.connect(); | ||
}, 1000); | ||
isErrorOccured = true; | ||
}); | ||
|
||
socket.on("connection:conflict", () => { | ||
socket.disconnect(); | ||
alert(socketi18n.conflict); | ||
window.location.href = `${api}/auth/logout?redirect=true`; | ||
}); | ||
|
||
socket.on("connection:unauthorized", () => { | ||
socket.disconnect(); | ||
alert(socketi18n.unauthorized); | ||
window.location.href = `${api}/auth/logout?redirect=true`; | ||
}); | ||
|
||
socket.on("achievement", (data) => { | ||
data = JSON.parse(data); | ||
console.log("[Socket.IO] Achievement"); | ||
console.log(data); | ||
data.rewards.forEach((reward) => { | ||
[...document.getElementsByClassName("achievementOverlay")].forEach((element, i) => { | ||
element.style.bottom = `${7 * (i + 1)}vh`; | ||
}); | ||
const div = document.createElement("div"); | ||
div.classList.add("achievementOverlay"); | ||
document.getElementById("achievementsContainer").appendChild(div); | ||
document.getElementsByClassName("achievementOverlay")[achievementCount].innerHTML = ` | ||
<div class="achievementInner"> | ||
<div class="achievementInnerLeft"> | ||
<div class="achievementMedal"> | ||
<img src="/images/parts/icons/medal-solid.svg" /> | ||
</div> | ||
<div class="achievementContentVertical"> | ||
<span class="achievementContentTitle">${data[`title_${lang}`]}</span> | ||
<span class="achievementContentDesc">${data[`detail_${lang}`]}</span> | ||
</div> | ||
</div> | ||
<div class="achievementLine"></div> | ||
<div class="achievementInnerRight"> | ||
<span class="achievementRewardTitle">${socketi18n[reward[0]]}</span> | ||
<span class="achievementRewardDesc">${getReward(reward[0], reward[1])}</span> | ||
</div> | ||
</div>`; | ||
achievementCount++; | ||
setTimeout(() => { | ||
achievementCount--; | ||
document.getElementsByClassName("achievementOverlay")[0].remove(); | ||
}, 4000); | ||
}); | ||
}); | ||
|
||
const getReward = (type, id) => { | ||
if (type == "reward") return "-"; | ||
if (type == "alias") return alias[id]; | ||
}; | ||
|
||
const ping = setInterval(() => { | ||
socket.emit("ping"); | ||
}, 5000); |
Oops, something went wrong.