Skip to content

Please add message push for loading state. #8

@albirrkarim

Description

@albirrkarim

Please add message push for loading state. so my app can detect your iframe's current state.

I'm using React

My application read the eventName from your iframe.

 useEffect(() => {
    if (frame.current) {
      window.addEventListener("message", subscribe);
      document.addEventListener("message", subscribe);

      function subscribe(event) {
        const json = parse(event);

        if (json?.source !== "readyplayerme") {
          return;
        }

        // I need more eventName as trigger to my application
        if (json.eventName == "v1.user.updated" || json.eventName == "v1.subscription.created") {
          setShow(true);
        }

        // Susbribe to all events sent from Ready Player Me once frame is ready
        if (json.eventName === "v1.frame.ready") {
          frame.current.contentWindow.postMessage(
            JSON.stringify({
              target: "readyplayerme",
              type: "subscribe",
              eventName: "v1.**"
            }),
            "*"
          );
        }

        // Get avatar GLB URL
        if (json.eventName === "v1.avatar.exported") {
          console.log(`Avatar URL: ${json.data.url}`);
          localStorage.setItem("avatar_url", json.data.url);
          setAvatarURL(json.data.url);
        }

        // Get user id
        if (json.eventName === "v1.user.set") {
          console.log(`User with id ${json.data.id} set: ${JSON.stringify(json)}`);
        }
      }

      function parse(event) {
        try {
          return JSON.parse(event.data);
        } catch (error) {
          return null;
        }
      }
    }
  }, [frame.current]);

While Iframe is loading for the first time.
Please give:

  • first_load_start
  • first_load_end

Screen Shot 2022-06-11 at 16 04 41

While Iframe is loading for avatar object

  • avatar_load_start
  • avatar_load_end

Screen Shot 2022-06-11 at 15 52 16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions