forked from lavender/watch-party
fix votekiss
parent
fb136a1899
commit
437004fb9b
|
@ -5,6 +5,9 @@ import {
|
||||||
} from "./watch-session.mjs?v=048af96";
|
} from "./watch-session.mjs?v=048af96";
|
||||||
import { emojify, findEmojis } from "./emojis.mjs?v=048af96";
|
import { emojify, findEmojis } from "./emojis.mjs?v=048af96";
|
||||||
|
|
||||||
|
let nickname = "";
|
||||||
|
let kisses = {};
|
||||||
|
|
||||||
function setCaretPosition(elem, caretPos) {
|
function setCaretPosition(elem, caretPos) {
|
||||||
if (elem.createTextRange) {
|
if (elem.createTextRange) {
|
||||||
var range = elem.createTextRange();
|
var range = elem.createTextRange();
|
||||||
|
@ -185,12 +188,20 @@ const setupChatboxEvents = (socket) => {
|
||||||
handled = true;
|
handled = true;
|
||||||
break;
|
break;
|
||||||
case "/votekiss":
|
case "/votekiss":
|
||||||
printChatMessage(
|
if(kisses[args]&&kisses[args][nickname])
|
||||||
"vote-kiss",
|
printChatMessage(
|
||||||
"/votekiss",
|
"vote-kiss",
|
||||||
"b57fdc",
|
"/votekiss",
|
||||||
document.createTextNode("you voted to kiss " + args)
|
"b57fdc",
|
||||||
);
|
document.createTextNode("you already voted to kiss " + args)
|
||||||
|
);
|
||||||
|
else
|
||||||
|
printChatMessage(
|
||||||
|
"vote-kiss",
|
||||||
|
"/votekiss",
|
||||||
|
"b57fdc",
|
||||||
|
document.createTextNode("you voted to kiss " + args)
|
||||||
|
);
|
||||||
handled = false;
|
handled = false;
|
||||||
// we also handle this on receive
|
// we also handle this on receive
|
||||||
break;
|
break;
|
||||||
|
@ -235,7 +246,8 @@ const setupChatboxEvents = (socket) => {
|
||||||
/**
|
/**
|
||||||
* @param {WebSocket} socket
|
* @param {WebSocket} socket
|
||||||
*/
|
*/
|
||||||
export const setupChat = async (socket) => {
|
export const setupChat = async (socket, _nickname) => {
|
||||||
|
nickname = _nickname; // We need this for commands
|
||||||
document.querySelector("#chatbox-container").style["display"] = "flex";
|
document.querySelector("#chatbox-container").style["display"] = "flex";
|
||||||
setupChatboxEvents(socket);
|
setupChatboxEvents(socket);
|
||||||
|
|
||||||
|
@ -338,7 +350,6 @@ const formatTime = (ms) => {
|
||||||
}:${seconds < 10 ? "0" + seconds : seconds}`;
|
}:${seconds < 10 ? "0" + seconds : seconds}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
let kisses = {};
|
|
||||||
function handleClientCommand(content, user) {
|
function handleClientCommand(content, user) {
|
||||||
let handled = false;
|
let handled = false;
|
||||||
if (content.startsWith("/")) {
|
if (content.startsWith("/")) {
|
||||||
|
@ -348,7 +359,7 @@ function handleClientCommand(content, user) {
|
||||||
case "/votekiss":
|
case "/votekiss":
|
||||||
kisses[args] = kisses[args] || {};
|
kisses[args] = kisses[args] || {};
|
||||||
kisses[args][user] = true;
|
kisses[args][user] = true;
|
||||||
if (Object.keys(kisses[args]).length > 3) {
|
if (Object.keys(kisses[args]).length >= 3) {
|
||||||
printChatMessage(
|
printChatMessage(
|
||||||
"user-kissed",
|
"user-kissed",
|
||||||
args,
|
args,
|
||||||
|
@ -386,7 +397,7 @@ export const logEventToChat = async (event) => {
|
||||||
event.colour,
|
event.colour,
|
||||||
document.createTextNode("left")
|
document.createTextNode("left")
|
||||||
);
|
);
|
||||||
for (let kissed in kisses) delete kisses[kissed][user];
|
for (let kissed in kisses) delete kisses[kissed][event.user];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "ChatMessage": {
|
case "ChatMessage": {
|
||||||
|
|
|
@ -220,7 +220,7 @@ export const joinSession = async (nickname, sessionId, colour) => {
|
||||||
|
|
||||||
setupOutgoingEvents(video, socket);
|
setupOutgoingEvents(video, socket);
|
||||||
setupIncomingEvents(video, socket);
|
setupIncomingEvents(video, socket);
|
||||||
setupChat(socket);
|
setupChat(socket, nickname);
|
||||||
});
|
});
|
||||||
socket.addEventListener("reconnecting", (e) => {
|
socket.addEventListener("reconnecting", (e) => {
|
||||||
console.log("Reconnecting...");
|
console.log("Reconnecting...");
|
||||||
|
|
Loading…
Reference in New Issue