yantene / hinano

1 stars 0 forks source link

メモ #7

Open yantene opened 3 years ago

yantene commented 3 years ago

ページの増やし方

frontend/src/hoge.pug

doctype html
html(lang="ja")
  head
    meta(charset="utf-8")
    title hoge
  body
    h1 hoge
    audio#audio(width="400", height="300", autoplay="1")

frontend/src/hoge.ts

function start () {
  const audio = document.querySelector("#audio");
  if (!(audio instanceof HTMLMediaElement)) throw new Error("#audio is not an HTMLMediaElement")

  navigator.getUserMedia({ video: false, audio: true },
    function (stream) {
      console.log(stream);
      audio.srcObject = stream;
    },
    function (err) {
      console.log(err);
    },
  );
}

window.addEventListener("load", () => {
  start();
});

ftontend/webpack.common.js

module.exports = {
  entry: {
    game: "./src/game.ts",
    webrtc: "./src/hoge.ts",
  },
  ...
plugins: [
  new HtmlWebpackPlugin({
    filename: "hoge.html",
    template: "./src/hoge.pug",
    chunks: ["hoge"],
  }),
  ...