Simulating/Testing Events in Stream Elements

Message Event with Random String as text - onEventReceived

// Function to dispatch a custom message event
    function simulateMessageEvent() {
      
      function generateRandomString(length) {
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let result = '';
    const charactersLength = characters.length;
    for (let i = 0; i < length; i++) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return result;
}

const randomString = generateRandomString(10); // Generates a random string of length 10
      
      const messageEvent = new CustomEvent("onEventReceived", {
        detail: {
          listener: "message",
          event: {
            data: {
              badges: [
                {
                  type: "broadcaster",
                  version: "1",
                  url: "https://static-cdn.jtvnw.net/badges/v1/5527c58c-fb7d-422d-b71b-f309dcb85cc1/3",
                  description: "Broadcaster"
                },
                {
                  type: "subscriber",
                  version: "3012",
                  url: "https://static-cdn.jtvnw.net/badges/v1/4093de28-b3d9-4b4c-9f9c-74fc9391746b/3",
                  description: "1-Year Subscriber"
                },
                {
                  type: "premium",
                  version: "1",
                  url: "https://static-cdn.jtvnw.net/badges/v1/bbbe0db0-a598-423e-86d0-f9fb98ca1933/3",
                  description: "Prime Gaming"
                }
              ],
              displayName: "flygOn_LiTe",
              text: `${randomString}`,
              emotes: [
                {
                  type: "twitch",
                  name: "NotLikeThis",
                  id: "58765",
                  gif: false,
                  animated: false,
                  urls: {
                    "1": "https://static-cdn.jtvnw.net/emoticons/v2/58765/static/dark/1.0",
                    "2": "https://static-cdn.jtvnw.net/emoticons/v2/58765/static/dark/2.0",
                    "4": "https://static-cdn.jtvnw.net/emoticons/v2/58765/static/dark/3.0"
                  },
                  start: 13,
                  end: 24
                },
                {
                  type: "twitch",
                  name: "WutFace",
                  id: "28087",
                  gif: false,
                  animated: false,
                  urls: {
                    "1": "https://static-cdn.jtvnw.net/emoticons/v2/28087/static/dark/1.0",
                    "2": "https://static-cdn.jtvnw.net/emoticons/v2/28087/static/dark/2.0",
                    "4": "https://static-cdn.jtvnw.net/emoticons/v2/28087/static/dark/3.0"
                  },
                  start: 25,
                  end: 32
                }
              ]
            }
          }
        }
      });
      console.log('Dispatching simulated message event');
      window.dispatchEvent(messageEvent);
    }

Message Event - onEventReceived

// Function to dispatch a custom message event
    function simulateMessageEvent() {
      const messageEvent = new CustomEvent("onEventReceived", {
        detail: {
          listener: "message",
          event: {
            data: {
              badges: [
                {
                  type: "broadcaster",
                  version: "1",
                  url: "https://static-cdn.jtvnw.net/badges/v1/5527c58c-fb7d-422d-b71b-f309dcb85cc1/3",
                  description: "Broadcaster"
                },
                {
                  type: "subscriber",
                  version: "3012",
                  url: "https://static-cdn.jtvnw.net/badges/v1/4093de28-b3d9-4b4c-9f9c-74fc9391746b/3",
                  description: "1-Year Subscriber"
                },
                {
                  type: "premium",
                  version: "1",
                  url: "https://static-cdn.jtvnw.net/badges/v1/bbbe0db0-a598-423e-86d0-f9fb98ca1933/3",
                  description: "Prime Gaming"
                }
              ],
              displayName: "flygOn_LiTe",
              text: "Hello World! NotLikeThis WutFace",
              emotes: [
                {
                  type: "twitch",
                  name: "NotLikeThis",
                  id: "58765",
                  gif: false,
                  animated: false,
                  urls: {
                    "1": "https://static-cdn.jtvnw.net/emoticons/v2/58765/static/dark/1.0",
                    "2": "https://static-cdn.jtvnw.net/emoticons/v2/58765/static/dark/2.0",
                    "4": "https://static-cdn.jtvnw.net/emoticons/v2/58765/static/dark/3.0"
                  },
                  start: 13,
                  end: 24
                },
                {
                  type: "twitch",
                  name: "WutFace",
                  id: "28087",
                  gif: false,
                  animated: false,
                  urls: {
                    "1": "https://static-cdn.jtvnw.net/emoticons/v2/28087/static/dark/1.0",
                    "2": "https://static-cdn.jtvnw.net/emoticons/v2/28087/static/dark/2.0",
                    "4": "https://static-cdn.jtvnw.net/emoticons/v2/28087/static/dark/3.0"
                  },
                  start: 25,
                  end: 32
                }
              ]
            }
          }
        }
      });
      console.log('Dispatching simulated message event');
      window.dispatchEvent(messageEvent);
    }

Follower Event - onEventReceived

  // Function to dispatch a custom follower event
    function simulateFollowerEvent() {
        const followerEvent = new CustomEvent("onEventReceived", {
            detail: {
                listener: "follower-latest",
                event: {
                    avatar: "https://cdn.streamelements.com/assets/dashboard/my-overlays/overlay-default-preview-2.jpg",
                    displayName: "Andria",
                    providerId: "140296153",
                    name: "andria",
                    _id: "669891a5157ee106ae81bc00",
                    sessionTop: false,
                    type: "follower",
                    originalEventName: "follower-latest"
                }
            }
        });
        console.log('Dispatching simulated follower event');
        window.dispatchEvent(followerEvent);
    }

Follower Event - onSessionUpdate

// Function to dispatch a custom follower event
function simulateFollowerEvent() {
  const randomCount = Math.floor(Math.random() * 100) + 1; // Generate a random count between 1 and 100
  const followerEvent = new CustomEvent("onSessionUpdate", {
    detail: {
      session: {
        data: {
          "follower-total": {
            "count": randomCount // Use random follower count for testing
          }
        }
      }
    }
  });
  console.log('Dispatching simulated follower event with count:', randomCount); // Added logging
  window.dispatchEvent(followerEvent);
}