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