◀ Overview
Microphone access in a browser window (and streamed playback)

A simple script to show how to request access to, then access a microphone device and also play back the audio stream to debug it. A useful starting point for making an experience revolving around microphone access.

import { Behaviour } from "@needle-tools/engine";

export class Microphone extends Behaviour {
  start() {
    this.getLocalStream();
  }

  public el: Element;

  attachStream(stream, el, options) {
    var item;
    var URL = window.URL;
    var element = el;
    var opts = {
      autoplay: true,
      mirror: false,
      muted: false,
      audio: false,
      disableContextMenu: false,
    };

    if (options) {
      for (item in options) {
        opts[item] = options[item];
      }
    }

    if (!element) {
      element = document.createElement(opts.audio ? "audio" : "video");
    } else if (element.tagName.toLowerCase() === "audio") {
      opts.audio = true;
    }

    if (opts.autoplay) element.autoplay = "autoplay";
    if (opts.muted) element.muted = true;
    if (!opts.audio && opts.mirror) {
      ["", "moz", "webkit", "o", "ms"].forEach(function (prefix) {
        var styleName = prefix ? prefix + "Transform" : "transform";
        element.style[styleName] = "scaleX(-1)";
      });
    }

    element.srcObject = stream;
    return element;
  }

  getLocalStream() {
    navigator.mediaDevices
      .getUserMedia({
        video: false,
        audio: true,
      })
      .then((stream) => {
        var doesnotexist = !this.el;
        this.el = this.attachStream(stream, this.el, {
          audio: true,
          autoplay: true,
        });
        if (doesnotexist) document.body.appendChild(this.el);
      })
      .catch((err) => {
        console.log("u got an error:" + err);
      });
  }
}
AR Move/Scale/Rotate Controls for Needle on Mobile

This is live for preview over at https://needle-ar.glitch.me/

I will share a github repository if others are interested in collaborating on this, so far I have just sorted functionality for spawning a product model and a floor plane that is large to move it around on. Scale and Rotate work with two finger touches.

I am hoping to figure out how to show and raycast against AR detected planes over here which will remove the need for a large floor plane to raycast against ⁠Unknown

Public Github Repository: https://github.com/ROBYER1/Needle-AR-Demo