posted an update —

It's hard to test LiveStreaming in Spark AR

So, we figured out a way to test our code with LiveStreaming methods without actually going live.

Here's what we did

We created a flag for production mode. We set it to false. In this case, LiveStreaming module.

var comments = [];

function generateMockComments3 () {
  return Time.setInterval(() => {
    const commentsTypes = [
      "#BottomLeft",
      "#TopLeft",
      "#CenterLeft",
      "#CenterRight",
      "#BottomRight",
      "#TopRight",
    ];
    const rand = getRandomInt(6);
    comments.push(commentsTypes[rand]);
    Diagnostic.log(commentsTypes[rand]);
  }, 350);
} 

function generateMockComments2 () {
  return Time.setInterval(() => {
    const commentsTypes = [
      "#MoveLeft",
      "#MoveRight",
      "#PowerUp",
      "#PowerDown"
    ];
    const rand = getRandomInt(4);
    comments.push(commentsTypes[rand]);
    Diagnostic.log(commentsTypes[rand]);
  }, 350);
}

function countHash(hash) {
  let count = 0;
  comments.forEach(comment => {
    if (comment == hash) {
      count++;
    }
  });
  return count;
}

var LiveStreaming;
var production = true;
if (!production) {
  LiveStreaming = {};
  LiveStreaming.comments = {};
  LiveStreaming.comments.startHashtagCounter = () => {
    subscribe: delegate => {
      const timeInMilliseconds = 1500;
      const mockNewCommentFromLive = () => {
        delegate({
          "#PowerUp": countHash("#PowerUp"),
          "#PowerDown": countHash("#PowerDown"),
          "#MoveLeft": countHash("#MoveLeft"),
          "#MoveRight": countHash("#MoveRight"),
          "#TopLeft": countHash("#TopLeft"),
          "#TopRight": countHash("#TopRight"),
          "#CenterLeft": countHash("#CenterLeft"),
          ...

        });
      };
      return Time.setInterval(mockNewCommentFromLive, timeInMilliseconds);
    }
  };
} else {
  LiveStreaming = require("LiveStreaming");
}

Log in or sign up for Devpost to join the conversation.