Skip to content

fjqgx/devicemanager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Browser Device Manager

This is a device management tool for browsers, which supports the acquisition of microphone, camera and screen shared images. Including some external equipment

The PC supports the browser under windows, MacOS, Linux and electron

The mobile terminal supports Android and IOS browser

device manager demo

Install

html

  <script src="./browserdevicemanager.js" ></script>

npm

  npm i browserdevicemanager

Usage

get camera list

  var devicemanager = new BrowserDeviceManager();

  devicemanager.getCameraList().then((list) => {
    for (let i = 0; i < list.length; ++i) {
      console.log("camera label:", list[i].label, "  deviceId:", list[i].deviceId);
    }
  }).catch((err) => {
    console.log(err);
  })

get mic list

  var devicemanager = new BrowserDeviceManager();

  devicemanager.getMicList().then((list) => {
    for (let i = 0; i < list.length; ++i) {
      console.log("camera label:", list[i].label, "  deviceId:", list[i].deviceId);
    }
  }).catch((err) => {
    console.log(err);
  })

get camera

pc

var devicemanager = new BrowserDeviceManager();
devicemanager.getVideoTrack({deviceId: ""}).then((videotrack) => {
  let mediastream = new MediaStream();
  mediastream.addTrack(videotrack);
  video.srcObject = mediastream;  // video is html video element
}).catch((err) => {
  console.log("get video track error:", err);
})

mobile

var devicemanager = new BrowserDeviceManager();
// user is front, environment is back camera
devicemanager.getVideoTrack({facingMode: "user" }).then((videotrack) => {
  let mediastream = new MediaStream();
  mediastream.addTrack(videotrack);
  video.srcObject = mediastream;  // video is html video element
}).catch((err) => {
  console.log("get video track error:", err);
})

get mic

var devicemanager = new BrowserDeviceManager();

devicemanager.geAudioTrack({deviceId: ""}).then((videotrack) => {
  let mediastream = new MediaStream();
  mediastream.addTrack(videotrack);
  audio.srcObject = mediastream;  // audio is html audio element
}).catch((err) => {
  console.log("get audio track error:", err);
})

get screen

var devicemanager = new BrowserDeviceManager();

devicemanager.getScreenTrack().then((mediastream) => {
  video.srcObject = mediastream;  // video is html video element
}).catch((err) => {
  console.log("get screen track error:", err);
})

About

device management of browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published