Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: notifyMe while players >= 3 #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions js/wsClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@
});
}

function notifyMe(text) {
if (!("Notification"in window)) {
console.log("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
const notification = new Notification(text);
} else if (Notification.permission !== "denied") {
Notification.requestPermission().then((permission)=>{
if (permission === "granted") {
const notification = new Notification(text);
}
}
);
}
}

WsClient.prototype.initWebsocketConnect = function(resolve, reject) {
if (window.WebSocket) {
this.socket = new WebSocket(this.url);
Expand All @@ -98,6 +113,16 @@
window.is = false;
}else{
window.wsClient.panel.append(htmlEscape(msg))
if(msg.includes("Game starting!")) {
notifyMe("Windows 11 Update Notification!");
}
if (msg.includes("room current has")) {
if (msg.split("room current has")[1].match(/\d+/) >= 3) {
notifyMe("Windows 11 Update Notification!");
} else {
//this.sendMsg("Please waiting for another one!");
}
}
}
};
this.socket.onopen = (event) => {
Expand Down