Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*jshint esversion: 8 */
- (function () {
- 'use strict';
- let StumbleChat = {
- Version: "3.0.26",
- WebSocket: null,
- Room: {},
- Self: {},
- Userlist: {
- Resizable: true,
- Resized: false,
- list: undefined,
- User: new Map(),
- SortedUsers: [],
- Broadcast: new Map(),
- Count: () => document.querySelector("#onlinecount").innerText = StumbleChat.Userlist.User.size,
- Profile: (handle) => {
- if (StumbleChat.Userlist.User.get(handle).guest == 1) return Message.receive.public(`${(handle == StumbleChat.Self.handle) ? "You are" : StumbleChat.Userlist.User.get(handle).nick + " is"} in the room as a guest.`);
- let Profile = new XMLHttpRequest();
- Profile.onload = () => {
- if (Profile.status == 429) return Message.receive.public(`Please wait to view anymore profiles.`);
- try {
- let parse = JSON.parse(Profile.responseText);
- if (parse.error !== undefined) return;
- parse.handle = handle;
- Modal.Create(11, parse);
- } catch (e) {
- return Message.receive.public(`There was a problem loading the profile, try again.`);
- }
- };
- Profile.open("POST", `https://${window.location.hostname}/api/profile`, true);
- Profile.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
- Profile.setRequestHeader("CSRF-Token", document.getElementsByName('_csrf')[ 0 ].getAttribute("content"));
- Profile.send(JSON.stringify({ name: StumbleChat.Userlist.User.get(handle).username }));
- },
- Resize: () => {
- if (window.innerWidth > 652) {
- if (!StumbleChat.Userlist.Resizable) document.querySelector(".resizeuser").classList.remove("hidden");
- StumbleChat.Userlist.Resizable = true;
- } else {
- if (StumbleChat.Userlist.Resizable) {
- document.querySelector(".resizeuser").classList.add("hidden");
- document.querySelector("sc-userlist>.resizeuser").classList.remove("left");
- document.querySelector("sc-userlist").style = "";
- StumbleChat.Userlist.Resized = false;
- }
- StumbleChat.Userlist.Resizable = false;
- }
- },
- Organize: (handle) => {
- StumbleChat.Userlist.SortedUsers = StumbleChat.Userlist.SortedUsers.sort((c, a) => (a.mod > c.mod) ? 1 : (a.mod < c.mod) ? -1 : c.nick.toLowerCase().localeCompare(a.nick.toLowerCase()));
- for (let i = 0; i < StumbleChat.Userlist.SortedUsers.length; i++) {
- if (StumbleChat.Userlist.User.get(handle).mod > StumbleChat.Userlist.SortedUsers[ i ].mod) return document.querySelector(`#userlist>.list`).insertBefore(document.querySelector(`.bar[user-id="${handle}"]`), document.querySelector(`.bar[user-id="${StumbleChat.Userlist.SortedUsers[ i ].handle}"]`));
- if (StumbleChat.Userlist.User.get(handle).mod == StumbleChat.Userlist.SortedUsers[ i ].mod && StumbleChat.Userlist.SortedUsers[ i ].nick.toLowerCase().localeCompare(StumbleChat.Userlist.User.get(handle).nick.toLowerCase()) == 1) return document.querySelector(`#userlist>.list`).insertBefore(document.querySelector(`.bar[user-id="${handle}"]`), document.querySelector(`.bar[user-id="${StumbleChat.Userlist.SortedUsers[ i ].handle}"]`));
- }
- document.querySelector(`#userlist>.list`).lastChild.parentNode.insertBefore(document.querySelector(`.bar[user-id="${handle}"]`), document.querySelector(`#userlist>.list`).lastChild.nextSibling);
- },
- Menu: {
- Element: null,
- State: 0,
- Task: null,
- Display: (handle) => {
- StumbleChat.Userlist.Menu.State = 1;
- let menu_items = document.querySelectorAll(".user-menu-item");
- document.querySelector(".user-menu-name").innerText = StumbleChat.Userlist.User.get(handle).nick;
- menu_items[ 0 ].classList[ (StumbleChat.Self.handle != handle) ? "add" : "remove" ]("hidden"); // Nickname
- menu_items[ 2 ].classList[ (StumbleChat.Self.handle == handle) ? "add" : "remove" ]("hidden"); // Private Message
- menu_items[ 3 ].classList.add("hidden"); // hide
- menu_items[ 4 ].classList.add("hidden"); // unhide
- if (StumbleChat.Userlist.User.get(handle).broadcasting.length || StumbleChat.Userlist.Broadcast.has(handle)) {
- if (StumbleChat.Self.handle == handle) {
- menu_items[ 3 ].classList[ (StumbleChat.Self.Hidden) ? "add" : "remove" ]("hidden"); // Hide
- menu_items[ 4 ].classList[ (StumbleChat.Self.Hidden) ? "remove" : "add" ]("hidden"); // Unhide
- } else {
- menu_items[ 3 ].classList[ (StumbleChat.Chat.Settings.HideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase()) || StumbleChat.Chat.Settings.TempHideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase())) ? "add" : "remove" ]("hidden"); // hide
- menu_items[ 4 ].classList[ (StumbleChat.Chat.Settings.HideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase()) || StumbleChat.Chat.Settings.TempHideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase())) ? "remove" : "add" ]("hidden"); // unhide
- }
- }
- if (StumbleChat.Self.handle == handle) {
- menu_items[ 5 ].classList.add("hidden"); // grant super
- menu_items[ 6 ].classList.add("hidden"); // grant moderator
- menu_items[ 7 ].classList.add("hidden"); // grant operator
- menu_items[ 8 ].classList.add("hidden"); // revoke
- menu_items[ 9 ].classList.add("hidden"); // close broadcast
- menu_items[ 10 ].classList.add("hidden"); // kick
- menu_items[ 11 ].classList.add("hidden"); // ban
- menu_items[ 12 ].classList.add("hidden"); // ignore
- menu_items[ 13 ].classList.add("hidden"); // unignore
- menu_items[ 14 ].classList.add("hidden"); // abuse
- } else {
- if (StumbleChat.Self.mod >= 2) { // Moderator
- menu_items[ 5 ].classList[ (StumbleChat.Userlist.User.get(handle).mod < 4 && StumbleChat.Self.mod >= 4 && StumbleChat.Userlist.User.get(handle).mod != 3 && StumbleChat.Userlist.User.get(handle).guest == false) ? "remove" : "add" ]("hidden"); // grant super
- menu_items[ 6 ].classList[ (StumbleChat.Userlist.User.get(handle).mod < 4 && StumbleChat.Self.mod >= 3 && StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod && StumbleChat.Userlist.User.get(handle).mod != 2 && StumbleChat.Userlist.User.get(handle).guest == false) ? "remove" : "add" ]("hidden"); // grant moderator
- menu_items[ 7 ].classList[ (StumbleChat.Userlist.User.get(handle).mod < 4 && StumbleChat.Self.mod >= 2 && StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod && StumbleChat.Userlist.User.get(handle).mod != 1 && StumbleChat.Userlist.User.get(handle).guest == false) ? "remove" : "add" ]("hidden"); // grant operator
- menu_items[ 8 ].classList[ (StumbleChat.Userlist.User.get(handle).mod < 4 && StumbleChat.Self.mod >= 2 && StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod && StumbleChat.Userlist.User.get(handle).mod > 0 && StumbleChat.Userlist.User.get(handle).guest == false) ? "remove" : "add" ]("hidden"); // revoke
- menu_items[ 9 ].classList[ (StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod && StumbleChat.Userlist.Broadcast.has(handle)) ? "remove" : "add" ]("hidden"); // close broadcast
- menu_items[ 10 ].classList[ (StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod) ? "remove" : "add" ]("hidden"); // kick
- menu_items[ 11 ].classList[ (StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod) ? "remove" : "add" ]("hidden"); // ban
- } else {
- menu_items[ 5 ].classList.add("hidden"); // grant super
- menu_items[ 6 ].classList.add("hidden"); // grant moderator
- menu_items[ 7 ].classList.add("hidden"); // grant operator
- menu_items[ 8 ].classList.add("hidden"); // revoke
- menu_items[ 9 ].classList.add("hidden"); // close broadcast
- menu_items[ 10 ].classList.add("hidden"); // kick
- menu_items[ 11 ].classList.add("hidden"); // ban
- }
- if (StumbleChat.Self.mod == 5) {
- menu_items[ 12 ].classList.add("hidden"); // ignore
- menu_items[ 13 ].classList.add("hidden"); // unignore
- } else {
- menu_items[ 12 ].classList[ (StumbleChat.Chat.Settings.IgnoredList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase()) || StumbleChat.Chat.Settings.TempIgnoredList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase())) ? "add" : "remove" ]("hidden"); // ignore
- menu_items[ 13 ].classList[ (StumbleChat.Chat.Settings.IgnoredList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase()) || StumbleChat.Chat.Settings.TempIgnoredList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase())) ? "remove" : "add" ]("hidden"); // unignore
- }
- menu_items[ 14 ].classList.remove("hidden"); // abuse
- }
- StumbleChat.Userlist.Menu.Element.classList.add(`user-menu-active`);
- },
- Hide: () => {
- if (StumbleChat.Userlist.Menu.State !== 0) {
- StumbleChat.Userlist.Menu.State = 0;
- if (StumbleChat.Userlist.Menu.Element) StumbleChat.Userlist.Menu.Element.classList.remove(`user-menu-active`);
- }
- StumbleChat.Userlist.Menu.Listen();
- },
- Position: (e) => {
- let clickCoords = StumbleChat.GUI.Pointer.Position(e);
- let menuWidth = StumbleChat.Userlist.Menu.Element.offsetWidth + 4;
- let menuHeight = StumbleChat.Userlist.Menu.Element.offsetHeight + 4;
- StumbleChat.Userlist.Menu.Element.style.left = ((window.innerWidth - clickCoords.x) < menuWidth) ? window.innerWidth - menuWidth + "px" : clickCoords.x + "px";
- StumbleChat.Userlist.Menu.Element.style.top = (((window.innerHeight - clickCoords.y) < menuHeight)) ? window.innerHeight - menuHeight + "px" : clickCoords.y + "px";
- },
- Listen: () => {
- document.addEventListener("pointerup", (e) => {
- StumbleChat.Userlist.Menu.Task = StumbleChat.GUI.Element.Exists(e, "bar");
- if (e.target.classList.contains("unreadmessage")) {
- StumbleChat.Chat.Scroll(true);
- } else if (StumbleChat.Userlist.Menu.Task) {
- let handle = StumbleChat.Userlist.Menu.Task.getAttribute("user-id");
- StumbleChat.Userlist.Menu.Element.setAttribute("user-id", handle);
- e.preventDefault();
- StumbleChat.Userlist.Menu.Display(handle);
- StumbleChat.Userlist.Menu.Position(e);
- }
- }, {
- once: true
- });
- },
- Check: () => {
- document.addEventListener("pointerup", (e) => {
- let elem = StumbleChat.GUI.Element.Exists(e, `user-menu-link`);
- if (elem) {
- e.preventDefault();
- let handle = StumbleChat.Userlist.Menu.Element.getAttribute("user-id");
- if (handle != null && StumbleChat.Userlist.User.has(handle) && elem.getAttribute("data-action") !== null) StumbleChat.Userlist.Menu.Item[ elem.getAttribute("data-action") ](handle);
- }
- });
- },
- Item: {
- nickname: () => Modal.Create(5),
- profile: (handle) => StumbleChat.Userlist.Profile(handle),
- close: (handle) => StumbleChat.WebSocket.send(`{"stumble":"close","handle":"${handle}"}`),
- kick: (handle) => StumbleChat.WebSocket.send(`{"stumble":"kick","handle":"${handle}"}`),
- ban: (handle) => StumbleChat.WebSocket.send(`{"stumble":"ban","handle":"${handle}"}`),
- grantsuper: (handle) => StumbleChat.WebSocket.send(`{"stumble":"role","type":"super","handle":"${handle}"}`),
- grantmoderator: (handle) => StumbleChat.WebSocket.send(`{"stumble":"role","type":"moderator","handle":"${handle}"}`),
- grantoperator: (handle) => StumbleChat.WebSocket.send(`{"stumble":"role","type":"operator","handle":"${handle}"}`),
- revoke: (handle) => StumbleChat.WebSocket.send(`{"stumble":"role","type":"revoke","handle":"${handle}"}`),
- pvtmsg: (handle) => {
- if (StumbleChat.Chat.Selected !== handle) document.querySelector(".unreadmessage").classList.add("hidden");
- if (StumbleChat.Userlist.User.has(handle)) {
- StumbleChat.Chat.Selected = handle;
- document.querySelector("#chat-position>#back").classList.add("show");
- document.querySelector("#chat-position>#back").innerHTML = `‹ ${StumbleChat.Userlist.User.get(handle).nick} (${(StumbleChat.Userlist.User.get(handle).guest == 0) ? StumbleChat.Userlist.User.get(handle).username : "guest"})`;
- document.getElementById("chat-content").innerHTML = "";
- let PM = document.querySelector(".privateMessages");
- if (!StumbleChat.Chat.Messages.has(handle)) StumbleChat.Chat.Messages.set(handle, {
- username: (StumbleChat.Userlist.User.get(handle).guest == 0) ? StumbleChat.Userlist.User.get(handle).username : "guest",
- avatar: StumbleChat.Userlist.User.get(handle).avatar,
- nick: StumbleChat.Userlist.User.get(handle).nick,
- missedmsg: 0,
- message: [],
- namebackgroundcolor: StumbleChat.Userlist.User.get(handle).namebackgroundcolor,
- backgroundcolor: StumbleChat.Userlist.User.get(handle).backgroundcolor,
- messagetextcolor: StumbleChat.Userlist.User.get(handle).messagetextcolor
- });
- if (!PM.querySelector(`[user-id="${handle}"]`)) {
- document.querySelector("#userlist>h2:nth-child(2)").classList.remove("hidden");
- PM.classList.remove("hidden");
- let element = document.createElement('div');
- element.setAttribute("class", "list-item");
- element.innerHTML = `<span class="private" user-id=${handle}><div class="nickname">${StumbleChat.Userlist.User.get(handle).nick}</div><div class="unreadpm"></div><span class="closepm">x</span></span>`;
- document.querySelector(".privateMessages").insertAdjacentHTML("afterBegin", element.outerHTML);
- } else {
- StumbleChat.Chat.Messages.get(handle).missedmsg = 0;
- PM.querySelector(".unreadpm").innerText = StumbleChat.Chat.Messages.get(handle).missedmsg;
- PM.querySelector(".unreadpm").classList.remove("show");
- }
- if (document.querySelector(`.selected`)) document.querySelector(`.selected`).classList.remove("selected");
- PM.querySelector(`[user-id="${handle}"]`).classList.add("selected");
- StumbleChat.Chat.Messages.get(handle).message.forEach((value, index) => {
- if (index > 0) {
- if (value.nick == StumbleChat.Chat.Messages.get(handle).message[ index - 1 ].nick && value.handle == StumbleChat.Chat.Messages.get(handle).message[ index - 1 ].handle) {
- let element = document.createElement("div");
- element.setAttribute("class", "content");
- element.innerHTML = `<span class="hidden-selectable">[${value.time}]</span><span class="timestamp">${value.time}</span><span class="message common" style="color:${value.messagetextcolor}">${value.msg}</span></div>`;
- document.querySelector("#chat-content>.message:last-child").appendChild(element);
- } else {
- createChatItem(value);
- }
- } else {
- createChatItem(value);
- }
- });
- StumbleChat.Chat.Scroll(true);
- document.querySelector("#textarea").focus();
- }
- },
- hide: (handle) => {
- if (StumbleChat.Self.handle == handle) {
- StumbleChat.Self.Hidden = true;
- Message.receive.public(`You are now hidden.`);
- } else {
- if (!StumbleChat.Userlist.User.get(handle).guest) {
- StumbleChat.Chat.Settings.HideList.push(StumbleChat.Userlist.User.get(handle).username.toUpperCase());
- localStorage.setItem('HideList', JSON.stringify(StumbleChat.Chat.Settings.HideList));
- } else {
- StumbleChat.Chat.Settings.TempHideList.push(StumbleChat.Userlist.User.get(handle).username.toUpperCase());
- }
- Message.receive.public(`${StumbleChat.Userlist.User.get(handle).nick} has been hidden, you will not see and hear them anymore.`);
- }
- StumbleChat.Videos.View(handle);
- },
- unhide: (handle) => {
- if (StumbleChat.Self.handle == handle) {
- StumbleChat.Self.Hidden = false;
- Message.receive.public(`You are now unhidden.`);
- } else {
- if (!StumbleChat.Userlist.User.get(handle).guest) {
- for (let i = 0; i < StumbleChat.Chat.Settings.HideList.length; i++) {
- if (StumbleChat.Chat.Settings.HideList[ i ] == StumbleChat.Userlist.User.get(handle).username.toUpperCase()) StumbleChat.Chat.Settings.HideList.splice(i, 1);
- }
- localStorage.setItem('HideList', JSON.stringify(StumbleChat.Chat.Settings.HideList));
- } else {
- for (let i = 0; i < StumbleChat.Chat.Settings.TempHideList.length; i++) {
- if (StumbleChat.Chat.Settings.TempHideList[ i ] == StumbleChat.Userlist.User.get(handle).username.toUpperCase()) StumbleChat.Chat.Settings.TempHideList.splice(i, 1);
- }
- }
- Message.receive.public(`${StumbleChat.Userlist.User.get(handle).nick} is unhidden, you can see and hear them again.`);
- }
- StumbleChat.Videos.View(handle);
- },
- ignore: (handle) => {
- if (!StumbleChat.Userlist.User.has(handle)) return;
- document.querySelector(`.bar[user-id="${handle}"] .nickname`).innerHTML = `<s>${StumbleChat.Userlist.User.get(handle).nick}</s>`;
- if (!StumbleChat.Userlist.User.get(handle).guest) {
- StumbleChat.Chat.Settings.IgnoredList.push(StumbleChat.Userlist.User.get(handle).username.toUpperCase());
- localStorage.setItem('IgnoredList', JSON.stringify(StumbleChat.Chat.Settings.IgnoredList));
- } else {
- StumbleChat.Chat.Settings.TempIgnoredList.push(StumbleChat.Userlist.User.get(handle).username.toUpperCase());
- }
- Message.receive.public(`User has been ignored, you will not see their messages.`);
- },
- unignore: (handle) => {
- document.querySelector(`.bar[user-id="${handle}"] .nickname`).innerHTML = `${StumbleChat.Userlist.User.get(handle).nick}`;
- if (!StumbleChat.Userlist.User.get(handle).guest) {
- for (let i = 0; i < StumbleChat.Chat.Settings.IgnoredList.length; i++) {
- if (StumbleChat.Chat.Settings.IgnoredList[ i ] == StumbleChat.Userlist.User.get(handle).username.toUpperCase()) StumbleChat.Chat.Settings.IgnoredList.splice(i, 1);
- }
- localStorage.setItem('IgnoredList', JSON.stringify(StumbleChat.Chat.Settings.IgnoredList));
- } else {
- for (let i = 0; i < StumbleChat.Chat.Settings.IgnoredList.length; i++) {
- if (StumbleChat.Chat.Settings.TempIgnoredList[ i ] == StumbleChat.Userlist.User.get(handle).username.toUpperCase()) StumbleChat.Chat.Settings.TempIgnoredList.splice(i, 1);
- }
- }
- Message.receive.public(`User has been unignored, you will now see their messages.`);
- },
- abuse: (handle) => {
- Message.receive.public(`User has been reported to admins!`);
- StumbleChat.WebSocket.send(`{"stumble":"abuse","handle":"${handle}"}`);
- },
- }
- }
- },
- Chat: {
- Resizable: true,
- Resized: false,
- Password: undefined,
- Scroll: (opt) => (StumbleChat.Chat.Settings.Scroll || opt !== undefined) ? document.getElementById("chat").scrollTop = document.getElementById("chat").scrollHeight : 0,
- Selected: 0,
- Resize: () => {
- if (window.innerWidth > 652) {
- if (!StumbleChat.Chat.Resizable) document.querySelector(".resizechat").classList.remove("hidden");
- StumbleChat.Chat.Resizable = true;
- } else {
- if (StumbleChat.Chat.Resizable) {
- document.querySelector(".resizechat").classList.add("hidden");
- document.querySelector("sc-chat>.resizechat").classList.remove("right");
- document.querySelector("sc-chat").style = "";
- StumbleChat.Chat.Resized = false;
- }
- StumbleChat.Chat.Resizable = false;
- }
- },
- Background: {
- Set: () => {
- let Image = document.getElementById("modal-text-input").value;
- let BGColor = document.getElementById("modal-bgcolor-input").value;
- if (Image == "") {
- if ((BGColor.match(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/) != null || BGColor.match(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/) != null)) {
- if (StumbleChat.Chat.Settings.background != BGColor) {
- StumbleChat.Chat.Settings.background = BGColor;
- StumbleChat.Chat.Settings.backgroundUrl = "";
- localStorage.setItem("background", StumbleChat.Chat.Settings.background);
- localStorage.setItem("backgroundUrl", "");
- StumbleChat.Chat.Background.Load();
- Modal.Destroy();
- }
- }
- } else {
- if (Image.match(/([a-z\-_0-9\/\:\.]*\.(jpg|jpeg|png|gif))/i) != null) {
- StumbleChat.Chat.Settings.backgroundUrl = Image;
- StumbleChat.Chat.Settings.background = `url("${Image}") 0% 0% / cover no-repeat rgb(1, 1, 1)`;
- localStorage.setItem("background", StumbleChat.Chat.Settings.background);
- localStorage.setItem("backgroundUrl", Image);
- StumbleChat.Chat.Background.Load();
- Modal.Destroy();
- }
- }
- },
- Load: () => document.querySelector("body").style.background = StumbleChat.Chat.Settings.background,
- Reset: () => {
- StumbleChat.Chat.Settings.background = "#111111";
- StumbleChat.Chat.Settings.backgroundUrl = "";
- localStorage.setItem("background", StumbleChat.Chat.Settings.background);
- localStorage.setItem("backgroundUrl", "");
- StumbleChat.Chat.Background.Load();
- Modal.Destroy();
- }
- },
- Color: {
- Set: () => {
- let Color = document.getElementById("modal-color-input").value;
- if (Color.match(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/) !== null || Color.match(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/) !== null) {
- StumbleChat.Chat.Settings.chatcolor = Color;
- localStorage.setItem("chatcolor", StumbleChat.Chat.Settings.chatcolor);
- StumbleChat.Chat.Color.Load();
- Modal.Destroy();
- }
- },
- Load: () => {
- document.querySelector("#chat-wrapper").style.background = StumbleChat.Chat.Settings.chatcolor + "94";
- document.querySelector("#userlist").style.background = StumbleChat.Chat.Settings.chatcolor + "94";
- },
- Reset: () => {
- StumbleChat.Chat.Settings.chatcolor = "#000000";
- localStorage.setItem("chatcolor", StumbleChat.Chat.Settings.chatcolor);
- StumbleChat.Chat.Color.Load();
- Modal.Destroy();
- }
- },
- setTopic: () => {
- let topic = document.getElementById("room-topic").value;
- if (topic === undefined) return;
- if (typeof topic !== "string") return;
- if (topic.length > 200) return Message.receive.public(`Room topic is considerably large, keep it 8-60 characters.`);
- StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "room", "type": "topic", "topic": topic }));
- Modal.Destroy();
- },
- setBroadcastPassword: (clear) => {
- let password = document.getElementById("broadcast-password").value;
- if (!clear) {
- if (typeof password != "string") return;
- if (password.length > 60) return Message.receive.public(`Broadcasting password is considerably large, keep it 8-60 characters.`);
- if (password.length < 8) return Message.receive.public(`Broadcasting password is considerably small, keep it 8-60 characters.`);
- } else if (!StumbleChat.Room.broadcast_password) return Message.receive.public(`There's currently no broadcasting password set.`);
- StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "room", "type": "broadcast_password", "password": (clear) ? null : password }));
- Modal.Destroy();
- },
- Settings: {
- Scroll: true,
- FeaturedResize: false,
- isMobile: false,
- SaveEnabled: false,
- YouTubeEnabled: true,
- TwitchEnabled: true,
- SoundCloudEnabled: true,
- WSHHEnabled: true,
- DailyMotionEnabled: true,
- SoundmeterEnabled: true,
- PrivateMessageEnabled: true,
- SoundsEnabled: true,
- IgnoredList: [],
- HideList: [],
- TempIgnoredList: [],
- TempHideList: [],
- ChatSide: true,
- RoomVolume: 0,
- LinksEnabled: true,
- ImgurEnabled: true,
- audiodevice: "NONE",
- videodevice: "NONE",
- YouTubeStartTime: 0,
- YouTubeQueueID: undefined,
- YouTubePausedTime: new Date(),
- YouTubeClicked: true,
- LargeEmbeddedVideos: false,
- LargeFont: false,
- BroadcastVolume: new Map(),
- TempBroadcastVolume: new Map()
- },
- Status: {
- Resets: 0,
- MissedMsg: 0,
- Timelastpost: new Date(),
- Kicked: false,
- AdjustingQueue: false,
- ModalOpened: -1,
- ModalState: 2,
- LoadedEventListenersInit: false,
- LoadedEventListenersJoined: false,
- Playing: {
- SoundCloud: false,
- WSSH: false,
- DailyMotion: false,
- Twitch: false,
- YouTube: false
- }
- },
- Sounds: {
- public_message: new Audio('../sounds/message.mp3'),
- private_message: new Audio('../sounds/private_message.mp3')
- },
- Messages: new Map(),
- },
- Videos: {
- Resolutions: [
- [ 352, 240 ],
- [ 480, 360 ],
- [ 852, 480 ],
- [ 1280, 720 ],
- [ 1920, 1080 ],
- [ 4096, 2160 ]
- ],
- Device: null,
- AudioPaused: true,
- OpenMic: false,
- AudioAwaitingPause: false,
- Password: undefined,
- Soundmeter: (handle, stream) => {
- if (StumbleChat.Chat.Settings.SoundmeterEnabled) {
- StumbleChat.Userlist.Broadcast.get(handle).spectrum = window.hark(stream, {});
- let parent = StumbleChat.Userlist.Broadcast.get(handle).element.parentElement;
- parent.classList.add("visualizer");
- parent.setAttribute("volume", 0);
- StumbleChat.Userlist.Broadcast.get(handle).spectrum.on('volume_change', (volume) => {
- if (volume <= -100) parent.setAttribute("volume", 0);
- if (volume >= -100) parent.setAttribute("volume", 1);
- if (volume >= -95) parent.setAttribute("volume", 2);
- if (volume >= -90) parent.setAttribute("volume", 3);
- if (volume >= -80) parent.setAttribute("volume", 4);
- if (volume >= -70) parent.setAttribute("volume", 5);
- if (volume >= -60) parent.setAttribute("volume", 6);
- if (volume >= -50) parent.setAttribute("volume", 7);
- if (volume >= -40) parent.setAttribute("volume", 8);
- if (volume >= -30) parent.setAttribute("volume", 9);
- if (volume >= -15) parent.setAttribute("volume", 10);
- });
- }
- },
- View: (handle) => {
- if (StumbleChat.Self.handle == handle) {
- if (StumbleChat.Userlist.Broadcast.get(handle).video !== null) {
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(1)`).classList[ StumbleChat.Self.Hidden ? "remove" : "add" ]("video_badge");
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(1)`).classList[ StumbleChat.Self.Hidden ? "add" : "remove" ]("video_badge_hide");
- StumbleChat.Userlist.Broadcast.get(handle).video.track.enabled = !StumbleChat.Self.Hidden;
- }
- } else {
- if (StumbleChat.Userlist.User.get(handle).broadcasting.length > 0) {
- if (StumbleChat.Chat.Settings.HideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase()) || StumbleChat.Chat.Settings.TempHideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase())) {
- clearTimeout(StumbleChat.Userlist.User.get(handle).disconnecttimer);
- if (StumbleChat.Userlist.Broadcast.has(handle)) {
- if (StumbleChat.Userlist.Broadcast.get(handle).spectrum !== undefined) StumbleChat.Userlist.Broadcast.get(handle).spectrum.stop();
- StumbleChat.Userlist.Broadcast.get(handle).stream.getTracks().forEach((track) => track.stop());
- StumbleChat.Userlist.Broadcast.get(handle).transport.close();
- StumbleChat.WebSocket.send(`{"stumble":"subscribe","type":"unsubscribe","handle":"${handle}"}`);
- }
- removeBroadcastElement(handle);
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(2)`).classList.remove("audio_badge");
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(2)`).classList.add("audio_badge_hide");
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(1)`).classList.remove("video_badge");
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(1)`).classList.add("video_badge_hide");
- StumbleChat.Videos.Update();
- } else {
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(2)`).classList.add("audio_badge");
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(2)`).classList.remove("audio_badge_hide");
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(1)`).classList.add("video_badge");
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(1)`).classList.remove("video_badge_hide");
- StumbleChat.Userlist.User.get(handle).broadcasting.forEach((value) => StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "subscribe", "type": "request", "kind": value, "handle": handle })));
- }
- }
- }
- },
- Update: () => {
- let videos = document.querySelector("#videos");
- let videosItems = videos.querySelectorAll(".videos-items");
- let d = {
- featured: videos.querySelectorAll("#embeddedvideos > .js-video:not(.hidden)"),
- regular: videos.querySelectorAll("#regularvideos > .js-video:not(.hidden)")
- };
- if (!d.featured.length) videos.querySelector("#embeddedvideos").classList.add("hidden");
- if (!d.regular.length) videos.querySelector("#regularvideos").classList.add("hidden");
- videos.className = (d.featured.length && d.regular.length) ? (videos.clientWidth / videos.clientHeight > 1 / 0.75 ? "row" : "column") : "";
- videosItems.forEach((element, index) => {
- if ("object" == typeof videosItems[ index ]) {
- let wrapper = videosItems[ index ];
- let childs = videos.querySelectorAll(".videos-items:nth-child(" + (1 * index + 1) + ") > .js-video:not(.hidden)");
- if (childs.length) {
- wrapper.classList.remove("hidden");
- StumbleChat.Videos.Resize({ wrapper: wrapper, height: wrapper.clientHeight, width: wrapper.clientWidth, childs: childs });
- }
- }
- });
- },
- Resize: (a) => {
- let c = a.childs.length;
- let e = 100;
- let f = 100;
- let d = 0;
- let g = 0;
- for (; c;) {
- let d = Math.floor(a.height / c);
- let h = Math.floor(d / 0.75);
- if (h > a.width) {
- h = a.width;
- d = Math.floor(0.75 * h);
- }
- let i = Math.floor(a.width / h);
- for (; i * c < a.childs.length || d * c > a.height;) {
- i++;
- h = Math.floor(a.width / i);
- d = Math.floor(0.75 * h);
- }
- let j = d * h;
- let k = a.height * a.width;
- let l = Math.floor(1e4 * ((k - j * a.childs.length) / k)) / 100;
- if (0 < l && e >= l) {
- if (1 < c && a.childs.length % i) {
- let d = i;
- for (; d;) {
- if (Math.ceil(a.childs.length / d) > c) {
- d++;
- break;
- }
- d--;
- }
- g = d < i && d ? Math.floor((a.width - d * h) / 2) : 0;
- } else {
- g = 0;
- }
- e = l;
- f = Math.floor(100 * (100 * (h / (a.width - 2 * g)))) / 100;
- }
- c--;
- }
- for (let c in a.wrapper.style.padding = "0 " + g + "px", a.childs) {
- if ("object" == typeof a.childs[ c ] && (a.childs[ c ].style.width = f + "%")) {
- let e = a.childs[ c ].clientHeight;
- let g = a.childs[ c ].clientWidth;
- a.childs[ c ].style.width = (100 === f && a.height - d > e) ? f + "%" : Math.floor(100 * (e * g / (e + d) / (g / f))) / 100 + "%";
- }
- }
- },
- Menu: {
- Element: null,
- State: 0,
- Task: null,
- Display: (handle) => {
- if (!StumbleChat.Userlist.User.has(handle)) return;
- StumbleChat.Videos.Menu.State = 1;
- let menu_items = document.querySelectorAll(".video-menu-item");
- let SavedVolume;
- if (!StumbleChat.Userlist.User.get(document.querySelector("#video-menu").getAttribute("user-id")).guest) {
- SavedVolume = StumbleChat.Chat.Settings.BroadcastVolume[ StumbleChat.Userlist.User.get(document.querySelector("#video-menu").getAttribute("user-id")).username.toUpperCase() ];
- } else {
- SavedVolume = StumbleChat.Chat.Settings.TempBroadcastVolume[ StumbleChat.Userlist.User.get(document.querySelector("#video-menu").getAttribute("user-id")).username.toUpperCase() ];
- }
- document.querySelector(".video-menu-name").innerText = StumbleChat.Userlist.User.get(handle).nick;
- document.querySelector("#video-volume").addEventListener("pointerup", (e) => StumbleChat.Videos.Menu.Item.volume(document.querySelector("#video-menu").getAttribute("user-id"), e.target.value), {
- once: true
- });
- document.querySelector("#video-volume").value = (SavedVolume != undefined) ? SavedVolume : 100;
- // Hide Volume Meter if it's ourselves
- if (StumbleChat.Self.handle == handle) {
- menu_items[ 0 ].classList.add("hidden"); // Volume
- menu_items[ 2 ].classList.add("hidden"); // Private Message
- menu_items[ 3 ].classList[ (StumbleChat.Self.Hidden) ? "add" : "remove" ]("hidden"); // Hide
- menu_items[ 4 ].classList[ (StumbleChat.Self.Hidden) ? "remove" : "add" ]("hidden"); // Unhide
- menu_items[ 8 ].classList.add("hidden"); // Fullscreen
- menu_items[ 9 ].classList.add("hidden"); // PiP
- } else {
- menu_items[ 0 ].classList.remove("hidden"); // Volume
- menu_items[ 2 ].classList.remove("hidden"); // Private Message
- menu_items[ 3 ].classList[ (StumbleChat.Chat.Settings.HideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase()) || StumbleChat.Chat.Settings.TempHideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase())) ? "add" : "remove" ]("hidden"); // Hide
- menu_items[ 4 ].classList[ (StumbleChat.Chat.Settings.HideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase()) || StumbleChat.Chat.Settings.TempHideList.includes(StumbleChat.Userlist.User.get(handle).username.toUpperCase())) ? "remove" : "add" ]("hidden"); // Unhide
- menu_items[ 8 ].classList.remove("hidden"); // Fullscreen
- menu_items[ 9 ].classList.remove("hidden"); // PiP
- }
- // KICK/BAN CLOSE
- if (StumbleChat.Self.mod >= 2) {
- menu_items[ 5 ].classList[ (StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod) ? "remove" : "add" ]("hidden"); // Kick
- menu_items[ 6 ].classList[ (StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod) ? "remove" : "add" ]("hidden"); // Ban
- menu_items[ 7 ].classList[ (StumbleChat.Self.mod > StumbleChat.Userlist.User.get(handle).mod) ? "remove" : "add" ]("hidden"); // Close Broadcast
- } else {
- menu_items[ 5 ].classList.add("hidden"); // Kick
- menu_items[ 6 ].classList.add("hidden"); // Ban
- menu_items[ 7 ].classList.add("hidden"); // close Broadcast
- }
- StumbleChat.Videos.Menu.Element.classList.add(`video-menu-active`);
- },
- Hide: () => {
- if (StumbleChat.Videos.Menu.State !== 0) {
- StumbleChat.Videos.Menu.State = 0;
- if (StumbleChat.Videos.Menu.Element) StumbleChat.Videos.Menu.Element.classList.remove(`video-menu-active`);
- }
- document.querySelector("#video-volume").removeEventListener("pointerup", (e) => StumbleChat.Videos.Menu.Item.volume(document.querySelector("#video-menu").getAttribute("user-id"), e.target.value), {
- once: true
- });
- StumbleChat.Videos.Menu.Listen();
- },
- Position: (e) => {
- let clickCoords = StumbleChat.GUI.Pointer.Position(e);
- let menuWidth = StumbleChat.Videos.Menu.Element.offsetWidth + 4;
- let menuHeight = StumbleChat.Videos.Menu.Element.offsetHeight + 4;
- StumbleChat.Videos.Menu.Element.style.left = ((window.innerWidth - clickCoords.x) < menuWidth) ? window.innerWidth - menuWidth + "px" : clickCoords.x + "px";
- StumbleChat.Videos.Menu.Element.style.top = (((window.innerHeight - clickCoords.y) < menuHeight)) ? window.innerHeight - menuHeight + "px" : clickCoords.y + "px";
- },
- Listen: () => {
- document.addEventListener("pointerup", (e) => {
- e.preventDefault();
- StumbleChat.Videos.Menu.Task = StumbleChat.GUI.Element.Exists(e, "video-wrapper");
- if (StumbleChat.Videos.Menu.Task) {
- let handle = StumbleChat.Videos.Menu.Task.firstElementChild.getAttribute("video-id");
- if (handle !== null) {
- document.querySelector("#video-menu").setAttribute("user-id", handle);
- StumbleChat.Videos.Menu.Display(handle);
- StumbleChat.Videos.Menu.Position(e);
- }
- }
- }, {
- once: true
- });
- },
- Check: () => {
- document.addEventListener("pointerup", (e) => {
- let elem = StumbleChat.GUI.Element.Exists(e, `video-menu-link`);
- if (elem) {
- e.preventDefault();
- let handle = document.querySelector("#video-menu").getAttribute("user-id");
- if (handle != null && StumbleChat.Userlist.User.has(handle) && elem.getAttribute("data-action") != null) StumbleChat.Videos.Menu.Item[ elem.getAttribute("data-action") ](handle);
- }
- });
- },
- Item: {
- volume: (handle, level) => {
- if (StumbleChat.Self.handle !== handle && level !== undefined) {
- if (StumbleChat.Userlist.Broadcast.has(handle)) {
- if (!StumbleChat.Userlist.User.get(handle).guest) {
- StumbleChat.Chat.Settings.BroadcastVolume[ StumbleChat.Userlist.User.get(handle).username.toUpperCase() ] = level;
- localStorage.setItem('BroadcastVolume', JSON.stringify(StumbleChat.Chat.Settings.BroadcastVolume));
- } else {
- StumbleChat.Chat.Settings.TempBroadcastVolume[ StumbleChat.Userlist.User.get(handle).username.toUpperCase() ] = level;
- }
- StumbleChat.Userlist.Broadcast.get(handle).volume = level;
- StumbleChat.Userlist.Broadcast.get(handle).element.volume = (level / 100) * (StumbleChat.Chat.Settings.RoomVolume / 100);
- }
- }
- },
- profile: (handle) => StumbleChat.Userlist.Profile(handle),
- fullscreen: (handle) => {
- let elem = document.querySelector(`[video-id="${handle}"]`);
- if (elem.requestFullscreen) {
- elem.requestFullscreen();
- } else if (elem.mozRequestFullScreen) {
- elem.mozRequestFullScreen();
- } else if (elem.webkitRequestFullscreen) {
- elem.webkitRequestFullscreen();
- } else if (elem.msRequestFullscreen) {
- elem.msRequestFullscreen();
- }
- },
- pip: (handle) => {
- if (handle !== StumbleChat.Self.handle) {
- if (document.pictureInPictureElement) {
- document.exitPictureInPicture();
- } else {
- if (document.pictureInPictureEnabled) document.querySelector(`[video-id="${handle}"]`).requestPictureInPicture();
- }
- }
- },
- close: (handle) => StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "close",
- "handle": handle
- })),
- kick: (handle) => StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "kick",
- "handle": handle
- })),
- ban: (handle) => StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "ban",
- "handle": handle
- })),
- pvtmsg: (handle) => {
- if (StumbleChat.Chat.Selected !== handle) document.querySelector(".unreadmessage").classList.add("hidden");
- if (StumbleChat.Userlist.User.has(handle)) {
- StumbleChat.Chat.Selected = handle;
- document.querySelector("#chat-position>#back").classList.add("show");
- document.querySelector("#chat-position>#back").innerHTML = `‹ ${StumbleChat.Userlist.User.get(handle).nick} (${(StumbleChat.Userlist.User.get(handle).guest == 0) ? StumbleChat.Userlist.User.get(handle).username : "guest"})`;
- document.getElementById("chat-content").innerHTML = "";
- let PM = document.querySelector(".privateMessages");
- if (!StumbleChat.Chat.Messages.has(handle)) StumbleChat.Chat.Messages.set(handle, {
- username: (StumbleChat.Userlist.User.get(handle).guest == 0) ? StumbleChat.Userlist.User.get(handle).username : "guest",
- avatar: StumbleChat.Userlist.User.get(handle).avatar,
- nick: StumbleChat.Userlist.User.get(handle).nick,
- missedmsg: 0,
- message: [],
- namebackgroundcolor: StumbleChat.Userlist.User.get(handle).namebackgroundcolor,
- backgroundcolor: StumbleChat.Userlist.User.get(handle).backgroundcolor,
- messagetextcolor: StumbleChat.Userlist.User.get(handle).messagetextcolor
- });
- if (!PM.querySelector(`[user-id="${handle}"]`)) {
- document.querySelector("#userlist>h2:nth-child(2)").classList.remove("hidden");
- PM.classList.remove("hidden");
- let element = document.createElement('div');
- element.setAttribute("class", "list-item");
- element.innerHTML = `<span class="private" user-id=${handle}><div class="nickname">${StumbleChat.Userlist.User.get(handle).nick}</div><div class="unreadpm"></div><span class="closepm">x</span></span>`;
- document.querySelector(".privateMessages").insertAdjacentHTML("afterBegin", element.outerHTML);
- } else {
- StumbleChat.Chat.Messages.get(handle).missedmsg = 0;
- PM.querySelector(".unreadpm").innerText = StumbleChat.Chat.Messages.get(handle).missedmsg;
- PM.querySelector(".unreadpm").classList.remove("show");
- }
- if (document.querySelector(`.selected`)) document.querySelector(`.selected`).classList.remove("selected");
- PM.querySelector(`[user-id="${handle}"]`).classList.add("selected");
- StumbleChat.Chat.Messages.get(handle).message.forEach((value, index) => {
- if (index > 0) {
- if (value.nick == StumbleChat.Chat.Messages.get(handle).message[ index - 1 ].nick && StumbleChat.Chat.Messages.get(handle).message[ index - 1 ].handle == value.handle) {
- let element = document.createElement("div");
- element.setAttribute("class", "content");
- element.innerHTML = `<span class="hidden-selectable">[${value.time}]</span><span class="timestamp">${value.time}</span><span class="message common" style="color:${value.messagetextcolor}">${value.msg}</span></div>`;
- document.querySelector("#chat-content>.message:last-child").appendChild(element);
- } else {
- createChatItem(value);
- }
- } else {
- createChatItem(value);
- }
- });
- StumbleChat.Chat.Scroll(true);
- document.querySelector("#textarea").focus();
- }
- },
- hide: (handle) => {
- if (!StumbleChat.Userlist.User.has(handle)) return;
- if (StumbleChat.Self.handle === handle) {
- StumbleChat.Self.Hidden = true;
- Message.receive.public(`You are now hidden.`);
- } else {
- if (!StumbleChat.Userlist.User.get(handle).guest) {
- StumbleChat.Chat.Settings.HideList.push(StumbleChat.Userlist.User.get(handle).username.toUpperCase());
- localStorage.setItem('HideList', JSON.stringify(StumbleChat.Chat.Settings.HideList));
- } else {
- StumbleChat.Chat.Settings.TempHideList.push(StumbleChat.Userlist.User.get(handle).username.toUpperCase());
- }
- Message.receive.public(`${StumbleChat.Userlist.User.get(handle).nick} has been hidden.`);
- }
- StumbleChat.Videos.View(handle);
- },
- unhide: (handle) => {
- if (StumbleChat.Self.handle === handle) {
- StumbleChat.Self.Hidden = false;
- Message.receive.public(`You are now unhidden.`);
- } else {
- if (!StumbleChat.Userlist.User.get(handle).guest) {
- for (let i = 0; i < StumbleChat.Chat.Settings.HideList.length; i++) {
- if (StumbleChat.Chat.Settings.HideList[ i ] == StumbleChat.Userlist.User.get(handle).username.toUpperCase()) StumbleChat.Chat.Settings.HideList.splice(i, 1);
- }
- localStorage.setItem('HideList', JSON.stringify(StumbleChat.Chat.Settings.HideList));
- } else {
- for (let i = 0; i < StumbleChat.Chat.Settings.TempHideList.length; i++) {
- if (StumbleChat.Chat.Settings.TempHideList[ i ] == StumbleChat.Userlist.User.get(handle).username.toUpperCase()) StumbleChat.Chat.Settings.TempHideList.splice(i, 1);
- }
- }
- Message.receive.public(`${StumbleChat.Userlist.User.get(handle).nick} is unhidden.`);
- }
- StumbleChat.Videos.View(handle);
- }
- }
- }
- },
- GUI: {
- Pointer: {
- Position: (e) => {
- let posx = 0;
- let posy = 0;
- if (!e) e = window.event;
- if (e.pageX || e.pageY) {
- posx = e.pageX;
- posy = e.pageY;
- } else if (e.clientX || e.clientY) {
- posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
- posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
- }
- return {
- x: posx,
- y: posy
- };
- }
- },
- Element: {
- Exists: (e, className) => {
- let el = e.srcElement || e.target;
- if (el.classList.contains(className)) {
- return el;
- } else {
- while (el == el.parentNode) {
- if (el.classList && el.classList.contains(className)) return el;
- }
- }
- return false;
- }
- }
- }
- };
- let ModType = [ "", "Operator", "Mod", "Super", "Owner", "Admin" ];
- let ModColor = [ "", " red", " green", " blue", " gold", " black" ];
- let CheckCompatibility = {
- Storage: () => {
- let storage;
- try {
- storage = window.localStorage;
- let x = '__storage_test__';
- storage.setItem(x, x);
- storage.removeItem(x);
- return true;
- } catch (e) {
- return e instanceof window.DOMException && (e.code === 22 || e.code === 1014 || e.name === 'QuotaExceededError' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') && (storage && storage.length !== 0);
- }
- },
- Device: () => {
- const handlerName = window.stumblechatClient.detectDevice();
- if (handlerName) {
- console.log(`Device: ${handlerName}`);
- } else {
- console.warn("There's currently no support for this browser.");
- return false;
- }
- StumbleChat.Videos.Device = null;
- try {
- StumbleChat.Videos.Device = new window.stumblechatClient.Device();
- } catch (error) {
- if (error.name === 'UnsupportedError') console.warn("There's currently no support for this browser.");
- return false;
- }
- StumbleChat.Videos.Device.load({
- routerRtpCapabilities: {
- codecs: [
- { "kind": "audio", "mimeType": "audio/opus", "clockRate": 48000, "channels": 2, "rtcpFeedback": [ { "type": "transport-cc", "parameter": "" } ], "parameters": {}, "preferredPayloadType": 100 },
- { "kind": "video", "mimeType": "video/VP8", "clockRate": 90000, "rtcpFeedback": [ { "type": "nack", "parameter": "" }, { "type": "nack", "parameter": "pli" }, { "type": "ccm", "parameter": "fir" }, { "type": "goog-remb", "parameter": "" }, { "type": "transport-cc", "parameter": "" } ], "parameters": { "x-google-start-bitrate": 1000 }, "preferredPayloadType": 101 },
- ],
- headerExtensions: [
- { "kind": "audio", "uri": "urn:ietf:params:rtp-hdrext:sdes:mid", "preferredId": 1, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "video", "uri": "urn:ietf:params:rtp-hdrext:sdes:mid", "preferredId": 1, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "video", "uri": "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id", "preferredId": 2, "preferredEncrypt": false, "direction": "recvonly" },
- { "kind": "video", "uri": "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id", "preferredId": 3, "preferredEncrypt": false, "direction": "recvonly" },
- { "kind": "audio", "uri": "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", "preferredId": 4, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "video", "uri": "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", "preferredId": 4, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "audio", "uri": "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01", "preferredId": 5, "preferredEncrypt": false, "direction": "recvonly" },
- { "kind": "video", "uri": "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01", "preferredId": 5, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "video", "uri": "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07", "preferredId": 6, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "video", "uri": "urn:ietf:params:rtp-hdrext:framemarking", "preferredId": 7, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "audio", "uri": "urn:ietf:params:rtp-hdrext:ssrc-audio-level", "preferredId": 10, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "video", "uri": "urn:3gpp:video-orientation", "preferredId": 11, "preferredEncrypt": false, "direction": "sendrecv" },
- { "kind": "video", "uri": "urn:ietf:params:rtp-hdrext:toffset", "preferredId": 12, "preferredEncrypt": false, "direction": "sendrecv" }
- ]
- }
- });
- return true;
- },
- WebSocket: () => "WebSocket" in window,
- MouseSupport: (eventName) => {
- let el = document.createElement('div');
- eventName = 'on' + eventName;
- let isSupported = (eventName in el);
- if (!isSupported) {
- el.setAttribute(eventName, 'return;');
- isSupported = typeof el[ eventName ] == 'function';
- }
- el = null;
- return isSupported;
- }
- };
- let SubscribeQueue = [];
- let ServerResponse = {
- joined: (rcv) => {
- StumbleChat.Room = rcv.room;
- document.querySelector(`.topic`).innerText = rcv.room.topic || "NO TOPIC";
- StumbleChat.Self = rcv.self;
- document.getElementById("textarea").disabled = false;
- if (StumbleChat.Self.guest == 1) document.getElementById("user-settings").classList.add("hidden");
- Message.receive.public(`Client Version: ${StumbleChat.Version}`);
- Message.receive.public(`Type /help for in chat commands.`);
- if (StumbleChat.Self.mod >= 2) document.getElementById("banlist").classList.remove("hidden");
- if (StumbleChat.Self.mod >= 3) document.getElementById("room-settings").classList.remove("hidden");
- if (StumbleChat.Self.mod >= 1) {
- document.getElementById("media").parentElement.classList.remove("hidden");
- document.getElementById("youtube-close-embed").classList.remove("hidden");
- document.getElementById("twitch-close-embed").classList.remove("hidden");
- document.getElementById("soundcloud-close-embed").classList.remove("hidden");
- document.getElementById("dailymotion-close-embed").classList.remove("hidden");
- document.getElementById("worldstarhiphop-close-embed").classList.remove("hidden");
- }
- if (!StumbleChat.Chat.Status.LoadedEventListenersJoined) {
- StumbleChat.Chat.Status.LoadedEventListenersJoined = true;
- document.getElementById("banlist").addEventListener("pointerup", (event) => StumbleChat.WebSocket.send(`{"stumble":"banlist"}`), {
- passive: true
- });
- document.getElementById("user-options").addEventListener("pointerup", (event) => {
- switch (event.target.id) {
- case "youtube":
- setTimeout(() => StumbleChat.WebSocket.send(`{"stumble": "youtube","type": "playlist"}`), 500);
- break;
- case "twitch":
- Modal.Create(12);
- break;
- case "soundcloud":
- Modal.Create(17);
- break;
- case "dailymotion":
- Modal.Create(18);
- break;
- case "worldstarhiphop":
- Modal.Create(16);
- break;
- case "client-settings":
- Modal.Create(10);
- break;
- case "theme-settings":
- Modal.Create(14);
- break;
- case "room-settings":
- Modal.Create(19);
- break;
- default:
- break;
- }
- }, {
- passive: true
- });
- }
- if (!StumbleChat.Chat.Settings.isMobile) document.querySelector("#media-screen").classList.remove("hidden");
- document.getElementById('media-broadcast').classList.remove('hidden');
- document.getElementById('media-settings').classList.remove('hidden');
- document.getElementById('media-loading').classList.add('hidden');
- document.getElementById('media-ptt').classList.add('hidden');
- document.getElementById('media-openmic').classList.add('hidden');
- document.getElementById('media-stop').classList.add('hidden');
- // Userlist
- rcv.userlist = rcv.userlist.sort((c, a) => (a.mod > c.mod) ? 1 : (a.mod < c.mod) ? -1 : c.nick.toLowerCase().localeCompare(a.nick.toLowerCase()));
- StumbleChat.Userlist.SortedUsers = rcv.userlist;
- rcv.userlist.forEach((user, index) => {
- StumbleChat.Userlist.User.set(user.handle, user);
- StumbleChat.Userlist.User.get(user.handle).disconnecttimer = undefined;
- StumbleChat.Userlist.User.get(user.handle).broadcasting = [];
- if (user.avatar == 1) {
- StumbleChat.Userlist.User.get(user.handle).avatar = `/profile/${user.username.toLowerCase()}/cached/small_avatar.jpg`;
- if (StumbleChat.Self.handle == user.handle) StumbleChat.Self.avatar = `/profile/${user.username.toLowerCase()}/cached/small_avatar.jpg`;
- StumbleChat.Userlist.list.insertAdjacentHTML("beforeend", `<li class="bar" user-id="${user.handle}"><img src="${StumbleChat.Userlist.User.get(user.handle).avatar}" class="bar-item"><div class="bar-item"><span class="nickname">${((StumbleChat.Chat.Settings.IgnoredList.includes(user.username.toUpperCase()) || StumbleChat.Chat.Settings.TempIgnoredList.includes(user.username.toUpperCase())) ? `<s>${user.nick}</s>` : user.nick)}</span><span class="username">${(user.guest) ? `guest` : user.username}</span></div><div class="user-status"><div class="role${ModColor[ user.mod ]}">${ModType[ user.mod ]}</div><div class="status"><div class="hidden"></div><div class="hidden"></div></div></div></li>`);
- } else {
- StumbleChat.Userlist.User.get(user.handle).avatar = undefined;
- if (StumbleChat.Self.handle == user.handle) StumbleChat.Self.avatar = undefined;
- StumbleChat.Userlist.list.insertAdjacentHTML("beforeend", `<li class="bar" user-id="${user.handle}"><div class="bar-item no-image"></div><div class="bar-item"><span class="nickname">${((StumbleChat.Chat.Settings.IgnoredList.includes(user.username.toUpperCase()) || StumbleChat.Chat.Settings.TempIgnoredList.includes(user.username.toUpperCase())) ? `<s>${user.nick}</s>` : user.nick)}</span><span class="username">${(user.guest) ? `guest` : user.username}</span></div><div class="user-status"><div class="role${ModColor[ user.mod ]}">${ModType[ user.mod ]}</div><div class="status"><div class="hidden"></div><div class="hidden"></div></div></div></li>`);
- }
- StumbleChat.Userlist.Count();
- });
- // Broadcasts
- ServerResponse.producers({ producers: rcv.broadcasts });
- // Embeds
- if (rcv.youtube != undefined) ServerResponse.youtube({ type: "play", id: rcv.youtube.id, duration: rcv.youtube.duration, queueid: rcv.youtube.queueid, time: rcv.youtube.time + Math.round((new Date() - new Date(rcv.youtube.started)) / 1000), title: rcv.youtube.title });
- if (rcv.wshh.url != undefined) ServerResponse.wshh({ type: "play", url: rcv.wshh.url, embed: rcv.wshh.embed, title: rcv.wshh.title, thumbnail: rcv.wshh.thumbnail });
- if (rcv.twitch.name != undefined) ServerResponse.twitch({ type: "play", name: rcv.twitch.name });
- if (rcv.dailymotion.url != undefined) ServerResponse.dailymotion({ type: "play", url: rcv.dailymotion.url, embed: rcv.dailymotion.embed, title: rcv.dailymotion.title, thumbnail: rcv.dailymotion.thumbnail });
- if (rcv.soundcloud.url != undefined) ServerResponse.soundcloud({ type: "play", url: rcv.soundcloud.url, embed: rcv.soundcloud.embed, title: rcv.soundcloud.title });
- },
- join: (rcv) => {
- StumbleChat.Userlist.User.set(rcv.handle, {
- handle: rcv.handle,
- namebackgroundcolor: rcv.namebackgroundcolor,
- messagetextcolor: rcv.messagetextcolor,
- backgroundcolor: rcv.backgroundcolor,
- avatar: rcv.avatar,
- username: rcv.username,
- guest: rcv.guest,
- nick: rcv.nick,
- mod: rcv.mod,
- disconnecttimer: undefined,
- broadcasting: []
- });
- Message.receive.public(`${rcv.nick} (${(rcv.guest) ? `guest` : rcv.username}:${rcv.handle}) has joined.`);
- StumbleChat.Userlist.SortedUsers.push(StumbleChat.Userlist.User.get(rcv.handle));
- StumbleChat.Userlist.SortedUsers = StumbleChat.Userlist.SortedUsers.sort((c, a) => (a.mod > c.mod) ? 1 : (a.mod < c.mod) ? -1 : c.nick.toLowerCase().localeCompare(a.nick.toLowerCase()));
- let first;
- let beforeUser;
- for (let i = 0; i < StumbleChat.Userlist.SortedUsers.length; i++) {
- if (StumbleChat.Userlist.User.get(rcv.handle).mod > StumbleChat.Userlist.SortedUsers[ i ].mod) {
- if (i == 0) {
- first = true;
- break;
- }
- beforeUser = StumbleChat.Userlist.SortedUsers[ i ].handle;
- break;
- } else if (StumbleChat.Userlist.User.get(rcv.handle).mod == StumbleChat.Userlist.SortedUsers[ i ].mod) {
- if (StumbleChat.Userlist.SortedUsers[ i ].nick.toLowerCase().localeCompare(StumbleChat.Userlist.User.get(rcv.handle).nick.toLowerCase()) == 1) {
- beforeUser = StumbleChat.Userlist.SortedUsers[ i ].handle;
- break;
- }
- }
- }
- if (rcv.avatar == 1) {
- StumbleChat.Userlist.User.get(rcv.handle).avatar = `/profile/${rcv.username.toLowerCase()}/cached/small_avatar.jpg`;
- } else {
- StumbleChat.Userlist.User.get(rcv.handle).avatar = undefined;
- }
- let element = `<li class="bar" user-id="${rcv.handle}">${(StumbleChat.Userlist.User.get(rcv.handle).avatar == undefined) ? `<div class="bar-item no-image"></div>` : `<img src="/profile/${rcv.username.toLowerCase()}/cached/small_avatar.jpg" class="bar-item">`}<div class="bar-item"><span class="nickname">${((StumbleChat.Chat.Settings.IgnoredList.includes(rcv.username.toUpperCase()) || StumbleChat.Chat.Settings.TempIgnoredList.includes(rcv.username.toUpperCase())) ? `<s>${rcv.nick}</s>` : rcv.nick)}</span><span class="username">${(rcv.guest) ? `guest` : rcv.username}</span></div><div class="user-status"><div class="role${ModColor[ rcv.mod ]}">${ModType[ rcv.mod ]}</div><div class="status"><div class="hidden"></div><div class="hidden"></div></div></div></li>`;
- if (first) {
- StumbleChat.Userlist.list.insertAdjacentHTML("afterbegin", element);
- } else {
- if (beforeUser) {
- StumbleChat.Userlist.list.querySelector(`li[user-id="${beforeUser}"]`).insertAdjacentHTML("beforebegin", element);
- } else {
- StumbleChat.Userlist.list.insertAdjacentHTML("beforeend", element);
- }
- }
- StumbleChat.Userlist.Count();
- },
- room: (rcv) => {
- switch (rcv.type) {
- case "guests":
- StumbleChat.Room.guests_allowed = rcv.enabled;
- Message.receive.public(`Guest mode has been ${(rcv.enabled) ? "enabled" : "disabled"}.`);
- break;
- case "public":
- StumbleChat.Room.public = rcv.enabled;
- Message.receive.public(`Room has been made ${(rcv.enabled) ? "public" : "private"}.`);
- break;
- case "greenroom":
- StumbleChat.Room.greenroom = rcv.enabled;
- Message.receive.public(`Greenroom has been ${(rcv.enabled) ? "enabled" : "disabled"}.`);
- break;
- case "topic":
- StumbleChat.Room.topic = rcv.topic || "NO TOPIC";
- document.querySelector('.topic').innerText = StumbleChat.Room.topic;
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} has ${(rcv.topic == "") ? "cleared" : "changed"} the room topic.`);
- break;
- case "broadcast_password":
- Message.receive.public(`${(rcv.enabled == true) ? "Broadcast password was enabled." : "Broadcast password was disabled."}`);
- StumbleChat.Room.broadcast_password = rcv.enabled;
- break;
- }
- },
- banlist: (rcv) => Modal.Create(9, rcv.users),
- quit: (rcv) => {
- Broadcast.unpublish(rcv.handle);
- if (StumbleChat.Userlist.User.has(rcv.handle)) {
- document.querySelector(`#userlist li[user-id="${rcv.handle}"]`).remove();
- if (document.querySelector(`.privateMessages > div > span[user-id="${rcv.handle}"]`) !== null) {
- if (StumbleChat.Chat.Messages.has(rcv.handle)) document.querySelector(`.privateMessages > div > span[user-id="${rcv.handle}"] > .nickname`).innerText += ` (offline)`;
- }
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} (${(StumbleChat.Userlist.User.get(rcv.handle).guest == 0) ? StumbleChat.Userlist.User.get(rcv.handle).username : "guest"}:${rcv.handle}) has left.`);
- if (StumbleChat.Chat.Selected == rcv.handle) Message.receive.private(rcv.handle, `${StumbleChat.Userlist.User.get(rcv.handle).nick} has gone offline.`);
- clearTimeout(StumbleChat.Userlist.User.get(rcv.handle).disconnecttimer);
- StumbleChat.Userlist.User.delete(rcv.handle);
- for (let i = StumbleChat.Userlist.SortedUsers.length - 1; i >= 0; i--) {
- if (StumbleChat.Userlist.SortedUsers[ i ].handle == rcv.handle) {
- StumbleChat.Userlist.SortedUsers.splice(i, 1);
- break;
- }
- }
- StumbleChat.Userlist.Count();
- }
- },
- closed: (rcv) => {
- StumbleChat.Chat.Status.Kicked = true;
- Modal.Create(8, rcv.text);
- },
- msg: (rcv) => {
- if (StumbleChat.Userlist.User.has(rcv.handle)) {
- if (!StumbleChat.Chat.Settings.IgnoredList.includes(StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase()) && !StumbleChat.Chat.Settings.TempIgnoredList.includes(StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase())) Message.receive.public(rcv.text, StumbleChat.Userlist.User.get(rcv.handle).username, StumbleChat.Userlist.User.get(rcv.handle).nick, StumbleChat.Userlist.User.get(rcv.handle).avatar, StumbleChat.Userlist.User.get(rcv.handle).namebackgroundcolor, StumbleChat.Userlist.User.get(rcv.handle).backgroundcolor, StumbleChat.Userlist.User.get(rcv.handle).messagetextcolor);
- }
- },
- nick: (rcv) => {
- let listusers = document.querySelector(`.bar[user-id="${rcv.handle}"] .nickname`);
- listusers.innerText = rcv.nick;
- if (StumbleChat.Chat.Messages.has(rcv.handle)) {
- let listpm = document.querySelector(`.privateMessages > div > span[user-id="${rcv.handle}"] > .nickname`);
- listpm.innerText = rcv.nick;
- StumbleChat.Chat.Messages.get(rcv.handle).nick = rcv.nick;
- if (StumbleChat.Chat.Selected == rcv.handle) document.querySelector(`#back`).innerHTML = `< ${StumbleChat.Chat.Messages.get(rcv.handle).nick} (${(StumbleChat.Userlist.User.get(rcv.handle).guest == 0) ? StumbleChat.Chat.Messages.get(rcv.handle).username : "guest"})`;
- }
- if (StumbleChat.Self.handle == rcv.handle) {
- Message.receive.public(`You've successfully changed your nickname!`);
- StumbleChat.Self.nick = rcv.nick;
- localStorage.setItem('nick', rcv.nick);
- } else {
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} has changed their nickname to ${rcv.nick}`);
- }
- if (StumbleChat.Userlist.Broadcast.has(rcv.handle)) StumbleChat.Userlist.Broadcast.get(rcv.handle).element.parentElement.querySelector('.nickname').innerText = rcv.nick;
- StumbleChat.Userlist.User.get(rcv.handle).nick = rcv.nick;
- StumbleChat.Userlist.Organize(rcv.handle);
- },
- role: (rcv) => {
- let role = document.querySelector(`.bar[user-id="${rcv.handle}"] .role`);
- switch (rcv.type) {
- case "super":
- if (StumbleChat.Self.handle == rcv.handle) {
- StumbleChat.Self.mod = 3;
- Message.receive.public(`You are now a super!`);
- document.getElementById("media").parentElement.classList.remove("hidden");
- document.getElementById("youtube-close-embed").classList.remove("hidden");
- document.getElementById("twitch-close-embed").classList.remove("hidden");
- document.getElementById("soundcloud-close-embed").classList.remove("hidden");
- document.getElementById("dailymotion-close-embed").classList.remove("hidden");
- document.getElementById("worldstarhiphop-close-embed").classList.remove("hidden");
- document.getElementById("banlist").classList.remove("hidden");
- document.getElementById("room-settings").classList.remove("hidden");
- } else {
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} has become a super.`);
- }
- role.classList = "role blue";
- role.innerText = "Super";
- StumbleChat.Userlist.User.get(rcv.handle).mod = 3;
- StumbleChat.Userlist.Organize(rcv.handle);
- break;
- case "moderator":
- if (StumbleChat.Self.handle == rcv.handle) {
- StumbleChat.Self.mod = 2;
- Message.receive.public(`You are now a moderator!`);
- document.getElementById("media").parentElement.classList.remove("hidden");
- document.getElementById("youtube-close-embed").classList.remove("hidden");
- document.getElementById("twitch-close-embed").classList.remove("hidden");
- document.getElementById("soundcloud-close-embed").classList.remove("hidden");
- document.getElementById("dailymotion-close-embed").classList.remove("hidden");
- document.getElementById("worldstarhiphop-close-embed").classList.remove("hidden");
- document.getElementById("banlist").classList.remove("hidden");
- document.getElementById("room-settings").classList.add("hidden");
- } else {
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} has become a moderator.`);
- }
- role.classList = "role green";
- role.innerText = "Mod";
- StumbleChat.Userlist.User.get(rcv.handle).mod = 2;
- StumbleChat.Userlist.Organize(rcv.handle);
- break;
- case "operator":
- if (StumbleChat.Self.handle == rcv.handle) {
- StumbleChat.Self.mod = 1;
- Message.receive.public(`You are now an operator.`);
- document.getElementById("media").parentElement.classList.remove("hidden");
- document.getElementById("youtube-close-embed").classList.remove("hidden");
- document.getElementById("twitch-close-embed").classList.remove("hidden");
- document.getElementById("soundcloud-close-embed").classList.remove("hidden");
- document.getElementById("dailymotion-close-embed").classList.remove("hidden");
- document.getElementById("worldstarhiphop-close-embed").classList.remove("hidden");
- document.getElementById("banlist").classList.add("hidden");
- document.getElementById("room-settings").classList.add("hidden");
- } else {
- Message.receive.public(StumbleChat.Userlist.User.get(rcv.handle).nick + " has become an operator.");
- }
- role.classList = "role red";
- role.innerText = "Operator";
- StumbleChat.Userlist.User.get(rcv.handle).mod = 1;
- StumbleChat.Userlist.Organize(rcv.handle);
- break;
- case "revoke":
- if (StumbleChat.Self.handle == rcv.handle) {
- StumbleChat.Self.mod = 0;
- Message.receive.public(`You were stripped of your roles!`);
- document.getElementById("media").parentElement.classList.add("hidden");
- document.getElementById("youtube-close-embed").classList.add("hidden");
- document.getElementById("twitch-close-embed").classList.add("hidden");
- document.getElementById("soundcloud-close-embed").classList.add("hidden");
- document.getElementById("dailymotion-close-embed").classList.add("hidden");
- document.getElementById("worldstarhiphop-close-embed").classList.add("hidden");
- document.getElementById("banlist").classList.add("hidden");
- document.getElementById("room-settings").classList.add("hidden");
- } else {
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} has been stripped of their roles.`);
- }
- role.classList = "role";
- role.innerText = "";
- StumbleChat.Userlist.User.get(rcv.handle).mod = 0;
- StumbleChat.Userlist.Organize(rcv.handle);
- break;
- }
- },
- pvtmsg: (rcv) => {
- if (!StumbleChat.Chat.Settings.IgnoredList.includes(StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase()) && !StumbleChat.Chat.Settings.TempIgnoredList.includes(StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase())) Message.receive.private(rcv.handle, rcv.text, rcv.handle, StumbleChat.Userlist.User.get(rcv.handle).nick, StumbleChat.Userlist.User.get(rcv.handle).avatar, StumbleChat.Userlist.User.get(rcv.handle).namebackgroundcolor, StumbleChat.Userlist.User.get(rcv.handle).backgroundcolor, StumbleChat.Userlist.User.get(rcv.handle).messagetextcolor);
- },
- sysmsg: (rcv) => Message.receive.public(rcv.text),
- publish: (rcv) => Broadcast.publish[ rcv.type ](rcv),
- subscribe: (rcv) => {
- SubscribeQueue.push(rcv);
- if (SubscribeQueue.length == 1) return Broadcast.subscribe[ rcv.type ](rcv);
- },
- producers: (rcv) => {
- if (rcv.producers.length == 0) return;
- for (let i = 0; i < rcv.producers.length; i++) {
- for (let x = 0; x < rcv.producers[ i ].kind.length; x++) {
- let video = document.querySelector(`.bar[user-id="${rcv.producers[ i ].handle}"] .status>div:nth-child(1)`) !== null && rcv.producers[ i ].kind[ x ] == "video";
- let audio = document.querySelector(`.bar[user-id="${rcv.producers[ i ].handle}"] .status>div:nth-child(2)`) !== null && rcv.producers[ i ].kind[ x ] == "audio";
- if (!StumbleChat.Chat.Settings.HideList.includes(StumbleChat.Userlist.User.get(rcv.producers[ i ].handle).username.toUpperCase()) && !StumbleChat.Chat.Settings.TempHideList.includes(StumbleChat.Userlist.User.get(rcv.producers[ i ].handle).username.toUpperCase())) {
- StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "subscribe", "type": "request", "kind": rcv.producers[ i ].kind[ x ], "handle": rcv.producers[ i ].handle }));
- } else {
- Message.receive.public(`${(StumbleChat.Userlist.User.get(rcv.producers[ i ].handle).guest == 0) ? StumbleChat.Userlist.User.get(rcv.producers[ i ].handle).username : "guest"} started broadcasting ${rcv.producers[ i ].kind[ x ]} however you have them hidden.`);
- }
- if (StumbleChat.Chat.Settings.HideList.includes(StumbleChat.Userlist.User.get(rcv.producers[ i ].handle).username.toUpperCase()) || StumbleChat.Chat.Settings.TempHideList.includes(StumbleChat.Userlist.User.get(rcv.producers[ i ].handle).username.toUpperCase())) {
- if (video) document.querySelector(`.bar[user-id="${rcv.producers[ i ].handle}"] .status>div:nth-child(1)`).classList.add("video_badge_hide");
- if (audio) document.querySelector(`.bar[user-id="${rcv.producers[ i ].handle}"] .status>div:nth-child(2)`).classList.add("audio_badge_hide");
- } else {
- if (video) document.querySelector(`.bar[user-id="${rcv.producers[ i ].handle}"] .status>div:nth-child(1)`).classList.add("video_badge");
- if (audio) document.querySelector(`.bar[user-id="${rcv.producers[ i ].handle}"] .status>div:nth-child(2)`).classList.add("audio_badge");
- }
- if (video) document.querySelector(`.bar[user-id="${rcv.producers[ i ].handle}"] .status>div:nth-child(1)`).classList.remove("hidden");
- if (audio) document.querySelector(`.bar[user-id="${rcv.producers[ i ].handle}"] .status>div:nth-child(2)`).classList.remove("hidden");
- if (StumbleChat.Userlist.User.has(rcv.producers[ i ].handle)) StumbleChat.Userlist.User.get(rcv.producers[ i ].handle).broadcasting.push(rcv.producers[ i ].kind[ x ]);
- }
- }
- },
- unsubscribe: (rcv) => {
- if (StumbleChat.Userlist.User.has(rcv.handle)) StumbleChat.Userlist.User.get(rcv.handle).broadcasting = [];
- if (rcv.handle == StumbleChat.Self.handle || StumbleChat.Userlist.User.has(rcv.handle)) Message.receive.public(`${(rcv.handle !== StumbleChat.Self.handle) ? StumbleChat.Userlist.User.get(rcv.handle).nick + " has" : "You have"} stopped broadcasting.`);
- Broadcast.unpublish(rcv.handle);
- },
- youtube: (rcv) => {
- if (rcv.type == "play") {
- StumbleChat.Chat.Status.Playing.YouTube = true;
- if (StumbleChat.Chat.Settings.YouTubeEnabled == true) {
- document.querySelector("#videos > div > .youtube").classList.remove("hidden");
- let b = setInterval(() => StumbleChat.Videos.Update(), 4);
- if (window.YouTubePlayer == undefined) {
- window.YouTubePlayer = new window.YT.Player('youtubeplayer', {
- videoId: rcv.id,
- playerVars: {
- autohide: 2,
- autoplay: 1,
- mute: 0,
- controls: 0,
- disablekb: 1,
- enablejsapi: 1,
- fs: 0,
- iv_load_policy: 3,
- loop: 0,
- modestbranding: 1,
- origin: window.location.hostname,
- playsinline: 1,
- start: rcv.time,
- rel: 0,
- showinfo: 0
- },
- events: {
- onReady: Media.YouTube.Ready,
- onStateChange: Media.YouTube.onPlayerStateChange
- }
- });
- } else {
- window.YouTubePlayer.loadVideoById(rcv.id, rcv.time);
- }
- StumbleChat.Chat.Settings.YouTubeQueueID = rcv.queueid;
- StumbleChat.Chat.Settings.YouTubeStartTime = rcv.time;
- setTimeout(() => clearInterval(b), 800);
- }
- Message.receive.public(`Playing ${rcv.title} \n\nhttps://youtube.com/watch?v=${rcv.id}\n`);
- } else if (rcv.type == "stop") {
- StumbleChat.Chat.Status.Playing.YouTube = false;
- Media.YouTube.Stop(rcv.text);
- } else if (rcv.type == "playlist") {
- Modal.Create(7, rcv.tracks);
- }
- },
- wshh: (rcv) => {
- let elem;
- if (rcv.type == "play") {
- StumbleChat.Chat.Status.Playing.WSSH = true;
- if (StumbleChat.Chat.Settings.WSHHEnabled == true) {
- document.querySelector("#videos > div > .worldstarhiphop").classList.remove("hidden");
- StumbleChat.Videos.Update();
- elem = document.querySelector("#worldstarhiphopplayer>video");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#worldstarhiphopplayer").innerHTML = `<video id="video" poster="${rcv.thumbnail}" controls playsinline src="${rcv.embed}">Your browser does not support the video tag...</video>`;
- }
- Message.receive.public(StumbleChat.Userlist.User.has(rcv.handle) ? `${StumbleChat.Userlist.User.get(rcv.handle).nick} (${StumbleChat.Userlist.User.get(rcv.handle).username}) has started WSHH:\n${rcv.title}\n\n${rcv.url}` : `Playing WSHH:\n${rcv.title}\n\n${rcv.url}`);
- } else if (rcv.type == "stop") {
- StumbleChat.Chat.Status.Playing.WSSH = false;
- document.querySelector("#videos > div > .worldstarhiphop").classList.add("hidden");
- StumbleChat.Videos.Update();
- elem = document.querySelector("#worldstarhiphopplayer>video");
- if (elem !== null) elem.parentNode.removeChild(elem);
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} (${StumbleChat.Userlist.User.get(rcv.handle).username}) has stopped WSHH.`);
- }
- },
- soundcloud: (rcv) => {
- let elem;
- if (rcv.type == "play") {
- StumbleChat.Chat.Status.Playing.SoundCloud = true;
- if (StumbleChat.Chat.Settings.SoundCloudEnabled == true) {
- document.querySelector("#videos > div > .soundcloud").classList.remove("hidden");
- document.querySelector("#soundcloud-volume-slider").value = 100;
- StumbleChat.Videos.Update();
- elem = document.querySelector("#soundcloudplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#soundcloudplayer").innerHTML = rcv.embed;
- }
- Message.receive.public(StumbleChat.Userlist.User.has(rcv.handle) ? `${StumbleChat.Userlist.User.get(rcv.handle).nick} (${StumbleChat.Userlist.User.get(rcv.handle).username}) has started SoundCloud:\n${rcv.title}\n\n${rcv.url}` : `Playing SoundCloud:\n${rcv.title}\n\n${rcv.url}`);
- } else if (rcv.type == "stop") {
- StumbleChat.Chat.Status.Playing.SoundCloud = false;
- document.querySelector("#videos > div > .soundcloud").classList.add("hidden");
- StumbleChat.Videos.Update();
- elem = document.querySelector("#soundcloudplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} (${StumbleChat.Userlist.User.get(rcv.handle).username}) has stopped SoundCloud.`);
- }
- },
- dailymotion: (rcv) => {
- let elem;
- if (rcv.type == "play") {
- StumbleChat.Chat.Status.Playing.DailyMotion = true;
- if (StumbleChat.Chat.Settings.DailyMotionEnabled == true) {
- document.querySelector("#videos > div > .dailymotion").classList.remove("hidden");
- StumbleChat.Videos.Update();
- elem = document.querySelector("#dailymotionplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#dailymotionplayer").innerHTML = rcv.embed;
- }
- Message.receive.public(StumbleChat.Userlist.User.has(rcv.handle) ? `${StumbleChat.Userlist.User.get(rcv.handle).nick} (${StumbleChat.Userlist.User.get(rcv.handle).username}) has started DailyMotion:\n${rcv.title}\n\n${rcv.url}` : `Playing DailyMotion:\n${rcv.title}\n\n${rcv.url}`);
- } else if (rcv.type == "stop") {
- StumbleChat.Chat.Status.Playing.DailyMotion = false;
- document.querySelector("#videos > div > .dailymotion").classList.add("hidden");
- StumbleChat.Videos.Update();
- elem = document.querySelector("#dailymotionplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} (${StumbleChat.Userlist.User.get(rcv.handle).username}) has stopped DailyMotion.`);
- }
- },
- twitch: (rcv) => {
- let elem;
- if (rcv.type == "play") {
- StumbleChat.Chat.Status.Playing.Twitch = true;
- if (StumbleChat.Chat.Settings.TwitchEnabled == true) {
- document.querySelector("#videos > div > .twitch").classList.remove("hidden");
- StumbleChat.Videos.Update();
- elem = document.querySelector("#twitchplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#twitch-volume-slider").value = 100;
- window.TwitchPlayer = new window.Twitch.Player("twitchplayer", {
- autoplay: false,
- controls: false,
- width: "100%",
- height: "100%",
- channel: rcv.name,
- parent: [ window.location.hostname ]
- });
- }
- Message.receive.public(StumbleChat.Userlist.User.has(rcv.handle) ? `${StumbleChat.Userlist.User.get(rcv.handle).nick} (${StumbleChat.Userlist.User.get(rcv.handle).username}) has started Twitch:\nhttps://twitch.tv/${rcv.name}` : `Playing Twitch:\nhttps://twitch.tv/${rcv.name}`);
- } else if (rcv.type == "stop") {
- StumbleChat.Chat.Status.Playing.Twitch = false;
- window.TwitchPlayer = null;
- document.querySelector("#videos > div > .twitch").classList.add("hidden");
- StumbleChat.Videos.Update();
- elem = document.querySelector("#twitchplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} (${StumbleChat.Userlist.User.get(rcv.handle).username}) has stopped Twitch.`);
- }
- }
- };
- let localScreen;
- let Broadcast = {
- unpublish: (handle) => {
- if (StumbleChat.Userlist.Broadcast.has(handle)) {
- if (StumbleChat.Userlist.Broadcast.get(handle).spectrum !== undefined) StumbleChat.Userlist.Broadcast.get(handle).spectrum.stop();
- clearInterval(StumbleChat.Userlist.Broadcast.get(handle).iceInterval);
- StumbleChat.Userlist.Broadcast.get(handle).stream.getTracks().forEach((track) => track.stop());
- StumbleChat.Userlist.Broadcast.get(handle).transport.close();
- }
- if (StumbleChat.Userlist.User.has(handle)) clearTimeout(StumbleChat.Userlist.User.get(handle).disconnecttimer);
- if (handle == StumbleChat.Self.handle && localScreen != undefined) {
- localScreen.getTracks().forEach((track) => track.stop());
- localScreen = undefined;
- }
- removeBroadcastElement(handle);
- removeBroadcastBadge(handle);
- if (handle == StumbleChat.Self.handle) resetBroadcastState();
- StumbleChat.Videos.Update();
- },
- publish: {
- create: (rcv) => {
- try {
- if (!StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) {
- let Transport = StumbleChat.Videos.Device.createSendTransport(rcv.transport);
- StumbleChat.Userlist.Broadcast.set(StumbleChat.Self.handle, {
- "volume": 100,
- "spectrum": undefined,
- "stream": new window.MediaStream(),
- "video": null,
- "audio": null,
- "canvas": null,
- "element": null,
- "transport": Transport,
- "iceInterval": undefined,
- "connectSent": false
- });
- Transport.on('connect', ({ dtlsParameters }) => {
- if (!StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).connectSent) {
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).connectSent = true;
- StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "publish", "type": "connect", "dtlsParameters": dtlsParameters }));
- }
- });
- Transport.on("produce", (producer) => StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "publish", "type": producer.kind, "rtpParameters": producer.rtpParameters })));
- Transport.on("connectionstatechange", (connectionState) => {
- if (StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) {
- if (connectionState == "connected") {
- clearInterval(StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).iceInterval);
- } else if (connectionState == "disconnected") {
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).iceInterval = setInterval((handle) => StumbleChat.WebSocket.send(`{"stumble":"publish","type":"ice","handle":"${handle}"}`), 10000, StumbleChat.Self.handle);
- }
- }
- });
- let elem = {};
- if (localScreen !== undefined) {
- elem = createBroadcastElement(StumbleChat.Self.handle);
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element = elem.video;
- if (StumbleChat.Self.directory) StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).canvas = elem.canvas;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element.srcObject = localScreen;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element.muted = true;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element.play();
- localScreen.getTracks().forEach((track) => {
- if (track.kind == "video") {
- track.contentHint = "motion";
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(1)`).classList[ StumbleChat.Self.Hidden ? "remove" : "add" ]("video_badge");
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(1)`).classList[ StumbleChat.Self.Hidden ? "add" : "remove" ]("video_badge_hide");
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(1)`).classList.remove("hidden");
- }
- if (track.kind == "audio") {
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(2)`).classList.add("audio_badge");
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(2)`).classList.remove("hidden");
- StumbleChat.Videos.Soundmeter(StumbleChat.Self.handle, localScreen);
- }
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .${track.kind}_badge`).classList.remove("hidden");
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).transport.produce({ track: track }).then((consumed) => StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle)[ track.kind ] = consumed);
- });
- document.getElementById('media-loading').classList.add('hidden');
- document.getElementById('media-stop').classList.add("no-audio");
- } else {
- let Constraints = {};
- if (StumbleChat.Chat.Settings.videodevice != "NONE") Constraints.video = { deviceId: StumbleChat.Chat.Settings.videodevice, width: StumbleChat.Videos.Resolutions[ StumbleChat.Chat.Settings.Resolution ][ 0 ], height: StumbleChat.Videos.Resolutions[ StumbleChat.Chat.Settings.Resolution ][ 1 ], frameRate: { ideal: StumbleChat.Videos.FrameRate, max: 60 } };
- if (StumbleChat.Chat.Settings.audiodevice != "NONE") Constraints.audio = { deviceId: StumbleChat.Chat.Settings.audiodevice, channelCount: { ideal: 2 }, echoCancellation: StumbleChat.Chat.Settings.EchoCancellation, autoGainControl: StumbleChat.Chat.Settings.AutoGainControl, noiseSuppression: StumbleChat.Chat.Settings.NoiseSupression };
- navigator.mediaDevices.getUserMedia(Constraints).then(stream => {
- if (!StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) return stream.getTracks().forEach((track) => track.stop());
- document.getElementById('media-loading').classList.add('hidden');
- document.getElementById('media-stop').classList.add("no-audio");
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).stream = stream;
- elem = createBroadcastElement(StumbleChat.Self.handle);
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element = elem.video;
- if (StumbleChat.Self.directory) StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).canvas = elem.canvas;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element.srcObject = StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).stream;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element.muted = true;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element.play();
- stream.getTracks().forEach((track, index) => {
- if (document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .${track.kind}_badge`) != undefined) document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .${track.kind}_badge`).classList.remove("hidden");
- document.getElementById('media-stop').classList.remove('hidden');
- if (track.kind == "audio") {
- document.getElementById('media-stop').classList.remove("no-audio");
- document.getElementById('media-ptt').classList.remove('hidden');
- document.getElementById('media-openmic').classList.remove('hidden');
- StumbleChat.Videos.Soundmeter(StumbleChat.Self.handle, stream);
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(2)`).classList.add("audio_badge");
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(2)`).classList.remove("hidden");
- }
- if (track.kind == "video") {
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(1)`).classList[ StumbleChat.Self.Hidden ? "remove" : "add" ]("video_badge");
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(1)`).classList[ StumbleChat.Self.Hidden ? "add" : "remove" ]("video_badge_hide");
- document.querySelector(`.bar[user-id="${StumbleChat.Self.handle}"] .status>div:nth-child(1)`).classList.remove("hidden");
- if (StumbleChat.Self.Hidden) track.enabled = false;
- }
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).transport.produce({ track: track }).then((produced) => {
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle)[ track.kind ] = produced;
- if (track.kind == "audio") StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).audio.pause();
- });
- });
- });
- }
- }
- } catch (e) {
- console.warn(e);
- Broadcast.unpublish(StumbleChat.Self.handle);
- Message.receive.public(`Fatal Error: Browser requires reloading to continue with anymore streams.`);
- }
- },
- connected: () => {
- Message.receive.public(`You have started broadcasting.`);
- document.getElementById('media-broadcast').classList.add('hidden');
- document.getElementById('media-settings').classList.add('hidden');
- document.getElementById('media-screen').classList.add('hidden');
- document.getElementById('media-stop').classList.remove('hidden');
- StumbleChat.Videos.Update();
- },
- error: (rcv) => {
- Message.receive.public(rcv.error);
- if (localScreen) localScreen.removeEventListener('inactive', (event) => Broadcast.unpublish(StumbleChat.Self.handle));
- Broadcast.unpublish(StumbleChat.Self.handle);
- },
- ice: (rcv) => {
- if (StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).transport.restartIce(rcv.transport);
- },
- close: () => Broadcast.unpublish(StumbleChat.Self.handle),
- disconnected: () => {
- clearTimeout(StumbleChat.Userlist.User.get(StumbleChat.Self.handle).disconnecttimer);
- if (StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) {
- if (StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).spectrum !== undefined) StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).spectrum.stop();
- clearInterval(StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).iceInterval);
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).stream.getTracks().forEach((track) => track.stop());
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).transport.close();
- }
- removeBroadcastElement(StumbleChat.Self.handle);
- removeBroadcastBadge(StumbleChat.Self.handle);
- resetBroadcastState();
- if (localScreen != undefined) {
- Message.receive.public("Stream disconnected. Try again.");
- localScreen.getTracks().forEach((track) => track.stop());
- localScreen = undefined;
- } else {
- Message.receive.public("Stream disconnected. Reloading broadcast again.");
- setTimeout(() => {
- requestBroadcast(StumbleChat.Videos.Password);
- }, 1000);
- }
- },
- cheese: () => {
- if (StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle) && StumbleChat.Self.directory) {
- try {
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).canvas.width = 320;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).canvas.height = 240;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).canvas.getContext('2d', { alpha: false }).drawImage(StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).element, 0, 0, 320, 240);
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "publish",
- "type": "cheese",
- "jpeg": StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).canvas.toDataURL('image/jpeg', 0.3)
- }));
- } catch (err) {
- console.warn(err);
- }
- }
- }
- },
- subscribe: {
- create: (rcv) => {
- try {
- if (!StumbleChat.Userlist.Broadcast.has(rcv.handle)) {
- let Transport = StumbleChat.Videos.Device.createRecvTransport(rcv.transport);
- StumbleChat.Userlist.Broadcast.set(rcv.handle, { "volume": 100, "spectrum": undefined, "stream": new window.MediaStream(), "video": null, "audio": null, "element": null, "transport": Transport, "iceInterval": undefined, "connectSent": false });
- Transport.on('connect', ({ dtlsParameters }) => {
- if (!StumbleChat.Userlist.Broadcast.get(rcv.handle).connectSent) {
- StumbleChat.Userlist.Broadcast.get(rcv.handle).connectSent = true;
- StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "subscribe", "type": "connect", "handle": rcv.handle, "dtlsParameters": dtlsParameters }));
- }
- });
- Transport.on("connectionstatechange", (connectionState) => {
- if (connectionState == "connected") {
- clearInterval(StumbleChat.Userlist.Broadcast.get(rcv.handle).iceInterval);
- } else if (connectionState == "disconnected") {
- StumbleChat.Userlist.Broadcast.get(rcv.handle).iceInterval = setInterval((handle) => StumbleChat.WebSocket.send(`{"stumble":"subscribe","type":"ice","handle":"${handle}"}`), 10000, rcv.handle);
- }
- });
- }
- } catch (e) {
- console.error(e);
- Broadcast.unpublish(rcv.handle);
- Message.receive.public(`Fatal Error: Browser requires reloading to continue with anymore streams.`);
- }
- StumbleChat.WebSocket.nextMessage();
- },
- consume: (rcv) => {
- try {
- if (StumbleChat.Userlist.Broadcast.has(rcv.handle)) {
- StumbleChat.Userlist.Broadcast.get(rcv.handle).transport.consume({ "id": rcv.consume.id, "producerId": rcv.consume.producerId, "kind": rcv.consume.kind, "rtpParameters": rcv.consume.rtpParameters }).then((consume) => {
- StumbleChat.Userlist.Broadcast.get(rcv.handle)[ rcv.consume.kind ] = consume;
- StumbleChat.Userlist.Broadcast.get(rcv.handle)[ rcv.consume.kind ].resume();
- StumbleChat.Userlist.Broadcast.get(rcv.handle).stream.addTrack(StumbleChat.Userlist.Broadcast.get(rcv.handle)[ rcv.consume.kind ].track);
- if (StumbleChat.Userlist.Broadcast.get(rcv.handle).element == null) {
- let elem = createBroadcastElement(rcv.handle);
- StumbleChat.Userlist.Broadcast.get(rcv.handle).element = elem.video;
- StumbleChat.Userlist.Broadcast.get(rcv.handle).element.srcObject = StumbleChat.Userlist.Broadcast.get(rcv.handle).stream;
- StumbleChat.Userlist.Broadcast.get(rcv.handle).element.controls = false;
- StumbleChat.Userlist.Broadcast.get(rcv.handle).element.play();
- }
- if (rcv.consume.kind == "audio") {
- if (StumbleChat.Chat.Settings.SoundmeterEnabled) {
- StumbleChat.Userlist.Broadcast.get(rcv.handle).spectrum = window.hark(StumbleChat.Userlist.Broadcast.get(rcv.handle).stream, {});
- let parent = StumbleChat.Userlist.Broadcast.get(rcv.handle).element.parentElement;
- parent.classList.add("visualizer");
- parent.setAttribute("volume", 0);
- StumbleChat.Userlist.Broadcast.get(rcv.handle).spectrum.on('volume_change', (volume) => {
- if (volume <= -100) parent.setAttribute("volume", 0);
- if (volume >= -100) parent.setAttribute("volume", 1);
- if (volume >= -95) parent.setAttribute("volume", 2);
- if (volume >= -90) parent.setAttribute("volume", 3);
- if (volume >= -80) parent.setAttribute("volume", 4);
- if (volume >= -70) parent.setAttribute("volume", 5);
- if (volume >= -60) parent.setAttribute("volume", 6);
- if (volume >= -50) parent.setAttribute("volume", 7);
- if (volume >= -40) parent.setAttribute("volume", 8);
- if (volume >= -30) parent.setAttribute("volume", 9);
- if (volume >= -15) parent.setAttribute("volume", 10);
- });
- }
- if (!StumbleChat.Userlist.User.get(rcv.handle).guest) {
- if (StumbleChat.Chat.Settings.BroadcastVolume[ StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase() ] !== undefined) StumbleChat.Userlist.Broadcast.get(rcv.handle).volume = StumbleChat.Chat.Settings.BroadcastVolume[ StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase() ];
- } else {
- if (StumbleChat.Chat.Settings.TempBroadcastVolume[ StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase() ] !== undefined) {
- StumbleChat.Userlist.Broadcast.get(rcv.handle).volume = StumbleChat.Chat.Settings.TempBroadcastVolume[ StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase() ];
- } else {
- StumbleChat.Chat.Settings.TempBroadcastVolume[ StumbleChat.Userlist.User.get(rcv.handle).username.toUpperCase() ] = 25;
- StumbleChat.Userlist.Broadcast.get(rcv.handle).volume = 25;
- }
- }
- StumbleChat.Userlist.Broadcast.get(rcv.handle).element.volume = (StumbleChat.Userlist.Broadcast.get(rcv.handle).volume / 100) * (StumbleChat.Chat.Settings.RoomVolume / 100);
- }
- StumbleChat.Videos.Update();
- StumbleChat.WebSocket.nextMessage();
- }).catch((e) => {
- console.error("Consume Error:", e);
- StumbleChat.WebSocket.nextMessage();
- });
- } else {
- Message.receive.public(`Fatal Error: Couldn't consume a user, this is a developer issue and will be fixed soon. Do refresh; likely caused by server restarts.`);
- StumbleChat.WebSocket.nextMessage();
- }
- } catch (e) {
- console.error("Consume Error:", e);
- StumbleChat.WebSocket.nextMessage();
- }
- },
- connected: (rcv) => {
- if (StumbleChat.Userlist.User.has(rcv.handle)) Message.receive.public(`${StumbleChat.Userlist.User.get(rcv.handle).nick} started broadcasting!`);
- StumbleChat.WebSocket.nextMessage();
- },
- ice: (rcv) => {
- StumbleChat.Userlist.Broadcast.get(rcv.handle).transport.restartIce(rcv.transport);
- StumbleChat.WebSocket.nextMessage();
- },
- disconnected: (rcv) => {
- clearTimeout(StumbleChat.Userlist.User.get(rcv.handle).disconnecttimer);
- if (StumbleChat.Userlist.Broadcast.has(rcv.handle)) {
- if (StumbleChat.Userlist.Broadcast.get(rcv.handle).spectrum !== undefined) StumbleChat.Userlist.Broadcast.get(rcv.handle).spectrum.stop();
- StumbleChat.Userlist.Broadcast.get(rcv.handle).stream.getTracks().forEach((track) => track.stop());
- StumbleChat.Userlist.Broadcast.get(rcv.handle).transport.close();
- }
- StumbleChat.Userlist.Broadcast.delete(rcv.handle);
- StumbleChat.Videos.Update();
- StumbleChat.Userlist.User.get(rcv.handle).disconnecttimer = setTimeout((handle) => {
- StumbleChat.Userlist.User.get(handle).broadcasting.forEach((value) => StumbleChat.WebSocket.send(`{"stumble":"subscribe","type":"request","handle":"${handle}","kind":"${value}"}`));
- }, 3000, rcv.handle);
- StumbleChat.WebSocket.nextMessage();
- }
- }
- };
- function rollDiceAndDisplay () {
- // Generate a random number between 1 and 6 (inclusive) for a standard six-sided die
- const min = 1;
- const max = 6;
- const result = Math.floor(Math.random() * (max - min + 1)) + min;
- // Define Unicode dice symbols for numbers 1 through 6
- const diceSymbols = [ '⚀', '⚁', '⚂', '⚃', '⚄', '⚅' ];
- // Display the rolled dice symbol
- const diceSymbol = diceSymbols[ result - 1 ];
- return diceSymbol;
- }
- let Message = {
- send: (event) => {
- if ((event.key == "Enter" || event.code == "Enter") && !event.shiftKey) {
- event.preventDefault();
- StumbleChat.Chat.Status.Timelastpost = new Date();
- let text = document.getElementById("textarea");
- if (text.value.length > 0) {
- text.value = text.value.replace(/</g, '<').replace(/>/g, '>').replace(/ +/g, ' ');
- text.focus();
- if (text.value.match(/^\s*$/)) {
- text.value = "";
- return;
- }
- let command = text.value.match(/^(?:!|\/)([a-z?]{1,20})/i);
- if (command) {
- switch (command[ 1 ]) {
- case "help":
- Message.receive.public(`/help\n\n/device`);
- break;
- case "device":
- Message.receive.public(`Detected Device:\n${window.stumblechatClient.detectDevice()}`);
- break;
- case "roll":
- if (StumbleChat.WebSocket.readyState == 1) StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "msg",
- "text": rollDiceAndDisplay()
- }));
- break;
- }
- } else {
- if (StumbleChat.Chat.Selected == 0) {
- // Main Chat Selected
- if (StumbleChat.WebSocket !== null) {
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "msg",
- "text": text.value
- }));
- }
- } else {
- if (StumbleChat.Userlist.User.has(StumbleChat.Chat.Selected)) {
- // Private Chat Selected
- Message.receive.private(StumbleChat.Chat.Selected, text.value, StumbleChat.Self.handle, StumbleChat.Self.nick, StumbleChat.Self.avatar, StumbleChat.Self.namebackgroundcolor, StumbleChat.Self.backgroundcolor, StumbleChat.Self.messagetextcolor);
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "pvtmsg",
- "handle": StumbleChat.Chat.Selected,
- "text": text.value
- }));
- } else {
- Message.receive.private(StumbleChat.Chat.Selected, `User is offline. Message couldn't be delivered.`);
- }
- }
- }
- text.value = "";
- }
- }
- },
- receive: {
- public: (msg, username, nick, avatar, namebackgroundcolor, backgroundcolor, messagetextcolor) => {
- let Time = currentTime();
- let message = msg.replace(/</g, '<').replace(/>/g, '>').replace(/ +/g, ' ');
- if (message == " ") return;
- if (!StumbleChat.Chat.Messages.has(0)) StumbleChat.Chat.Messages.set(0, []);
- if (StumbleChat.Chat.Settings.LinksEnabled) message = parseLink(message);
- if (StumbleChat.Chat.Settings.ImgurEnabled) message = parseImgur(message);
- StumbleChat.Chat.Messages.get(0).push({
- "username": username,
- "nick": nick,
- "msg": message,
- "time": Time,
- "avatar": avatar,
- "namebackgroundcolor": namebackgroundcolor,
- "backgroundcolor": backgroundcolor,
- "messagetextcolor": messagetextcolor
- });
- if (nick !== StumbleChat.Self.nick && nick !== undefined && StumbleChat.Chat.Settings.SoundsEnabled && StumbleChat.Userlist.User.size <= 12) {
- StumbleChat.Chat.Sounds.public_message.pause();
- StumbleChat.Chat.Sounds.public_message.currentTime = 0;
- StumbleChat.Chat.Sounds.public_message.play();
- }
- if (StumbleChat.Chat.Selected == 0) {
- Message.unread();
- let len = StumbleChat.Chat.Messages.get(0).length - 2;
- if (len >= 0) {
- if (StumbleChat.Chat.Messages.get(0)[ len ].username == username && username != undefined && nick == StumbleChat.Chat.Messages.get(0)[ len ].nick) {
- let element = document.createElement("div");
- element.setAttribute("class", "content");
- element.innerHTML = `<span class="hidden-selectable">[${Time}]</span><span class="timestamp">${Time}</span><span class="message common" style="color:${messagetextcolor}">${message}</span></div>`;
- document.querySelector("#chat-content>.message:last-child").appendChild(element);
- } else {
- createChatItem({
- nick: nick,
- time: Time,
- avatar: avatar,
- msg: message,
- backgroundcolor: backgroundcolor,
- namebackgroundcolor: namebackgroundcolor,
- messagetextcolor: messagetextcolor,
- });
- }
- } else {
- createChatItem({
- nick: nick,
- time: Time,
- avatar: avatar,
- msg: message,
- backgroundcolor: backgroundcolor,
- namebackgroundcolor: namebackgroundcolor,
- messagetextcolor: messagetextcolor,
- });
- }
- StumbleChat.Chat.Scroll();
- }
- },
- private: (handle, msg, sender, nick, avatar, namebackgroundcolor, backgroundcolor, messagetextcolor) => {
- if (StumbleChat.Chat.Settings.PrivateMessageEnabled == false) return;
- let message = msg.replace(/</g, '<').replace(/>/g, '>').replace(/ +/g, ' ');
- if (message == " ") return;
- if (StumbleChat.Userlist.User.has(handle)) {
- let acc = StumbleChat.Userlist.User.get(handle);
- if (!StumbleChat.Chat.Messages.has(handle)) {
- StumbleChat.Chat.Messages.set(handle, {
- username: (acc.guest == 0) ? acc.username : "guest",
- nick: acc.nick,
- avatar: acc.avatar,
- missedmsg: 0,
- message: [],
- namebackgroundcolor: namebackgroundcolor,
- backgroundcolor: backgroundcolor,
- messagetextcolor: messagetextcolor
- });
- }
- let PM = document.querySelector(".privateMessages");
- if (!PM.querySelector(`[user-id="${handle}"]`)) {
- document.querySelector("#userlist>h2:nth-child(2)").classList.remove("hidden");
- PM.classList.remove("hidden");
- let element = document.createElement('div');
- element.setAttribute("class", "list-item");
- element.innerHTML = `<span class="private" user-id=${handle}><div class="nickname">${StumbleChat.Userlist.User.get(handle).nick}</div><div class="unreadpm"></div><span class="closepm">x</span></span>`;
- document.querySelector(".privateMessages").insertAdjacentHTML("afterBegin", element.outerHTML);
- }
- if (StumbleChat.Chat.Selected !== handle) {
- StumbleChat.Chat.Messages.get(handle).missedmsg++;
- PM.querySelector(`[user-id="${handle}"]>.unreadpm`).innerText = StumbleChat.Chat.Messages.get(handle).missedmsg;
- PM.querySelector(`[user-id="${handle}"]>.unreadpm`).classList.add("show");
- }
- }
- let Time = currentTime();
- if (StumbleChat.Chat.Settings.LinksEnabled) message = parseLink(message);
- if (StumbleChat.Chat.Settings.ImgurEnabled) message = parseImgur(message);
- StumbleChat.Chat.Messages.get(handle).message.push({
- "handle": sender,
- "nick": nick,
- "avatar": avatar,
- "msg": message,
- "time": Time,
- namebackgroundcolor: namebackgroundcolor,
- backgroundcolor: backgroundcolor,
- messagetextcolor: messagetextcolor
- });
- if (StumbleChat.Chat.Selected === handle) {
- Message.unread();
- let len = StumbleChat.Chat.Messages.get(handle).message.length - 2;
- if (len >= 0) {
- if (StumbleChat.Chat.Messages.get(handle).message[ len ].nick == nick && StumbleChat.Chat.Messages.get(handle).message[ len ].handle == sender) {
- let element = document.createElement("div");
- element.setAttribute("class", "content");
- element.innerHTML = `<span class="hidden-selectable">[${Time}]</span><span class="timestamp">${Time}</span><span class="message common" style="color:${messagetextcolor}">${message}</span></div>`;
- document.querySelector("#chat-content>.message:last-child").appendChild(element);
- } else {
- createChatItem({
- nick: nick,
- time: Time,
- avatar: avatar,
- msg: message,
- backgroundcolor: backgroundcolor,
- namebackgroundcolor: namebackgroundcolor,
- messagetextcolor: messagetextcolor,
- });
- }
- } else {
- createChatItem({
- nick: nick,
- time: Time,
- avatar: avatar,
- msg: message,
- backgroundcolor: backgroundcolor,
- namebackgroundcolor: namebackgroundcolor,
- messagetextcolor: messagetextcolor,
- });
- }
- StumbleChat.Chat.Scroll();
- }
- if (nick !== StumbleChat.Self.nick && StumbleChat.Chat.Settings.SoundsEnabled) {
- StumbleChat.Chat.Sounds.private_message.pause();
- StumbleChat.Chat.Sounds.private_message.currentTime = 0;
- StumbleChat.Chat.Sounds.private_message.play();
- }
- }
- },
- unread: () => {
- StumbleChat.Chat.Settings.Scroll = (Math.floor(document.getElementById("chat").scrollTop + 50) >= (document.getElementById("chat").scrollHeight - document.getElementById("chat").offsetHeight));
- if (StumbleChat.Chat.Settings.Scroll) {
- StumbleChat.Chat.Status.MissedMsg = 0;
- document.querySelector(".unreadmessage").classList.add("hidden");
- } else {
- StumbleChat.Chat.Status.MissedMsg++;
- document.querySelector(".unreadmessage").classList.remove("hidden");
- document.querySelector(".unreadmessage").innerHTML = "There are " + StumbleChat.Chat.Status.MissedMsg + " unread message(s)!";
- }
- }
- };
- let App = {
- Init: () => {
- window.AudioContext = window.AudioContext || window.webkitAudioContext;
- new window.AudioContext();
- // Prefetch elements commonly used.
- StumbleChat.Userlist.list = document.querySelector("#userlist>.list");
- // Attempts
- StumbleChat.Chat.Status.Resets++;
- if (StumbleChat.Chat.Status.Resets >= 10) return Modal.Create(3, "Cannot connect right now, try to refresh again shortly.");
- if (StumbleChat.Chat.Status.LoadedEventListenersInit == false) App.Listeners();
- if (!StumbleChat.Chat.Status.Kicked) App.Auth();
- },
- Auth: (password) => {
- Modal.Create(2);
- let Token = new XMLHttpRequest();
- Token.open("POST", `https://${window.location.hostname}/api/room/token`);
- Token.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
- Token.setRequestHeader("CSRF-Token", document.getElementsByName('_csrf')[ 0 ].getAttribute("content"));
- Token.onload = () => {
- if (Token.status != 200) return Modal.Create(3, "Server did not respond to our request");
- Modal.Destroy();
- let parse;
- try {
- parse = JSON.parse(Token.responseText);
- } catch (E) {
- parse = null;
- return Modal.Create(3, "You're temporarily blocked");
- }
- if (parse.error != "") return Modal.Create(3, parse.error);
- if (typeof parse.password == "boolean") {
- if (parse.password == false) return App.Socket(parse);
- Modal.Create(15);
- } else {
- Modal.Create(15, parse.password);
- }
- };
- Token.onerror = () => reloadClient();
- Token.send(JSON.stringify({
- name: StumbleChat.Room.name,
- password: password
- }));
- },
- Listeners: () => {
- StumbleChat.Userlist.Menu.Check();
- StumbleChat.Videos.Menu.Check();
- document.getElementById('media-stop').addEventListener('pointerdown', () => {
- StumbleChat.WebSocket.send(`{"stumble":"publish","type":"close"}`);
- Broadcast.unpublish(StumbleChat.Self.handle);
- }, {
- passive: true
- });
- StumbleChat.Chat.Status.LoadedEventListenersInit = true;
- },
- Socket: (parse) => {
- Modal.Create(2);
- StumbleChat.WebSocket = new WebSocket(parse.endpoint);
- StumbleChat.WebSocket.onopen = () => {
- window.wss = StumbleChat.WebSocket;
- Modal.Destroy();
- StumbleChat.Chat.Status.Resets = 0;
- loadStorage();
- let nick = (localStorage.getItem("nick") != null) ? localStorage.getItem("nick") : null;
- if (StumbleChat.Chat.Settings.LargeEmbeddedVideos == true) document.querySelector("#videos").prepend(document.querySelector(`#videos>div:nth-child(2)`));
- if (StumbleChat.Chat.Settings.LargeFont == true) document.querySelector("#chat-content").classList.add("large");
- StumbleChat.WebSocket.send(`{"stumble":"join","token":"${parse.result}","room":"${StumbleChat.Room.name.toLowerCase()}","nick":"${(nick == undefined) ? "" : nick}"}`);
- };
- StumbleChat.WebSocket.onclose = (e) => reloadClient();
- StumbleChat.WebSocket.nextMessage = () => {
- if (SubscribeQueue.splice(0, 1) && SubscribeQueue.length >= 1) Broadcast.subscribe[ SubscribeQueue[ 0 ].type ](SubscribeQueue[ 0 ]);
- };
- StumbleChat.WebSocket.onmessage = (rcv) => {
- try {
- if (rcv.data == 0) StumbleChat.WebSocket.send(0);
- let b = JSON.parse(rcv.data),
- d = b.stumble;
- if (typeof ServerResponse[ d ] === "function") ServerResponse[ b.stumble ](b);
- } catch (e) {
- console.warn(e, rcv.data);
- }
- };
- },
- Clear: () => {
- StumbleChat.WebSocket = null;
- let elem = document.querySelector("#twitchplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- elem = document.querySelector("#worldstarhiphopplayer>video");
- if (elem !== null) elem.parentNode.removeChild(elem);
- elem = document.querySelector("#soundcloudplayer>video");
- if (elem !== null) elem.parentNode.removeChild(elem);
- elem = document.querySelector("#dailymotionplayer>video");
- if (elem !== null) elem.parentNode.removeChild(elem);
- if (window.YouTubePlayer) {
- //document.querySelector("#youtube-volume-slider").value = 100;
- window.YouTubePlayer.destroy();
- window.YouTubePlayer = undefined;
- }
- document.querySelector("#videos > div > .youtube").classList.add("hidden");
- document.querySelector("#videos > div > .twitch").classList.add("hidden");
- document.querySelector("#videos > div > .soundcloud").classList.add("hidden");
- document.querySelector("#videos > div > .dailymotion").classList.add("hidden");
- document.querySelector("#videos > div > .worldstarhiphop").classList.add("hidden");
- document.querySelectorAll(`.privateMessages .nickname`).forEach((value, key) => {
- if (!value.innerText.includes("(offline)")) value.innerText += ` (offline)`;
- });
- if (!StumbleChat.Chat.Settings.isMobile) document.querySelector("#media-screen").classList.add("hidden");
- document.getElementById('media-broadcast').classList.add('hidden');
- document.getElementById('media-settings').classList.add('hidden');
- document.getElementById('media-loading').classList.add('hidden');
- document.getElementById('media-ptt').classList.add('hidden');
- document.getElementById('media-openmic').classList.add('hidden');
- document.getElementById('media-stop').classList.add('hidden');
- document.getElementById('media-stop').classList.remove("no-audio");
- StumbleChat.Userlist.User.forEach((value, key) => {
- let element = document.querySelector(`.bar[user-id="${key}"]`);
- if (element !== undefined) element.remove();
- });
- StumbleChat.Userlist.Broadcast.forEach((user, handle) => Broadcast.unpublish(handle));
- StumbleChat.Userlist.Broadcast = new Map();
- StumbleChat.Userlist.User = new Map();
- StumbleChat.Userlist.Count();
- },
- ChangeNick: () => {
- let nickname = document.getElementById("modal-text-input").value;
- if (nickname.match(/^([a-z0-9_]){1,16}$/i)) {
- for (let value of StumbleChat.Userlist.User) {
- if (value[ 1 ].nick.toUpperCase() === nickname.toUpperCase()) {
- Message.receive.public("This name is already taken, try another one.");
- return;
- }
- }
- if (nickname !== StumbleChat.Self.nick && StumbleChat.Userlist.User) {
- StumbleChat.WebSocket.send(`{"stumble":"nick","nick":"${document.getElementById("modal-text-input").value}"}`);
- Modal.Destroy();
- }
- }
- }
- };
- let Modal = {
- Create: (Type, msg) => {
- Modal.Destroy();
- StumbleChat.Chat.Status.ModalOpened = Type;
- document.getElementById('modal-back').classList.add("visible");
- Modal.Items[ Type ](msg);
- Modal.Center();
- },
- Destroy: () => {
- StumbleChat.Chat.Status.AdjustingQueue = false;
- StumbleChat.Chat.Status.ModalOpened = -1;
- document.getElementById('modal-back').classList.remove('visible');
- document.getElementById('modal-exit').classList.remove('visible');
- //document.querySelector("#textarea").focus();
- },
- Center: () => {
- let el = document.querySelector("#modal");
- if (el) el.style.marginTop = (window.innerHeight - el.offsetHeight) / 2 + 'px';
- },
- Items: {
- 0: () => { // Broadcast Options
- document.getElementById('modal-back').classList.remove("visible");
- document.querySelector("#modal > #title > p").innerHTML = `MEDIA OPTIONS`;
- document.querySelector("#modal > span").innerHTML = `<div id="broadcast-wrapper"><video id="previewvideo" autoplay="" class="hidden" playsinline="">Your browser does not support the video tag...</video><select id="videoSelect"></select><select id="audioSelect"></select><p>FRAMERATE:</p><div class="framerate-wrapper"><input class="framerate-options" type="radio" id="framerate1" name="framerate" value="15" ${(StumbleChat.Chat.Settings.FrameRate == 15) ? 'checked="checked"' : ""}"><label for="framerate1">15</label><input class="framerate-options" type="radio" id="framerate2" name="framerate" value="30" ${(StumbleChat.Chat.Settings.FrameRate == 30) ? 'checked="checked"' : ""}"><label for="framerate2">30</label><input class="framerate-options" type="radio" id="framerate3" name="framerate" value="60" ${(StumbleChat.Chat.Settings.FrameRate == 60) ? 'checked="checked"' : ""}"><label for="framerate3">60</label></div><p>RESOLUTION: </p><div class="resolution-wrapper"><input class="resolution-options" type="radio" id="resolution1" name="resolution" value="0" ${(StumbleChat.Chat.Settings.Resolution == 0) ? 'checked="checked"' : ""}><label for="resolution1">352x240 (240p)</label><br><input class="resolution-options" type="radio" id="resolution2" name="resolution" value="1" ${(StumbleChat.Chat.Settings.Resolution == 1) ? 'checked="checked"' : ""}><label for="resolution2">480x360 (360p)</label><br><input class="resolution-options" type="radio" id="resolution3" name="resolution" value="2" ${(StumbleChat.Chat.Settings.Resolution == 2) ? 'checked="checked"' : ""}><label for="resolution3">858x480 (480p)</label><br><input class="resolution-options" type="radio" id="resolution4" name="resolution" value="3" ${(StumbleChat.Chat.Settings.Resolution == 3) ? 'checked="checked"' : ""}><label for="resolution4">1280x720 (720p)</label> <br><input class="resolution-options" type="radio" id="resolution5" name="resolution" value="4" ${(StumbleChat.Chat.Settings.Resolution == 4) ? 'checked="checked"' : ""}> <label for="resolution5">1920x1080 (1080p)</label> <br><input class="resolution-options" type="radio" id="resolution6" name="resolution" value="5" ${(StumbleChat.Chat.Settings.Resolution == 5) ? 'checked="checked"' : ""}> <label for="resolution6">4096x2160 (4K)</label></div><p>ENHANCEMENTS:</p><div class="enhancement-wrapper"><input type="checkbox" id="enhancement1" name="enhancement" value="echoCancellation" ${(StumbleChat.Chat.Settings.EchoCancellation) ? 'checked="checked"' : ""}><label for="enhancement1">Echo Cancellation</label><br><input type="checkbox" id="enhancement2" name="enhancement" value="autoGainControl" ${(StumbleChat.Chat.Settings.AutoGainControl) ? 'checked="checked"' : ""}><label for="enhancement2">Auto Gain Control</label><br><input type="checkbox" id="enhancement3" name="enhancement" value="noiseSuppression" ${(StumbleChat.Chat.Settings.NoiseSupression) ? 'checked="checked"' : ""}><label for="enhancement3">Noise Supression</label></div><button id='broadcastsettings'>SAVE</button></div>`;
- navigator.mediaDevices.enumerateDevices().then((Devices) => {
- createBroadcastItem(window.videoSelect, StumbleChat.Chat.Settings.videodevice, (StumbleChat.Chat.Settings.videodevice == "NONE" || StumbleChat.Chat.Settings.videodevice == null) ? "NONE" : "Saved Video Device");
- createBroadcastItem(window.audioSelect, StumbleChat.Chat.Settings.audiodevice, (StumbleChat.Chat.Settings.audiodevice == "NONE" || StumbleChat.Chat.Settings.audiodevice == null) ? "NONE" : "Saved Audio Device");
- if (StumbleChat.Chat.Settings.videodevice != "NONE") createBroadcastItem(window.videoSelect, "NONE", "NONE");
- if (StumbleChat.Chat.Settings.audiodevice != "NONE") createBroadcastItem(window.audioSelect, "NONE", "NONE");
- let audiocount = 0;
- let videocount = 0;
- for (let i = 0; i !== Devices.length; ++i) {
- const deviceInfo = Devices[ i ];
- if (deviceInfo.kind === 'audioinput') {
- createBroadcastItem(window.audioSelect, deviceInfo.deviceId, deviceInfo.label || `microphone ${++audiocount}`);
- } else if (deviceInfo.kind === 'videoinput') {
- createBroadcastItem(window.videoSelect, deviceInfo.deviceId, deviceInfo.label || `camera ${++videocount}`);
- }
- }
- if (StumbleChat.Chat.Settings.videodevice != "NONE") previewBroadcast(StumbleChat.Chat.Settings.videodevice);
- }).catch((err) => {
- Message.receive.public(`${err}`);
- });
- document.getElementById('modal-back').classList.add("visible");
- Modal.Center();
- },
- 1: () => { // Compatibility Warning
- document.querySelector("#modal > #title > p").innerHTML = `COMPATIBILITY WARNING`;
- document.querySelector("#modal > span").innerHTML = `You may experience issues with the app, in this case try a different browser!`;
- document.getElementById('modal-exit').classList.add("visible");
- },
- 2: () => { // Connecting
- document.querySelector("#modal > #title > p").innerHTML = `CONNECTING...`;
- document.querySelector("#modal > span").innerHTML = `<div class="lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>`;
- },
- 3: (msg) => { // Error
- document.querySelector("#modal > #title > p").innerHTML = `ERROR...`;
- document.querySelector("#modal > span").innerHTML = `${msg}`;
- },
- 4: () => { // Interact (First Time)
- StumbleChat.Chat.Settings.background = parseStorage("background", "#111111");
- StumbleChat.Chat.Settings.backgroundUrl = parseStorage("backgroundUrl", "");
- StumbleChat.Chat.Settings.chatcolor = parseStorage("chatcolor", "#000000");
- StumbleChat.Chat.Background.Load();
- StumbleChat.Chat.Color.Load();
- document.querySelector("#modal > #title > p").innerHTML = `VERIFY...`;
- document.querySelector("#modal > span").innerHTML = `<button id='interact'>VERIFY</button>`;
- },
- 5: () => { // Change Nickname
- document.querySelector("#modal > #title > p").innerHTML = `HELLO MY NAME IS`;
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off"><input id="modal-text-input" placeholder="${StumbleChat.Self.nick}" title="Accepted Character Range: a-z, A-Z, _, and 0-9 between 1 to 16 characters" pattern="^[A-Za-z0-9_]{1,16}$" type="text"></input><input type="submit"value="Set" id='change-nick'></input></form>`;
- document.querySelector("#modal-text-input").focus();
- document.getElementById('modal-exit').classList.add("visible");
- },
- 6: (msg) => { // Broadcast password
- document.querySelector("#modal > #title > p").innerHTML = `Broadcast Password`;
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off"><input id="modal-text-hidden" type="text" value="${msg}" hidden><input id="modal-text-input" placeholder="Password" autocomplete="off" value="${(StumbleChat.Videos.Password !== undefined) ? StumbleChat.Videos.Password : ""}"></input><input type="submit" value="Submit" id='broadcastpassword'></input></form>`;
- document.getElementById('modal-exit').classList.add("visible");
- document.querySelector("#modal-text-input").focus();
- },
- 7: (msg) => { // YouTube Search
- StumbleChat.Chat.Status.AdjustingQueue = true;
- document.querySelector("#modal > #title > p").innerHTML = `YouTube Search`;
- let Playlist = ``;
- for (let i = 0; i < msg.length; i++) {
- if (i === 0) {
- Playlist += `<br><br><h1>PLAYING</h1><ul><li class="youtubelist" id="${msg[ i ].queueid}"><img class="youtube_thumbnail" src="${msg[ i ].thumbnail}" alt="YouTube Thumbnail"><span class="close">x</span><p class="youtube_title">${msg[ i ].title}</p><p class="youtube_title">Username: ${msg[ i ].username} | Duration: ${new Date(msg[ i ].duration * 1000).toISOString().substr(11, 8)}</p></li></ul>`;
- if (msg.length > 1) Playlist += `<h1>UP NEXT</h1><ul id="youtuberemove" name="moderatorlist">`;
- }
- if (i !== 0) {
- Playlist += `<li class="youtubelist" id="${msg[ i ].queueid}"><img class="youtube_thumbnail" src="${msg[ i ].thumbnail}" alt="YouTube Thumbnail"><span class="close">x</span><p class="youtube_title">${msg[ i ].title}</p><p class="youtube_title">Username: ${msg[ i ].username} | Duration: ${new Date(msg[ i ].duration * 1000).toISOString().substr(11, 8)}</p></li>`;
- if (i == msg.length) Playlist += `</ul>`;
- }
- }
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off"><input id="modal-text-input" placeholder="Link/Keyword Search" type="text"></input><input type="submit" value="Submit" id='search'></input> ${Playlist} </form>`;
- document.querySelector("#modal-text-input").focus();
- document.getElementById('modal-exit').classList.add("visible");
- },
- 8: (msg) => { // ATTENTION / NOTICE
- document.querySelector("#modal > #title > p").innerHTML = `ATTENTION...`;
- document.querySelector("#modal > span").innerHTML = `${msg}`;
- },
- 9: (msg) => { // Ban List
- document.querySelector("#modal > #title > p").innerHTML = `Ban List`;
- let List = ``;
- msg.forEach((value, index) => List += `<li class="banlist" user-id="${value[ 0 ]}" username="${value[ 1 ]}">${value[ 1 ]}<span class="close">x</span></li>`);
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off"><ul id="banremove" name="moderatorlist"> ${(List == '') ? `<li class="banlist">LIST IS EMPTY</li>` : List} </ul></form>`;
- document.getElementById('modal-exit').classList.add("visible");
- },
- 10: () => { // User Options
- document.querySelector("#modal > #title > p").innerHTML = `Client Settings`;
- document.querySelector("#modal > span").innerHTML =
- `<div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.SoundmeterEnabled == true) ? `checked` : ``}>
- <span id="soundmeter" class="slider round"></span>
- </label>
- <h2>Soundmeter:</h2>
- </div>
- <h3>Track broadcast audio levels.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.YouTubeEnabled == true) ? `checked` : ``}>
- <span id="youtube" class="slider round"></span>
- </label>
- <h2>YouTube:</h2>
- </div>
- <h3>Watch YouTube embeds.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.TwitchEnabled == true) ? `checked` : ``}>
- <span id="twitch" class="slider round"></span>
- </label>
- <h2>Twitch:</h2>
- </div>
- <h3>Watch Twitch embeds.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.WSHHEnabled == true) ? `checked` : ``}>
- <span id="wshh" class="slider round"></span>
- </label>
- <h2>WSHH:</h2>
- </div>
- <h3>Watch WSHH embeds.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.DailyMotionEnabled == true) ? `checked` : ``}>
- <span id="dailymotion" class="slider round"></span>
- </label>
- <h2>DailyMotion:</h2>
- </div>
- <h3>Watch DailyMotion embeds.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.SoundCloudEnabled == true) ? `checked` : ``}>
- <span id="soundcloud" class="slider round"></span>
- </label>
- <h2>SoundCloud:</h2>
- </div>
- <h3>Watch SoundCloud embeds.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.PrivateMessageEnabled == true) ? `checked` : ``}>
- <span id="pm" class="slider round"></span>
- </label>
- <h2>PMs:</h2>
- </div>
- <h3>Allow private messages from other users.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.SoundsEnabled == true) ? `checked` : ``}>
- <span id="sounds" class="slider round"></span>
- </label>
- <h2>Chat Sounds:</h2>
- </div>
- <h3>Get audio alerts when there's a message.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.ImgurEnabled == true) ? `checked` : ``}>
- <span id="imgur" class="slider round"></span>
- </label>
- <h2>Imgur:</h2>
- <h3>Show Imgur images/videos posted by other users in the chat.</h3>
- </div>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.LinksEnabled == true) ? `checked` : ``}>
- <span id="links" class="slider round"></span>
- </label>
- <h2>Links:</h2>
- <h3>Show links posted by other users.</h3>
- </div>`;
- document.getElementById('modal-exit').classList.add("visible");
- },
- 11: (msg) => { // User Profile
- document.querySelector("#modal > #title > p").innerHTML = `${msg.username}`;
- let date = new Date(msg.created);
- document.querySelector("#modal > span").innerHTML = ` <div class="card"><p class="age">CREATED: ${date.toLocaleDateString("en-US")}</p><img src="${(msg.avatar == undefined) ? "/styles/images/no-background.png" : `/profile/${msg.username.toLowerCase()}/cached/large_avatar.jpg`}" style="width:180px; height:100px;margin:0 auto;" alt="Avatar"><p class="age">AGE: ${msg.age}</p><p class="title">${(msg.description !== null) ? msg.description : "No Description"}</p><br><p>Subscription: ${msg.subscription} | Coins: ${msg.coins}</p></div>`;
- document.getElementById('modal-exit').classList.add("visible");
- },
- 12: () => { // Twitch Search
- document.querySelector("#modal > #title > p").innerHTML = `Twitch Search`;
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off"><input id="modal-text-input" placeholder="Channel" type="text"></input><input type="submit" id='twitch-close' value="Stop"></input><input type="submit" value="Submit" id='searchtwitch'></input></form>`;
- document.querySelector("#modal-text-input").focus();
- document.getElementById('modal-exit').classList.add("visible");
- },
- 13: () => { // Topic
- document.querySelector("#modal > #title > p").innerHTML = `TOPIC`;
- document.querySelector("#modal > span").innerText = (StumbleChat.Room.topic) ? `${StumbleChat.Room.topic}` : `No Topic`;
- document.getElementById('modal-exit').classList.add("visible");
- },
- 14: () => { // Chat Color
- let currentcolor = "";
- if (StumbleChat.Chat.Settings.background.match(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/) !== null || StumbleChat.Chat.Settings.background.match(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/) !== null) currentcolor = `value="${StumbleChat.Chat.Settings.background}"`;
- document.querySelector("#modal > #title > p").innerHTML = `Theme Settings`;
- document.querySelector("#modal > span").innerHTML =
- `<p>Chat Color:</p>
- <br>
- <form action="javascript:void(0);" autocomplete="off">
- <input id="modal-color-input" value="${StumbleChat.Chat.Settings.chatcolor}" type="color"></input>
- <input style="width:46px;" type="submit" id='resetchatcolor' value="Reset"></input>
- <input style="width:54px;" type="submit" id='setchatcolor' value="Set"></input>
- </form>
- <hr>
- <p>Background URL/Color:</p>
- <br>
- <br>
- <form action="javascript:void(0);" autocomplete="off">
- <input id="modal-text-input" placeholder="${StumbleChat.Chat.Settings.backgroundUrl == "" ? "Image Url" : StumbleChat.Chat.Settings.backgroundUrl}" type="text"></input>
- <input type="color" id='modal-bgcolor-input' ${currentcolor}></input>
- <input style="width:46px;" type="submit" id='resetbackground' value="Reset"></input>
- <input style="width:54px;" type="submit" id='setbackground' value="Set"></input>
- </form>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.LargeEmbeddedVideos == true) ? `checked` : ``}>
- <span id="largeembeddedvideos" class="slider round"></span>
- </label>
- <h2>Large Embedded Videos:</h2>
- </div>
- <h3>Change size of broadcasts and embedded videos.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Chat.Settings.LargeFont == true) ? `checked` : ``}>
- <span id="largefont" class="slider round"></span>
- </label>
- <h2>Large Font:</h2>
- </div>
- <h3>Adjust font size.</h3>`;
- document.getElementById('modal-exit').classList.add("visible");
- },
- 15: (msg) => { // Room password
- msg = (msg) ? `<div class="warning-label">${msg}</div>` : ``;
- document.querySelector("#modal > #title > p").innerHTML = `Room Password`;
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off">${msg}<input id="modal-text-input" placeholder="${(StumbleChat.Chat.Password == undefined) ? "Password" : StumbleChat.Chat.Password}" autocomplete="off" value="${(StumbleChat.Chat.Password !== undefined) ? StumbleChat.Chat.Password : ""}"></input><input type="submit" value="Set" id='roompassword'></input></form>`;
- document.querySelector("#modal-text-input").focus();
- },
- 16: () => { // worldstarhiphop
- document.querySelector("#modal > #title > p").innerHTML = `WSHH Search`;
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off"><input id="modal-text-input" placeholder="URL" type="text"></input><input type="submit" id='worldstarhiphop-close' value="Stop"></input><input type="submit" value="Submit" id='searchworldstarhiphop'></input></form>`;
- document.querySelector("#modal-text-input").focus();
- document.getElementById('modal-exit').classList.add("visible");
- },
- 17: () => { // worldstarhiphop
- document.querySelector("#modal > #title > p").innerHTML = `SoundCloud Search`;
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off"><input id="modal-text-input" placeholder="URL" type="text"></input><input type="submit" id='soundcloud-close' value="Stop"></input><input type="submit" value="Submit" id='searchsoundcloud'></input></form>`;
- document.querySelector("#modal-text-input").focus();
- document.getElementById('modal-exit').classList.add("visible");
- },
- 18: () => { // dailymotion
- document.querySelector("#modal > #title > p").innerHTML = `DailyMotion Search`;
- document.querySelector("#modal > span").innerHTML = `<form action="javascript:void(0);" autocomplete="off"><input id="modal-text-input" placeholder="URL" type="text"></input><input type="submit" id='dailymotion-close' value="Stop"></input><input type="submit" value="Submit" id='searchdailymotion'></input></form>`;
- document.querySelector("#modal-text-input").focus();
- document.getElementById('modal-exit').classList.add("visible");
- },
- 19: () => { // Room Options
- document.querySelector("#modal > #title > p").innerHTML = `Room Options`;
- document.querySelector("#modal > span").innerHTML = `
- <p>Room Topic:</p>
- <br><br>
- <form action="javascript:void(0);" autocomplete="off">
- <input id="room-topic" placeholder="Topic" type="text"></input>
- <input type="submit" value="Set" id='changeroomtopic' style="width:54px;"></input>
- </form>
- <hr>
- <p>Broadcast Password:</p>
- <br><br>
- <form action="javascript:void(0);" autocomplete="off">
- <input id="broadcast-password" placeholder="Password" autocomplete="off"></input>
- <input type="submit" id='broadcast-password-clear' value="Clear" style="width:44px;">
- <input type="submit" id='changebroadcastpassword' value="Set" style="width:54px;"></input>
- </form>`;
- if (StumbleChat.Self.mod >= 4) document.querySelector("#modal > span").innerHTML += `
- <hr><div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Room.guests_allowed == true) ? `checked` : ``}>
- <span id="guestsallowed" class="slider round"></span>
- </label>
- <h2>Guests:</h2>
- </div>
- <h3>Allow unregistered users to enter the room.</h3>
- <hr>
- <div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Room.public == true) ? `checked` : ``}>
- <span id="publicroom" class="slider round"></span>
- </label>
- <h2>List room in directory:</h2>
- </div>
- <h3>Be found on our directory page by users browsing the rooms.</h3>`;
- document.querySelector("#modal > span").innerHTML += `
- <hr><div class="optionside">
- <label class="switch">
- <input type="checkbox" ${(StumbleChat.Room.greenroom == true) ? `checked` : ``}>
- <span id="greenroom" class="slider round"></span>
- </label>
- <h2>Greenroom:</h2>
- </div>
- <h3>Enable a waiting area where you can moderate and choose who can broadcast.</h3>`;
- document.getElementById('modal-exit').classList.add("visible");
- },
- 20: () => { // Permission Check
- document.querySelector("#modal > #title > p").innerHTML = `GATHERING PERMISSIONS`;
- document.querySelector("#modal > span").innerHTML = `Some devices for video to automatically play, the user must accept the prompt requesting camera access.`;
- },
- 21: () => { // Permission Failed
- document.querySelector("#modal > #title > p").innerHTML = `MISSING PERMISSIONS`;
- document.querySelector("#modal > span").innerHTML = `Some devices for video to automatically play, the user must accept the prompt requesting camera access.`;
- },
- }
- };
- let Media = {
- YouTube: {
- Add: () => {
- let VideoID = document.getElementById("modal-text-input").value.match(/(?:www\.|https:\/\/)?(?:www\.|m\.)?youtu(?:be\.com\/v\/|be\.com\/watch\?v\=|\/v\=|be\.com\/embed\/|\.be\/)([A-Za-z0-9_\-]{11})(?:\?t=([0-9]{1,6}))?/i);
- if (VideoID !== null) {
- if (VideoID[ 1 ] !== undefined) {
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "youtube",
- "type": "add",
- "id": VideoID[ 1 ],
- "time": (VideoID[ 2 ] !== undefined) ? VideoID[ 2 ] : 0
- }));
- Modal.Destroy();
- }
- } else {
- let keywordsearch = document.getElementById("modal-text-input").value;
- if (keywordsearch !== "") {
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "youtube",
- "type": "add",
- "id": keywordsearch,
- "time": 0
- }));
- Modal.Destroy();
- }
- }
- },
- Stop: (text) => {
- if (window.YouTubePlayer !== undefined) window.YouTubePlayer.stopVideo();
- if (text != undefined) Message.receive.public(text);
- document.querySelector("#videos > div > .youtube").classList.add("hidden");
- StumbleChat.Videos.Update();
- if (StumbleChat.Chat.Status.AdjustingQueue) setTimeout(() => StumbleChat.WebSocket.send(`{"stumble": "youtube","type": "playlist"}`), 500);
- },
- Ready: (event) => {
- let b = setInterval(() => StumbleChat.Videos.Update(), 4);
- event.target.playVideo();
- document.querySelector("#youtube-volume-slider").classList.remove("hidden");
- StumbleChat.Videos.Update();
- setTimeout(() => clearInterval(b), 800);
- },
- onPlayerStateChange: (event) => {
- let b = setInterval(() => StumbleChat.Videos.Update(), 4);
- if (event.data == -1) {
- StumbleChat.Chat.Settings.YouTubePausedTime = new Date();
- StumbleChat.Chat.Settings.YouTubeClicked = false;
- }
- if (event.data == 1 && !StumbleChat.Chat.Settings.YouTubeClicked) {
- window.YouTubePlayer.seekTo(StumbleChat.Chat.Settings.YouTubeStartTime + (Math.floor((new Date() - StumbleChat.Chat.Settings.YouTubePausedTime) / 1000)));
- StumbleChat.Chat.Settings.YouTubeClicked = true;
- }
- setTimeout(() => clearInterval(b), 800);
- }
- },
- Twitch: {
- Add: () => {
- let Channel = document.getElementById("modal-text-input").value;
- if (Channel.match(/^[a-zA-Z0-9_]{3,24}$/i) !== null) {
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "twitch",
- "type": "play",
- "name": Channel
- }));
- Modal.Destroy();
- }
- },
- Stop: () => {
- if (StumbleChat.Chat.Status.Playing.Twitch) {
- document.querySelector("#videos > div > .twitch").classList.add("hidden");
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "twitch",
- "type": "stop"
- }));
- StumbleChat.Videos.Update();
- }
- }
- },
- WSHH: {
- Add: () => {
- let URL = document.getElementById("modal-text-input").value;
- if (URL.match(/^(?:https:\/\/(?:worldstarhiphop|worldstar)\.com\/videos\/)([a-z0-9]{20})/i) !== null) {
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "wshh",
- "type": "play",
- "url": URL
- }));
- Modal.Destroy();
- }
- },
- Stop: () => {
- if (StumbleChat.Chat.Status.Playing.WSSH) {
- document.querySelector("#videos > div > .worldstarhiphop").classList.add("hidden");
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "wshh",
- "type": "stop"
- }));
- StumbleChat.Videos.Update();
- }
- }
- },
- DailyMotion: {
- Add: () => {
- let URL = document.getElementById("modal-text-input").value;
- if (URL.match(/^(?:(?:http|https):\/\/)?(?:www.)?(dailymotion\.com|dai\.ly)\/((video\/([^_]+))|(hub\/([^_]+)|([^\/_]+)))$/i) !== null) {
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "dailymotion",
- "type": "play",
- "url": URL
- }));
- Modal.Destroy();
- }
- },
- Stop: () => {
- if (StumbleChat.Chat.Status.Playing.DailyMotion) {
- document.querySelector("#videos > div > .dailymotion").classList.add("hidden");
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "dailymotion",
- "type": "stop"
- }));
- StumbleChat.Videos.Update();
- }
- }
- },
- SoundCloud: {
- Add: () => {
- let URL = document.getElementById("modal-text-input").value;
- if (URL.match(/((https:\/\/)|(http:\/\/)|(www.)|(m\.)|(\s))+(soundcloud.com\/)+[a-zA-Z0-9\-\.]+(\/)+[a-zA-Z0-9\-\.]+/i) !== null) {
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "soundcloud",
- "type": "play",
- "url": URL
- }));
- Modal.Destroy();
- }
- },
- Stop: () => {
- if (StumbleChat.Chat.Status.Playing.SoundCloud) {
- document.querySelector("#videos > div > .soundcloud").classList.add("hidden");
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "soundcloud",
- "type": "stop"
- }));
- StumbleChat.Videos.Update();
- }
- }
- }
- };
- window.onload = () => {
- document.getElementById("textarea").disabled = true;
- if (window.innerWidth > 652) {
- document.querySelector(".resizechat").classList.remove("hidden");
- document.querySelector(".resizeuser").classList.remove("hidden");
- StumbleChat.Userlist.Resizable = true;
- StumbleChat.Chat.Resizable = true;
- }
- window.onresize = () => {
- StumbleChat.Userlist.Menu.Hide();
- StumbleChat.Videos.Menu.Hide();
- StumbleChat.Userlist.Resize();
- StumbleChat.Chat.Resize();
- Modal.Center();
- StumbleChat.Videos.Update();
- };
- if (!CheckCompatibility.WebSocket() || !CheckCompatibility.Device()) return Modal.Create(1);
- if (CheckCompatibility.Storage()) StumbleChat.Chat.Settings.SaveEnabled = true;
- StumbleChat.Userlist.Resize();
- StumbleChat.Chat.Settings.RoomVolume = parseStorage('RoomVolume', 100);
- StumbleChat.Chat.Sounds.public_message.volume = (StumbleChat.Chat.Settings.RoomVolume / 100);
- StumbleChat.Chat.Sounds.private_message.volume = (StumbleChat.Chat.Settings.RoomVolume / 100);
- StumbleChat.Chat.Settings.isMobile = CheckCompatibility.MouseSupport("touchend");
- document.addEventListener("contextmenu", (e) => {
- if (e.target.id == "userlist" || e.target.id == "embeddedvideos" || e.target.id == "videos" || e.target.id == "regularvideos ") e.preventDefault();
- });
- document.querySelector(".RoomVolume").setAttribute("value", StumbleChat.Chat.Settings.RoomVolume);
- StumbleChat.Userlist.Menu.Element = document.querySelector("#user-menu");
- StumbleChat.Userlist.Menu.State = 0;
- StumbleChat.Videos.Menu.Element = document.querySelector("#video-menu");
- StumbleChat.Videos.Menu.State = 0;
- document.getElementById("textarea").addEventListener("keypress", Message.send, { passive: false });
- window.addEventListener("keypress", (event) => {
- if (event.defaultPrevented) return;
- if (event.key == "Enter" || event.code == "Enter") {
- switch (StumbleChat.Chat.Status.ModalOpened) {
- case 0:
- saveBroadcast();
- break;
- case 5:
- App.ChangeNick();
- break;
- case 6:
- Modal.Destroy();
- StumbleChat.Videos.Password = document.querySelector("#modal-text-input").value;
- if (document.querySelector("#modal-text-hidden").value == 0) {
- requestBroadcast(StumbleChat.Videos.Password);
- } else if (document.querySelector("#modal-text-hidden").value == 1) {
- requestScreenshare(StumbleChat.Videos.Password);
- }
- break;
- case 7:
- Media.YouTube.Add();
- break;
- case 9:
- case 10:
- case 11:
- case 13:
- Modal.Destroy();
- break;
- case 12:
- Media.Twitch.Add();
- break;
- case 15:
- StumbleChat.Chat.Password = document.querySelector("#modal-text-input").value;
- App.Auth(document.querySelector("#modal-text-input").value);
- break;
- case 16:
- Media.WSHH.Add();
- break;
- case 17:
- Media.SoundCloud.Add();
- break;
- case 18:
- Media.DailyMotion.Add();
- break;
- }
- if (StumbleChat.Chat.Status.ModalOpened > -1) event.preventDefault();
- }
- }, { passive: true });
- document.getElementById("chat").addEventListener("scroll", (event) => {
- if (Math.floor(event.target.scrollTop + 50) >= (event.target.scrollHeight - event.target.offsetHeight)) Message.unread(true);
- }, {
- passive: true
- });
- document.getElementById("media-settings").addEventListener("pointerdown", () => Modal.Create(0), {
- passive: true
- });
- document.getElementById("media-broadcast").addEventListener("pointerdown", () => {
- if (StumbleChat.Chat.Settings.videodevice != "NONE" || StumbleChat.Chat.Settings.audiodevice != "NONE") {
- if (StumbleChat.Room.broadcast_password == true) {
- Modal.Create(6, 0);
- } else {
- requestBroadcast(StumbleChat.Videos.Password);
- }
- } else {
- Message.receive.public(`You need to select an audio and/ or video device to use.`);
- Modal.Create(0);
- }
- }, {
- passive: true
- });
- document.getElementById("media-screen").addEventListener("pointerdown", () => {
- if (!StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) {
- if (StumbleChat.Room.broadcast_password == true) {
- Modal.Create(6, 1);
- } else {
- requestScreenshare();
- }
- }
- }, {
- passive: true
- });
- window.addEventListener("pointerdown", (event) => {
- if (event.target.id == "media-ptt") {
- if (StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) {
- if (StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).audio !== undefined) {
- event.target.innerText = "TALKING...";
- StumbleChat.Videos.AudioPaused = false;
- StumbleChat.Videos.AudioAwaitingPause = true;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).audio.resume();
- }
- }
- }
- }, {
- passive: true
- });
- window.addEventListener("pointerup", (event) => {
- // Audio Control
- event.preventDefault();
- if (!StumbleChat.Videos.AudioPaused && StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle) && StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).audio !== null) muteBroadcast();
- if (event.target.classList.contains("closepm")) {
- let handle = event.target.parentElement.attributes[ "user-id" ].value;
- if (StumbleChat.Chat.Selected === handle) {
- document.querySelector(".unreadmessage").classList.add("hidden");
- StumbleChat.Chat.Selected = 0;
- document.querySelector("#chat-position>#back").classList.remove("show");
- document.getElementById("chat-content").innerHTML = "";
- StumbleChat.Chat.Messages.get(0).forEach((value, index) => {
- if (index > 0) {
- if (StumbleChat.Chat.Messages.get(0)[ index - 1 ].username == value.username && value.username != undefined && value.nick == StumbleChat.Chat.Messages.get(0)[ index - 1 ].nick) {
- let element = document.createElement("div");
- element.setAttribute("class", "content");
- element.innerHTML = `<span class="hidden-selectable">[ ${value.time} ]</span><span class="timestamp">${value.time}</span><span class="message common" style="color:${value.messagetextcolor}">${value.msg}</span></div> `;
- document.querySelector("#chat-content>.message:last-child").appendChild(element);
- } else {
- createChatItem(value);
- }
- } else {
- createChatItem(value);
- }
- });
- StumbleChat.Chat.Scroll();
- document.querySelector("#textarea").focus();
- }
- event.target.parentElement.parentElement.remove();
- if (document.querySelector(`.privateMessages > div > span`) === null) {
- document.querySelector(`#userlist > h2:nth-child(2)`).classList.add(`hidden`);
- document.querySelector(`#userlist > .privateMessages`).classList.add(`hidden`);
- }
- } else if (event.target.classList.contains("private")) {
- let handle = event.target.attributes[ "user-id" ].value;
- if (StumbleChat.Chat.Selected !== handle) document.querySelector(".unreadmessage").classList.add("hidden");
- StumbleChat.Chat.Selected = handle;
- if (StumbleChat.Chat.Messages.has(handle)) {
- document.querySelector("#chat-position>#back").classList.add("show");
- document.querySelector("#chat-position>#back").innerHTML = `‹ ${StumbleChat.Chat.Messages.get(handle).nick} (${StumbleChat.Chat.Messages.get(handle).username})`;
- document.getElementById("chat-content").innerHTML = "";
- let PM = document.querySelector(`.privateMessages > div > span[ user-id="${handle}"]`);
- if (document.querySelector(`.selected`)) document.querySelector(`.selected`).classList.remove("selected");
- PM.classList.add("selected");
- StumbleChat.Chat.Messages.get(handle).missedmsg = 0;
- PM.querySelector(".unreadpm").innerText = StumbleChat.Chat.Messages.get(handle).missedmsg;
- PM.querySelector(".unreadpm").classList.remove("show");
- StumbleChat.Chat.Messages.get(handle).message.forEach((value, index) => {
- if (index > 0) {
- if (value.nick == StumbleChat.Chat.Messages.get(handle).message[ index - 1 ].nick && value.handle == StumbleChat.Chat.Messages.get(handle).message[ index - 1 ].handle) {
- let element = document.createElement("div");
- element.setAttribute("class", "content");
- element.innerHTML = `<span class="hidden-selectable">[ ${value.time} ]</span><span class="timestamp">${value.time}</span><span class="message common" style="color:${value.messagetextcolor}">${value.msg}</span></div> `;
- document.querySelector("#chat-content>.message:last-child").appendChild(element);
- } else {
- createChatItem(value);
- }
- } else {
- createChatItem(value);
- }
- });
- StumbleChat.Chat.Scroll();
- document.querySelector("#textarea").focus();
- }
- } else if (event.target.id == "back") {
- event.preventDefault();
- let PM = document.querySelector(`.privateMessages > div > span[ user-id="${StumbleChat.Chat.Selected}"]`);
- PM.classList.remove("selected");
- if (StumbleChat.Chat.Messages.get(StumbleChat.Chat.Selected).length == 0) {
- PM.parentElement.remove();
- StumbleChat.Chat.Messages.delete(StumbleChat.Chat.Selected);
- if (StumbleChat.Chat.Messages.size == 1) {
- document.querySelector("#userlist>h2:nth-child(2)").classList.add("hidden");
- PM.classList.add("hidden");
- }
- }
- StumbleChat.Chat.Selected = 0;
- document.querySelector(".unreadmessage").classList.add("hidden");
- document.querySelector("#chat-position>#back").classList.remove("show");
- document.getElementById("chat-content").innerHTML = "";
- StumbleChat.Chat.Messages.get(0).forEach((value, index) => {
- if (index > 0) {
- if (StumbleChat.Chat.Messages.get(0)[ index - 1 ].username == value.username && value.username != undefined && value.nick == StumbleChat.Chat.Messages.get(0)[ index - 1 ].nick) {
- let element = document.createElement("div");
- element.setAttribute("class", "content");
- element.innerHTML = `<span class="hidden-selectable">[ ${value.time} ]</span><span class="timestamp">${value.time}</span><span class="message common" style="color:${value.messagetextcolor}">${value.msg}</span></div> `;
- document.querySelector("#chat-content>.message:last-child").appendChild(element);
- } else {
- createChatItem(value);
- }
- } else {
- createChatItem(value);
- }
- });
- StumbleChat.Chat.Scroll(true);
- document.querySelector("#textarea").focus();
- } else if (event.target.id == "search") {
- Media.YouTube.Add();
- } else if (event.target.id == "broadcastpassword") {
- Modal.Destroy();
- StumbleChat.Videos.Password = document.querySelector("#modal-text-input").value;
- if (document.querySelector("#modal-text-hidden").value == 0) {
- requestBroadcast(StumbleChat.Videos.Password);
- } else if (document.querySelector("#modal-text-hidden").value == 1) {
- requestScreenshare(StumbleChat.Videos.Password);
- }
- } else if (event.target.id == "broadcastsettings") {
- saveBroadcast();
- } else if (event.target.id == "roompassword") {
- StumbleChat.Chat.Password = document.querySelector("#modal-text-input").value;
- App.Auth(document.querySelector("#modal-text-input").value);
- } else if (event.target.id == "resetbackground") {
- StumbleChat.Chat.Background.Reset();
- } else if (event.target.id == "setbackground") {
- StumbleChat.Chat.Background.Set();
- } else if (event.target.id == "resetchatcolor") {
- StumbleChat.Chat.Color.Reset();
- } else if (event.target.id == "setchatcolor") {
- StumbleChat.Chat.Color.Set();
- } else if (event.target.id == "searchtwitch") {
- Media.Twitch.Add();
- } else if (event.target.id == "searchsoundcloud") {
- Media.SoundCloud.Add();
- } else if (event.target.id == "searchdailymotion") {
- Media.DailyMotion.Add();
- } else if (event.target.id == "searchworldstarhiphop") {
- Media.WSHH.Add();
- } else if (event.target.id == "broadcast-password-clear") {
- StumbleChat.Chat.setBroadcastPassword(true);
- } else if (event.target.id == "twitch-close") {
- Media.Twitch.Stop();
- } else if (event.target.id == "soundcloud-close") {
- Media.SoundCloud.Stop();
- } else if (event.target.id == "dailymotion-close") {
- Media.DailyMotion.Stop();
- } else if (event.target.id == "worldstarhiphop-close") {
- Media.WSHH.Stop();
- } else if (event.target.id == "youtube-close-embed") {
- StumbleChat.WebSocket.send(`{"stumble":"youtube","type":"remove","id":${StumbleChat.Chat.Settings.YouTubeQueueID} } `);
- } else if (event.target.id == "changeroomtopic") {
- StumbleChat.Chat.setTopic();
- } else if (event.target.id == "changebroadcastpassword") {
- StumbleChat.Chat.setBroadcastPassword(false);
- } else if (event.target.id == "twitch-close-embed") {
- Media.Twitch.Stop();
- } else if (event.target.id == "soundcloud-close-embed") {
- Media.SoundCloud.Stop();
- } else if (event.target.id == "dailymotion-close-embed") {
- Media.DailyMotion.Stop();
- } else if (event.target.id == "worldstarhiphop-close-embed") {
- Media.WSHH.Stop();
- } else if (event.target.id == "modal-exit") {
- Modal.Destroy();
- } else if (event.target.id == "interact") {
- App.Init();
- } else if (event.target.id == "change-nick") {
- App.ChangeNick();
- } else if (event.target.classList.contains("resizeuser")) {
- document.querySelector("sc-userlist>.resizeuser").classList.toggle("left");
- if (!StumbleChat.Userlist.Resized) {
- document.querySelector("sc-userlist").style = "left:-210px;position:absolute;";
- StumbleChat.Userlist.Resized = true;
- } else {
- document.querySelector("sc-userlist").style = "";
- StumbleChat.Userlist.Resized = false;
- }
- StumbleChat.Videos.Update();
- } else if (event.target.classList.contains("resizechat")) {
- document.querySelector("sc-chat>.resizechat").classList.toggle("right");
- if (!StumbleChat.Chat.Resized) {
- document.querySelector("sc-chat").style = "right:-500px;position:absolute;";
- StumbleChat.Chat.Resized = true;
- } else {
- document.querySelector("sc-chat").style = "";
- StumbleChat.Chat.Resized = false;
- }
- StumbleChat.Videos.Update();
- } else if (event.target.classList.contains("resizetopic")) {
- Modal.Create(13);
- } else if (event.target.classList.contains("slider")) {
- switch (event.target.id) {
- case "youtube":
- if (StumbleChat.Chat.Settings.YouTubeEnabled == true) {
- let elem = document.querySelector("#youtubeplayer");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#videos > div > .youtube").classList.add("hidden");
- StumbleChat.Chat.Settings.YouTubeStartTime = 0;
- StumbleChat.Chat.Settings.YouTubeQueueID = undefined;
- StumbleChat.Chat.Settings.YouTubePausedTime = new Date();
- StumbleChat.Chat.Settings.YouTubeClicked = true;
- window.YouTubePlayer = undefined;
- let newNode = document.createElement("div");
- newNode.setAttribute("id", "youtubeplayer");
- document.querySelector(".youtube>.video>.video-wrapper").prepend(newNode);
- document.querySelector("#youtube-volume-slider").value = 100;
- }
- StumbleChat.Chat.Settings.YouTubeEnabled = !StumbleChat.Chat.Settings.YouTubeEnabled;
- localStorage.setItem('YouTubeEnabled', StumbleChat.Chat.Settings.YouTubeEnabled);
- break;
- case "twitch":
- if (StumbleChat.Chat.Settings.TwitchEnabled == true) {
- let elem = document.querySelector("#twitchplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#videos > div > .twitch").classList.add("hidden");
- }
- StumbleChat.Chat.Settings.TwitchEnabled = !StumbleChat.Chat.Settings.TwitchEnabled;
- localStorage.setItem('TwitchEnabled', StumbleChat.Chat.Settings.TwitchEnabled);
- break;
- case "soundcloud":
- if (StumbleChat.Chat.Settings.SoundCloudEnabled == true) {
- let elem = document.querySelector("#soundcloudplayer>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#videos > div > .soundcloud").classList.add("hidden");
- }
- StumbleChat.Chat.Settings.SoundCloudEnabled = !StumbleChat.Chat.Settings.SoundCloudEnabled;
- localStorage.setItem('SoundCloudEnabled', StumbleChat.Chat.Settings.SoundCloudEnabled);
- break;
- case "dailymotion":
- if (StumbleChat.Chat.Settings.DailyMotionEnabled == true) {
- let elem = document.querySelector("#dailymotion>iframe");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#videos > div > .dailymotion").classList.add("hidden");
- }
- StumbleChat.Chat.Settings.DailyMotionEnabled = !StumbleChat.Chat.Settings.DailyMotionEnabled;
- localStorage.setItem('DailyMotionEnabled', StumbleChat.Chat.Settings.DailyMotionEnabled);
- break;
- case "wshh":
- if (StumbleChat.Chat.Settings.WSHHEnabled == true) {
- let elem = document.querySelector("#worldstarhiphopplayer>video");
- if (elem !== null) elem.parentNode.removeChild(elem);
- document.querySelector("#videos > div > .worldstarhiphop").classList.add("hidden");
- }
- StumbleChat.Chat.Settings.WSHHEnabled = !StumbleChat.Chat.Settings.WSHHEnabled;
- localStorage.setItem('WSHHEnabled', StumbleChat.Chat.Settings.WSHHEnabled);
- break;
- case "largeembeddedvideos":
- if (StumbleChat.Chat.Settings.LargeEmbeddedVideos == false) {
- document.querySelector("#videos").prepend(document.querySelector(`#videos > div:nth-child(2)`));
- } else {
- document.querySelector("#videos").appendChild(document.querySelector(`#videos > div:nth-child(1)`));
- }
- StumbleChat.Videos.Update();
- StumbleChat.Chat.Settings.LargeEmbeddedVideos = !StumbleChat.Chat.Settings.LargeEmbeddedVideos;
- localStorage.setItem('LargeEmbeddedVideos', StumbleChat.Chat.Settings.LargeEmbeddedVideos);
- break;
- case "largefont":
- if (StumbleChat.Chat.Settings.LargeFont == false) {
- document.querySelector("#chat-content").classList.add("large");
- } else {
- document.querySelector("#chat-content").classList.remove("large");
- }
- StumbleChat.Chat.Settings.LargeFont = !StumbleChat.Chat.Settings.LargeFont;
- localStorage.setItem('LargeFont', StumbleChat.Chat.Settings.LargeFont);
- break;
- case "soundmeter":
- StumbleChat.Chat.Settings.SoundmeterEnabled = !StumbleChat.Chat.Settings.SoundmeterEnabled;
- localStorage.setItem('SoundmeterEnabled', StumbleChat.Chat.Settings.SoundmeterEnabled);
- break;
- case "pm":
- StumbleChat.Chat.Settings.PrivateMessageEnabled = !StumbleChat.Chat.Settings.PrivateMessageEnabled;
- localStorage.setItem('PrivateMessageEnabled', StumbleChat.Chat.Settings.PrivateMessageEnabled);
- break;
- case "sounds":
- StumbleChat.Chat.Settings.SoundsEnabled = !StumbleChat.Chat.Settings.SoundsEnabled;
- localStorage.setItem('SoundsEnabled', StumbleChat.Chat.Settings.SoundsEnabled);
- break;
- case "links":
- StumbleChat.Chat.Settings.LinksEnabled = !StumbleChat.Chat.Settings.LinksEnabled;
- localStorage.setItem('LinksEnabled', StumbleChat.Chat.Settings.LinksEnabled);
- break;
- case "imgur":
- StumbleChat.Chat.Settings.ImgurEnabled = !StumbleChat.Chat.Settings.ImgurEnabled;
- localStorage.setItem('ImgurEnabled', StumbleChat.Chat.Settings.ImgurEnabled);
- break;
- case "guestsallowed":
- StumbleChat.Room.guests_allowed = !StumbleChat.Room.guests_allowed;
- StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "room", "type": "guests", "enabled": (StumbleChat.Room.guests_allowed) ? 1 : 0 }));
- break;
- case "publicroom":
- StumbleChat.Room.public = !StumbleChat.Room.public;
- StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "room", "type": "public", "enabled": (StumbleChat.Room.public) ? 1 : 0 }));
- break;
- case "greenroom":
- StumbleChat.Room.greenroom = !StumbleChat.Room.greenroom;
- StumbleChat.WebSocket.send(JSON.stringify({ "stumble": "room", "type": "greenroom", "enabled": (StumbleChat.Room.greenroom) ? 1 : 0 }));
- break;
- }
- StumbleChat.Videos.Update();
- } else if (event.target.parentElement !== null && event.target.parentElement !== undefined) {
- if (event.target.parentElement.classList.contains("banlist")) {
- event.target.parentElement.remove();
- StumbleChat.WebSocket.send(JSON.stringify({
- "stumble": "unban",
- "username": event.target.parentElement.attributes.username.value,
- "id": event.target.parentElement.attributes[ "user-id" ].value
- }));
- } else if (event.target.parentElement.classList.contains("youtubelist")) {
- if (event.target.classList.contains("youtube_title")) return;
- if (event.target.classList.contains("youtube_thumbnail")) return;
- event.target.parentElement.remove();
- StumbleChat.WebSocket.send(`{"stumble":"youtube","type":"remove","id":${event.target.parentElement.id} } `);
- }
- }
- // Close context
- StumbleChat.Userlist.Menu.Task = StumbleChat.GUI.Element.Exists(event, "bar");
- if (!StumbleChat.Userlist.Menu.Task) {
- StumbleChat.Userlist.Menu.Task = null;
- StumbleChat.Userlist.Menu.Hide();
- }
- if (event.target.classList.contains("bar")) StumbleChat.Userlist.Menu.Listen();
- StumbleChat.Videos.Menu.Task = StumbleChat.GUI.Element.Exists(event, "video-wrapper");
- if (!StumbleChat.Videos.Menu.Task) {
- StumbleChat.Videos.Menu.Task = null;
- StumbleChat.Videos.Menu.Hide();
- }
- if (event.target.classList.contains("video-wrapper")) StumbleChat.Videos.Menu.Listen();
- }, {
- passive: false
- });
- window.addEventListener("pointermove", (event) => {
- if (!StumbleChat.Videos.AudioPaused && StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle) && event.target.id !== "media-ptt") {
- if (StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).audio !== null && !StumbleChat.Videos.AudioAwaitingPause) {
- if (!StumbleChat.Chat.Settings.isMobile) window.addEventListener("pointerup", muteBroadcast, {
- passive: true,
- once: true
- });
- }
- }
- }, {
- passive: true
- });
- document.querySelector("sc-videolist").addEventListener("dragstart", (e) => e.preventDefault());
- window.addEventListener("input", (e) => {
- if (e.target.classList.contains("RoomVolume")) {
- StumbleChat.Userlist.Broadcast.forEach((value, key) => {
- if (value.audio !== null && key !== StumbleChat.Self.handle) value.element.volume = (value.volume / 100) * (e.target.value / 100);
- });
- StumbleChat.Chat.Sounds.public_message.volume = (e.target.value / 100);
- StumbleChat.Chat.Sounds.private_message.volume = (e.target.value / 100);
- StumbleChat.Chat.Settings.RoomVolume = e.target.value;
- localStorage.setItem('RoomVolume', e.target.value);
- } else if (e.target.id == "twitch-volume-slider") {
- if (window.TwitchPlayer !== undefined) window.TwitchPlayer.setVolume((e.target.value / 100));
- } else if (e.target.id == "soundcloud-volume-slider") {
- let audio_iframe = document.querySelector('#soundcloudplayer>iframe');
- if (audio_iframe !== null) {
- let widget = window.SC.Widget(audio_iframe);
- widget.setVolume((e.target.value));
- }
- } else if (e.target.id == "youtube-volume-slider") {
- if (window.YouTubePlayer !== undefined) window.YouTubePlayer.setVolume((e.target.value / 100) * 100);
- }
- }, { passive: true });
- window.addEventListener("change", (e) => {
- if (e.target.parentElement.id == "media-openmic") {
- StumbleChat.Videos.OpenMic = e.target.checked;
- if (!StumbleChat.Videos.OpenMic) return muteBroadcast();
- document.querySelector("#media-ptt").innerText = "TALKING...";
- StumbleChat.Videos.AudioPaused = false;
- StumbleChat.Videos.AudioAwaitingPause = true;
- StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).audio.resume();
- } else if (e.target.id == "videoSelect") {
- previewBroadcast(window.videoSelect.value);
- }
- }, { passive: true });
- if (StumbleChat.Chat.Settings.isMobile) {
- document.querySelector("#media-screen").classList.add("hidden");
- window.addEventListener('touchend', e => {
- if (!StumbleChat.Videos.AudioPaused && StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) {
- if (StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).audio !== null && StumbleChat.Videos.AudioAwaitingPause) muteBroadcast();
- }
- }, {
- passive: true
- });
- }
- StumbleChat.Room.name = location.pathname.replace(/[\/]+(room)[\/]{1,}/gi, "").toUpperCase();
- Modal.Create(20);
- navigator.mediaDevices.getUserMedia({ video: true, audio: true }).then((stream) => stream.getTracks().forEach((track) => track.stop())).then(() => Modal.Create(4)).catch((err) => Modal.Create(4));
- };
- function parseStorage (key, defaultval) {
- if (StumbleChat.Chat.Settings.SaveEnabled == true) {
- if (localStorage.getItem(key) === null) localStorage.setItem(key, defaultval);
- try {
- return JSON.parse(localStorage.getItem(key));
- } catch (e) {
- return localStorage.getItem(key);
- }
- }
- return defaultval;
- }
- function loadStorage () {
- // Personal Settings
- StumbleChat.Chat.Settings.IgnoredList = parseStorage('IgnoredList', JSON.stringify([]));
- StumbleChat.Chat.Settings.HideList = parseStorage('HideList', JSON.stringify([]));
- StumbleChat.Chat.Settings.BroadcastVolume = parseStorage('BroadcastVolume', JSON.stringify({}));
- // User Settings
- StumbleChat.Chat.Settings.YouTubeEnabled = parseStorage('YouTubeEnabled', !StumbleChat.Chat.Settings.isMobile);
- StumbleChat.Chat.Settings.TwitchEnabled = parseStorage('TwitchEnabled', !StumbleChat.Chat.Settings.isMobile);
- StumbleChat.Chat.Settings.SoundCloudEnabled = parseStorage('SoundCloudEnabled', !StumbleChat.Chat.Settings.isMobile);
- StumbleChat.Chat.Settings.WSHHEnabled = parseStorage('WSHHEnabled', !StumbleChat.Chat.Settings.isMobile);
- StumbleChat.Chat.Settings.DailyMotionEnabled = parseStorage('DailyMotionEnabled', !StumbleChat.Chat.Settings.isMobile);
- StumbleChat.Chat.Settings.LargeEmbeddedVideos = parseStorage('LargeEmbeddedVideos', false);
- StumbleChat.Chat.Settings.LargeFont = parseStorage('LargeFont', false);
- StumbleChat.Chat.Settings.SoundmeterEnabled = parseStorage('SoundmeterEnabled', true);
- StumbleChat.Chat.Settings.PrivateMessageEnabled = parseStorage('PrivateMessageEnabled', true);
- StumbleChat.Chat.Settings.SoundsEnabled = parseStorage('SoundsEnabled', true);
- StumbleChat.Chat.Settings.LinksEnabled = parseStorage('LinksEnabled', true);
- StumbleChat.Chat.Settings.ImgurEnabled = parseStorage('ImgurEnabled', true);
- // Media Settings
- StumbleChat.Chat.Settings.audiodevice = parseStorage('audiodevice', "NONE");
- StumbleChat.Chat.Settings.videodevice = parseStorage('videodevice', "NONE");
- StumbleChat.Chat.Settings.Resolution = parseStorage('Resolution', 2);
- StumbleChat.Chat.Settings.FrameRate = parseStorage('FrameRate', 30);
- StumbleChat.Chat.Settings.EchoCancellation = parseStorage('EchoCancellation', true);
- StumbleChat.Chat.Settings.AutoGainControl = parseStorage('AutoGainControl', true);
- StumbleChat.Chat.Settings.NoiseSupression = parseStorage('NoiseSupression', true);
- }
- function currentTime () {
- return new Date().toLocaleString("en-US", {
- hour: "numeric",
- minute: "numeric",
- second: "numeric",
- hour12: true
- });
- }
- function parseLink (message) {
- return message.replace(/(?:(?:(?:https?|ftps?):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?/igm, (url) => {
- try {
- return (new URL(url).hostname.includes('xn--')) ? 'URL BLOCKED' : `<a target="_blank" href="${url}">${url}</a>`;
- } catch (e) {
- return `URL BLOCKED`;
- }
- });
- }
- function parseImgur (message) {
- let url = message.match(/https?:\/\/i\.imgur\.com\/[a-zA-Z0-9]*\.(jpeg|jpg|gif|png|mp4)/);
- if (url !== null) message = (url[ 1 ] == "mp4") ? `<center><video width="288px" height="162px" controls><source src="${url[ 0 ]}" type="video/mp4" /></video>\n<a href="${url[ 0 ]}" target="_blank">Direct Link</a></center>` : `<center><img src="${url[ 0 ]}" width="320px" height="240px" />\n<a href="${url[ 0 ]}" target="_blank">Direct Link</a></center>`;
- return message;
- }
- function reloadClient () {
- App.Clear();
- StumbleChat.Videos.Update();
- if (!StumbleChat.Chat.Status.Kicked) {
- Modal.Create(2);
- setTimeout(App.Init, 5000);
- }
- }
- function createChatItem (value) {
- let element = document.createElement("div");
- element.style.background = `${value.backgroundcolor}a3`;
- element.setAttribute("class", "message " + ((value.nick !== undefined) ? (value.avatar == undefined) ? "noavatar" : "common" : "system"));
- element.innerHTML = (value.nick !== undefined) ? ((value.avatar == undefined) ? `` : `<span class="avatar"><img src="${value.avatar}" alt="Avatar"></span>`) + `<span class="nickname" style = "background:${value.namebackgroundcolor}">${value.nick}</span><div class="content"><span class="hidden-selectable">[${value.time}]</span><span class="timestamp">${value.time}</span><span class="message common" style="color:${value.messagetextcolor}">${value.msg}</span>` : `<span class="hidden-selectable" > System Message\n[ ${value.time}]</span><span class="timestamp">${value.time}</span>${value.msg} `;
- document.getElementById("chat-content").appendChild(element);
- }
- function createBroadcastItem (el, deviceId, label) {
- let option = document.createElement('option');
- option.value = deviceId;
- option.innerText = label;
- el.appendChild(option);
- }
- function previewBroadcast (videodeviceId) {
- let Select = document.querySelector("#videoSelect");
- Select.disabled = true;
- let PreviewVideo = document.querySelector("#previewvideo");
- if (PreviewVideo.srcObject != undefined) {
- PreviewVideo.srcObject.getTracks().forEach((track) => track.stop());
- PreviewVideo.classList.add("hidden");
- }
- if (videodeviceId != undefined && videodeviceId != "NONE") {
- navigator.mediaDevices.getUserMedia({ video: { deviceId: { exact: videodeviceId } } }).then((stream) => {
- PreviewVideo.srcObject = stream;
- PreviewVideo.classList.remove("hidden");
- Select.disabled = false;
- PreviewVideo.play();
- }).catch(() => {
- Select.disabled = false;
- });
- } else {
- Select.disabled = false;
- }
- }
- function requestBroadcast (password) {
- StumbleChat.WebSocket.send(`{"stumble":"publish","type":"request","password":"${password}"}`);
- document.getElementById('media-broadcast').classList.add('hidden');
- document.getElementById('media-settings').classList.add('hidden');
- document.getElementById('media-screen').classList.add('hidden');
- document.getElementById('media-loading').classList.remove('hidden');
- document.getElementById('media-stop').classList.remove('hidden');
- document.getElementById('media-stop').classList.remove('no-audio');
- }
- function requestScreenshare (password) {
- navigator.mediaDevices.getDisplayMedia({
- video: {
- width: StumbleChat.Videos.Resolutions[ StumbleChat.Chat.Settings.Resolution ][ 0 ],
- height: StumbleChat.Videos.Resolutions[ StumbleChat.Chat.Settings.Resolution ][ 1 ],
- frameRate: { ideal: StumbleChat.Videos.FrameRate, max: 60 }
- },
- audio: true
- }).then((screen) => {
- localScreen = screen;
- localScreen.addEventListener('inactive', (event) => {
- if (localScreen != undefined) StumbleChat.WebSocket.send(`{"stumble":"publish","type":"close"} `);
- Broadcast.unpublish(StumbleChat.Self.handle);
- });
- requestBroadcast(password);
- }).catch(err => { });
- }
- function createBroadcastElement (handle) {
- let user = StumbleChat.Userlist.User.get(handle);
- if (user == undefined) user = { nick: "" };
- if (!document.querySelector(`#video[video-id= "${handle}"]`)) document.querySelector(`#regularvideos`).insertAdjacentHTML("afterBegin", ` <div class="js-video"><div class="video"><div class="video-wrapper"><video id="video" video-id="${handle}" autoplay playsinline>Your browser does not support the video tag...</video>${(handle == StumbleChat.Self.handle && StumbleChat.Self.directory) ? "<canvas canvas-id='" + handle + "' style='display:none;'></canvas>" : ""}<span class="nickname" title="${user.nick}" style="">${user.nick}</span></div></div></div> `);
- StumbleChat.Videos.Update();
- return {
- video: document.querySelector(`#video[ video-id= "${handle}"]`),
- canvas: (handle == StumbleChat.Self.handle && StumbleChat.Self.directory) ? document.querySelector(`canvas[ canvas-id= "${handle}"]`) : undefined
- };
- }
- function saveBroadcast () {
- if (window.videoSelect != undefined) {
- let PreviewVideo = document.querySelector("#previewvideo");
- if (PreviewVideo.srcObject != undefined) PreviewVideo.srcObject.getTracks().forEach((track) => track.stop());
- let SelectedFrameRate;
- let framerate = document.getElementsByName('framerate');
- for (let i = 0, length = framerate.length; i < length; i++) {
- if (framerate[ i ].checked) {
- SelectedFrameRate = framerate[ i ].value;
- break;
- }
- }
- let SelectedResolution;
- let resolution = document.getElementsByName('resolution');
- for (let i = 0, length = resolution.length; i < length; i++) {
- if (resolution[ i ].checked) {
- SelectedResolution = resolution[ i ].value;
- break;
- }
- }
- StumbleChat.Chat.Settings.audiodevice = window.audioSelect.value;
- localStorage.setItem("audiodevice", window.audioSelect.value);
- StumbleChat.Chat.Settings.videodevice = window.videoSelect.value;
- localStorage.setItem("videodevice", window.videoSelect.value);
- StumbleChat.Chat.Settings.FrameRate = SelectedFrameRate;
- localStorage.setItem('FrameRate', SelectedFrameRate);
- StumbleChat.Chat.Settings.Resolution = SelectedResolution;
- localStorage.setItem('Resolution', SelectedResolution);
- let enhancement = document.getElementsByName('enhancement');
- StumbleChat.Chat.Settings.EchoCancellation = enhancement[ 0 ].checked;
- localStorage.setItem('EchoCancellation', enhancement[ 0 ].checked);
- StumbleChat.Chat.Settings.AutoGainControl = enhancement[ 1 ].checked;
- localStorage.setItem('AutoGainControl', enhancement[ 1 ].checked);
- StumbleChat.Chat.Settings.NoiseSupression = enhancement[ 2 ].checked;
- localStorage.setItem('NoiseSupression', enhancement[ 2 ].checked);
- }
- Modal.Destroy();
- }
- function removeBroadcastElement (handle) {
- StumbleChat.Userlist.Broadcast.delete(handle);
- let uservid = document.querySelector(`#video[video-id="${handle}"]`);
- if (uservid !== null) uservid.parentElement.parentElement.parentElement.parentElement.removeChild(uservid.parentElement.parentElement.parentElement);
- }
- function removeBroadcastBadge (handle) {
- if (document.querySelector(`.bar[user-id="${handle}"]`)) {
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(1)`).classList.add("hidden");
- document.querySelector(`.bar[user-id="${handle}"] .status>div:nth-child(2)`).classList.add("hidden");
- }
- }
- function resetBroadcastState () {
- StumbleChat.Videos.OpenMic = false;
- document.querySelector("#media-openmic>input").checked = false;
- muteBroadcast();
- if (!StumbleChat.Chat.Settings.isMobile) document.querySelector("#media-screen").classList.remove("hidden");
- document.getElementById('media-broadcast').classList.remove('hidden');
- document.getElementById('media-settings').classList.remove('hidden');
- document.getElementById('media-loading').classList.add('hidden');
- document.getElementById('media-ptt').classList.add('hidden');
- document.getElementById('media-openmic').classList.add('hidden');
- document.getElementById('media-stop').classList.add('hidden');
- StumbleChat.Videos.Update();
- }
- function muteBroadcast () {
- if (!StumbleChat.Videos.OpenMic) {
- StumbleChat.Videos.AudioPaused = true;
- StumbleChat.Videos.AudioAwaitingPause = false;
- document.querySelector("#media-ptt").innerText = "TALK";
- if (StumbleChat.Userlist.Broadcast.has(StumbleChat.Self.handle)) StumbleChat.Userlist.Broadcast.get(StumbleChat.Self.handle).audio.pause();
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement