media-devices 0.5.0-2025-12-14.cc51834 → 0.5.0-2025-12-15.c5ed8d8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i["media-devices"]={}))})(this,function(i){"use strict";function c(){return typeof navigator<"u"&&!!navigator.mediaDevices}function r(){if(!c())throw new Error("The media devices API isn't supported here.");return navigator.mediaDevices}async function f(){return(await r().enumerateDevices()).filter(p).map(h)}function p(e){return e.deviceId!=="default"}function h(e){return{label:e.label||null,kind:e.kind,deviceId:e.deviceId||null,groupId:e.groupId||null}}var o=(e=>(e.VideoInput="videoinput",e.AudioInput="audioinput",e.AudioOutput="audiooutput",e))(o||{});async function g(e){return r().getUserMedia(e)}class m{_knownDevices=[];_gainedScreenAccessOnce=!1;ondevicechange=null;constructor(){c()&&r().addEventListener("devicechange",()=>{this.ondevicechange&&this.enumerateDevices()})}getUserMedia=async n=>{const t=await g(n);return this.enumerateDevices(),t};getDisplayMedia=async n=>{const t=await r().getDisplayMedia(n);return this._gainedScreenAccessOnce||(this._gainedScreenAccessOnce=!0,this.enumerateDevices()),t};enumerateDevices=async()=>{const n=await f();return this._checkForDeviceChanges(n),n};getSupportedConstraints=()=>r().getSupportedConstraints();_checkForDeviceChanges(n){const t=this._knownDevices;this._knownDevices=n;const s=this._calculateDeviceDiff(n,t);s.length&&this.ondevicechange?.({changes:s,devices:n})}_calculateDeviceDiff(n,t){const s=t.slice(),l=[],y=n.filter(d=>{const u=s.findIndex(a=>D(d,a));if(u>-1){const[a]=s.splice(u,1);if(d.label!==a.label){const _={type:"update",newInfo:d,oldInfo:a};l.push(_)}}return u===-1});return[...l,...s.map(d=>({type:"remove",device:d})),...y.map(d=>({type:"add",device:d}))]}}function D(e,n){if(n.deviceId)return e.deviceId===n.deviceId;function t(s){return`${s.kind}:${s.groupId}`}return t(e)===t(n)}var v=(e=>(e.Add="add",e.Remove="remove",e.Update="update",e))(v||{});const I=new m;i.DeviceKind=o,i.OperationType=v,i.default=I,i.supportsMediaDevices=c,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i["media-devices"]={}))})(this,(function(i){"use strict";function c(){return typeof navigator<"u"&&!!navigator.mediaDevices}function r(){if(!c())throw new Error("The media devices API isn't supported here.");return navigator.mediaDevices}async function f(){return(await r().enumerateDevices()).filter(p).map(h)}function p(e){return e.deviceId!=="default"}function h(e){return{label:e.label||null,kind:e.kind,deviceId:e.deviceId||null,groupId:e.groupId||null}}var o=(e=>(e.VideoInput="videoinput",e.AudioInput="audioinput",e.AudioOutput="audiooutput",e))(o||{});async function g(e){return r().getUserMedia(e)}class m{_knownDevices=[];_gainedScreenAccessOnce=!1;ondevicechange=null;constructor(){c()&&r().addEventListener("devicechange",()=>{this.ondevicechange&&this.enumerateDevices()})}getUserMedia=async n=>{const t=await g(n);return this.enumerateDevices(),t};getDisplayMedia=async n=>{const t=await r().getDisplayMedia(n);return this._gainedScreenAccessOnce||(this._gainedScreenAccessOnce=!0,this.enumerateDevices()),t};enumerateDevices=async()=>{const n=await f();return this._checkForDeviceChanges(n),n};getSupportedConstraints=()=>r().getSupportedConstraints();_checkForDeviceChanges(n){const t=this._knownDevices;this._knownDevices=n;const s=this._calculateDeviceDiff(n,t);s.length&&this.ondevicechange?.({changes:s,devices:n})}_calculateDeviceDiff(n,t){const s=t.slice(),l=[],y=n.filter(d=>{const u=s.findIndex(a=>D(d,a));if(u>-1){const[a]=s.splice(u,1);if(d.label!==a.label){const _={type:"update",newInfo:d,oldInfo:a};l.push(_)}}return u===-1});return[...l,...s.map(d=>({type:"remove",device:d})),...y.map(d=>({type:"add",device:d}))]}}function D(e,n){if(n.deviceId)return e.deviceId===n.deviceId;function t(s){return`${s.kind}:${s.groupId}`}return t(e)===t(n)}var v=(e=>(e.Add="add",e.Remove="remove",e.Update="update",e))(v||{});const I=new m;i.DeviceKind=o,i.OperationType=v,i.default=I,i.supportsMediaDevices=c,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "media-devices",
|
|
3
3
|
"description": "Easily manage media devices in the browser.",
|
|
4
|
-
"version": "0.5.0-2025-12-
|
|
4
|
+
"version": "0.5.0-2025-12-15.c5ed8d8",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jesse Gibson <JesseTheGibson@gmail.com>",
|
|
7
7
|
"repository": "github:PsychoLlama/media-devices",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"prettier": "3.7.4",
|
|
55
55
|
"typescript": "5.9.3",
|
|
56
56
|
"typescript-eslint": "^8.38.0",
|
|
57
|
-
"vite": "7.
|
|
57
|
+
"vite": "7.3.0",
|
|
58
58
|
"vite-plugin-dts": "^4.0.0",
|
|
59
59
|
"vitest": "^4.0.0"
|
|
60
60
|
}
|