Socket
Socket
Sign inDemoInstall

webrtc-mock

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webrtc-mock - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

47

dist/devicesMock.d.ts

@@ -45,3 +45,3 @@ export declare const VIDEO_KIND: "videoinput";

};
export declare const getDeviceAudioOut: () => {
export declare const getDeviceAudioOut: (index?: number | undefined) => {
deviceId: string;

@@ -58,7 +58,2 @@ groupId: string;

}[];
/**
* getDevicesAudioIn
*
* @returns {Array} devices
*/
export declare const getDevicesAudioIn: () => {

@@ -70,7 +65,8 @@ deviceId: string;

}[];
/**
* getAvailableDevices
*
* @returns {Array} devices
*/
export declare const getDevicesAudioOut: () => {
deviceId: string;
groupId: string;
kind: MediaDeviceKind;
label: string;
}[];
export declare const getAvailableDevices: () => {

@@ -82,25 +78,4 @@ deviceId: string;

}[];
/**
* setUserNotAccessAudioIn
*
* @param {boolean} notAccess - notAccess
*
* @returns {undefined}
*/
export declare const setUserNotAccessVideo: (notAccess: boolean) => void;
/**
* setUserNotAccessAudioIn
*
* @param {boolean} notAccess - notAccess
*
* @returns {undefined}
*/
export declare const setUserNotAccessAudioIn: (notAccess: boolean) => void;
/**
* setUserNotAccessAll
*
* @param {boolean} notAccess - notAccess
*
* @returns {undefined}
*/
export declare const setUserNotAccessAll: (notAccess: boolean) => void;

@@ -110,2 +85,3 @@ export declare const unsetAllRestrictions: () => void;

export declare const setCountAudioInDevicesAvailable: (count?: number) => void;
export declare const setCountAudioOutDevicesAvailable: (count?: number) => void;
export declare const videoDevicesAvailableResolutions: {

@@ -123,9 +99,2 @@ [x: string]: {

}) => boolean;
/**
* get Available Resolution for Video Device
*
* @param {string} deviceId - deviceId
*
* @returns {Array} resolutions
*/
export declare const getAvailableResolution: (deviceId: string) => {

@@ -132,0 +101,0 @@ id: string;

66

dist/devicesMock.js

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getAvailableResolution = exports.hasAvailableResolution = exports.videoDevicesAvailableResolutions = exports.setCountAudioInDevicesAvailable = exports.setCountVideoDevicesAvailable = exports.unsetAllRestrictions = exports.setUserNotAccessAll = exports.setUserNotAccessAudioIn = exports.setUserNotAccessVideo = exports.getAvailableDevices = exports.getDevicesAudioIn = exports.getDevicesVideo = exports.getDeviceAudioOut = exports.getDeviceAudioIn = exports.getDeviceVideo = exports.parseDevice = exports.hasUserNotAccessDevice = exports.DeviceMock = exports.hasPermissionDeniedBySystem = exports.unsetPermissionDeniedBySystem = exports.setPermissionDeniedBySystem = exports.hasNotFoundVideoDevice = exports.unsetNotFoundVideoDevice = exports.setNotFoundVideoDevice = exports.hasBusyVideoDevice = exports.unsetBusyVideoDevice = exports.setBusyVideoDevice = exports.generateDeviceId = exports.AUDIO_OUTPUT_KIND = exports.AUDIO_INPUT_KIND = exports.VIDEO_KIND = void 0;
exports.getAvailableResolution = exports.hasAvailableResolution = exports.videoDevicesAvailableResolutions = exports.setCountAudioOutDevicesAvailable = exports.setCountAudioInDevicesAvailable = exports.setCountVideoDevicesAvailable = exports.unsetAllRestrictions = exports.setUserNotAccessAll = exports.setUserNotAccessAudioIn = exports.setUserNotAccessVideo = exports.getAvailableDevices = exports.getDevicesAudioOut = exports.getDevicesAudioIn = exports.getDevicesVideo = exports.getDeviceAudioOut = exports.getDeviceAudioIn = exports.getDeviceVideo = exports.parseDevice = exports.hasUserNotAccessDevice = exports.DeviceMock = exports.hasPermissionDeniedBySystem = exports.unsetPermissionDeniedBySystem = exports.setPermissionDeniedBySystem = exports.hasNotFoundVideoDevice = exports.unsetNotFoundVideoDevice = exports.setNotFoundVideoDevice = exports.hasBusyVideoDevice = exports.unsetBusyVideoDevice = exports.setBusyVideoDevice = exports.generateDeviceId = exports.AUDIO_OUTPUT_KIND = exports.AUDIO_INPUT_KIND = exports.VIDEO_KIND = void 0;
const resolutionsList_1 = __importDefault(require("./resolutionsList"));

@@ -107,4 +107,4 @@ exports.VIDEO_KIND = 'videoinput';

exports.getDeviceAudioIn = getDeviceAudioIn;
const getDeviceAudioOut = () => {
return (0, exports.parseDevice)(new DeviceMock(exports.AUDIO_OUTPUT_KIND));
const getDeviceAudioOut = (index) => {
return (0, exports.parseDevice)(new DeviceMock(exports.AUDIO_OUTPUT_KIND, index));
};

@@ -128,7 +128,2 @@ exports.getDeviceAudioOut = getDeviceAudioOut;

exports.getDevicesVideo = getDevicesVideo;
/**
* getDevicesAudioIn
*
* @returns {Array} devices
*/
const getDevicesAudioIn = () => {

@@ -150,18 +145,22 @@ const countDevices = global.COUNT_DEVICES_AVAILABLE[exports.AUDIO_INPUT_KIND];

exports.getDevicesAudioIn = getDevicesAudioIn;
/**
* getAvailableDevices
*
* @returns {Array} devices
*/
const getDevicesAudioOut = () => {
const countDevices = global.COUNT_DEVICES_AVAILABLE[exports.AUDIO_OUTPUT_KIND];
switch (countDevices) {
case 0:
return [];
case 1:
return [(0, exports.getDeviceAudioOut)()];
case 2:
return [(0, exports.getDeviceAudioOut)(), (0, exports.getDeviceAudioOut)(2)];
case 3:
return [(0, exports.getDeviceAudioOut)(), (0, exports.getDeviceAudioOut)(2), (0, exports.getDeviceAudioOut)(3)];
default:
return [(0, exports.getDeviceAudioOut)()];
}
};
exports.getDevicesAudioOut = getDevicesAudioOut;
const getAvailableDevices = () => {
return [...(0, exports.getDevicesVideo)(), ...(0, exports.getDevicesAudioIn)(), (0, exports.getDeviceAudioOut)()];
return [...(0, exports.getDevicesVideo)(), ...(0, exports.getDevicesAudioIn)(), ...(0, exports.getDevicesAudioOut)()];
};
exports.getAvailableDevices = getAvailableDevices;
/**
* setUserNotAccessAudioIn
*
* @param {boolean} notAccess - notAccess
*
* @returns {undefined}
*/
const setUserNotAccessVideo = (notAccess) => {

@@ -171,9 +170,2 @@ global.DEVICES_USER_NOT_ACCESS[exports.VIDEO_KIND] = notAccess;

exports.setUserNotAccessVideo = setUserNotAccessVideo;
/**
* setUserNotAccessAudioIn
*
* @param {boolean} notAccess - notAccess
*
* @returns {undefined}
*/
const setUserNotAccessAudioIn = (notAccess) => {

@@ -183,9 +175,2 @@ global.DEVICES_USER_NOT_ACCESS[exports.AUDIO_INPUT_KIND] = notAccess;

exports.setUserNotAccessAudioIn = setUserNotAccessAudioIn;
/**
* setUserNotAccessAll
*
* @param {boolean} notAccess - notAccess
*
* @returns {undefined}
*/
const setUserNotAccessAll = (notAccess) => {

@@ -211,2 +196,6 @@ (0, exports.setUserNotAccessAudioIn)(notAccess);

exports.setCountAudioInDevicesAvailable = setCountAudioInDevicesAvailable;
const setCountAudioOutDevicesAvailable = (count = 1) => {
global.COUNT_DEVICES_AVAILABLE[exports.AUDIO_OUTPUT_KIND] = count;
};
exports.setCountAudioOutDevicesAvailable = setCountAudioOutDevicesAvailable;
const resolutionsWithout1080p = resolutionsList_1.default.filter(({ id }) => {

@@ -238,9 +227,2 @@ return id !== '1080p';

exports.hasAvailableResolution = hasAvailableResolution;
/**
* get Available Resolution for Video Device
*
* @param {string} deviceId - deviceId
*
* @returns {Array} resolutions
*/
const getAvailableResolution = (deviceId) => {

@@ -247,0 +229,0 @@ return exports.videoDevicesAvailableResolutions[deviceId];

@@ -1,2 +0,2 @@

import e from"lodash/flow";import t from"lodash/curryRight";import i from"lodash/map";import o from"lodash/sortBy";import s from"lodash/property";import n from"events-constructor";class d{constructor(e,{id:t="identifier",constraints:i={}}={}){this.contentHint="",this.readyState="live",this.isolated=!1,this.label="",this.muted=!1,this.onended=null,this.onisolationchange=null,this.onmute=null,this.onunmute=null,this.getConstraints=()=>this.constraints,this.stop=()=>{this.readyState="ended"},this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},i)}clone(){throw new Error("Method not implemented.")}getCapabilities(){throw new Error("Method not implemented.")}getSettings(){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}applyConstraints(e){return this.constraints=Object.assign({},e),Promise.resolve()}}const r=e=>new d("audio",e),a=e=>new d("video",e),c=()=>r({id:"fromAudioContext",constraints:{}}),l=()=>a({id:"fromCanvas",constraints:{}}),u=[{id:"CIF",width:352,height:288,aspectRatio:4/3},{id:"360p",width:640,height:360,aspectRatio:16/9},{id:"720p",width:1280,height:720,aspectRatio:16/9},{id:"1080p",width:1920,height:1080,aspectRatio:16/9}],h="videoinput",v=({prefix:e,postfix:t="DeviceId",index:i})=>`${e}${t}${void 0===i?"":i}`;class E{constructor(e,t){this.kind=e,this.deviceId=v({index:t,prefix:e}),this.groupId=`groupId ${e}`,this.label=`label ${e}`}toJSON(){throw new Error("Method not implemented.")}}const p=e=>{const t=e.toLowerCase();let i=!1;return t.includes(h)?i=!0===global.DEVICES_USER_NOT_ACCESS.videoinput:t.includes("audioinput")?i=!0===global.DEVICES_USER_NOT_ACCESS.audioinput:t.includes("audiooutput")&&(i=!0===global.DEVICES_USER_NOT_ACCESS.audiooutput),i},S=e=>Object.assign({},e),g=e=>S(new E(h,e)),I=e=>S(new E("audioinput",e)),_=()=>{switch(global.COUNT_DEVICES_AVAILABLE.videoinput){case 0:return[];case 1:return[g()];case 2:return[g(),g(2)];case 3:return[g(),g(2),g(3)];default:return[g()]}},m=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audioinput){case 0:return[];case 1:return[I()];case 2:return[I(),I(2)];case 3:return[I(),I(2),I(3)];default:return[I()]}},b=()=>[..._(),...m(),S(new E("audiooutput"))],D=e=>{global.DEVICES_USER_NOT_ACCESS.videoinput=e},C=e=>{global.DEVICES_USER_NOT_ACCESS.audioinput=e},f=e=>{C(e),D(e)},N=u.filter((({id:e})=>"1080p"!==e)),O={[v({prefix:h})]:u,[v({prefix:h,index:1})]:u,[v({prefix:h,index:2})]:N};class A{constructor(e,{id:t="identifier",constraints:i={}}={}){this.contentHint="",this.readyState="live",this.isolated=!1,this.label="",this.muted=!1,this.onended=null,this.onisolationchange=null,this.onmute=null,this.onunmute=null,this.getConstraints=()=>this.constraints,this.stop=()=>{this.readyState="ended"},this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},i)}clone(){throw new Error("Method not implemented.")}getCapabilities(){throw new Error("Method not implemented.")}getSettings(){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}applyConstraints(e){return this.constraints=Object.assign({},e),Promise.resolve()}}let V=0;class w{constructor(e=[]){this.active=!0,this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.getTracks=()=>this.tracks,this.getAudioTracks=()=>this.tracks.filter((({kind:e})=>"audio"===e)),this.getVideoTracks=()=>this.tracks.filter((({kind:e})=>"video"===e)),this.addTrack=e=>(this.tracks=[...this.tracks,e],this),this.id=(V+=1,`identifier-${V}`),this.tracks=e}}const y=()=>Promise.resolve(new w([c()])),T=()=>Promise.resolve(new w([l()])),j=(e,t={})=>{const{fromCanvas:i,fromAudioContext:o}=t,s=[];e.audio&&!o&&s.push(r({id:e.audio.deviceId.exact,deviceId:e.audio.deviceId,constraints:e.audio})),e.video&&!i&&s.push(a({id:e.video.deviceId.exact,deviceId:e.video.deviceId,constraints:e.video}));const n=new w(s);return i&&o?n.tracks=[l(),c()]:i?(n.addTrack(l()),delete n.video):o&&n.addTrack(c()),n},U=e=>JSON.parse(JSON.stringify(e)),k=n=>e(U,(e=>o(e,s(n))),t(i)(U)),x=k("id"),M=e=>U(Object.assign(Object.assign({},e),{tracks:x(e.tracks)})),B=e=>{const t=M(e);return delete t.id,t},P=({hasAccessDeviceAudioOutput:e=!1}={})=>b().map((t=>{let i;var o;return i="videoinput"===t.kind?Object.assign({resolutions:p(t.deviceId)?[]:(o=t.deviceId,O[o]),hasAccess:!p(t.deviceId)},t):"audioinput"===t.kind?Object.assign({hasAccess:!p(t.deviceId)},t):e?Object.assign({hasAccess:!0},t):Object.assign({},t),i})),R=["devicechange"];class Y{constructor(){this.getUserMedia=e=>{var t,i;let o,s;if(e&&e.video&&"object"==typeof e.video&&"object"==typeof e.video.deviceId&&!Array.isArray(e.video.deviceId)?o=e.video.deviceId.exact:e&&!0===e.video&&b().find((({kind:e})=>e===h))?(o=null===(t=b().find((({kind:e})=>e===h)))||void 0===t?void 0:t.deviceId,e.video={deviceId:{exact:o}}):e&&!0===e.video&&(e.video={deviceId:{exact:"notAvailableDevice"}}),e&&e.audio&&"object"==typeof e.audio&&"object"==typeof e.audio.deviceId&&!Array.isArray(e.audio.deviceId)?s=e.audio.deviceId.exact:e&&!0===e.audio&&b().find((({kind:e})=>"audioinput"===e))?(s=null===(i=b().find((({kind:e})=>"audioinput"===e)))||void 0===i?void 0:i.deviceId,e.audio={deviceId:{exact:s}}):e&&!0===e.audio&&(e.audio={deviceId:{exact:"notAvailableDevice"}}),o&&"string"==typeof o&&p(o))return Promise.reject(new Error(`Video DeviceId is not available: ${o}`));if(o&&"string"==typeof o&&(n=o,global.DEVICES_BUSY.videoinput.includes(n))){const e=(()=>{const e=new Error("Could not start video source");return e.name="NotReadableError",e})();return Promise.reject(e)}var n;if(o&&"string"==typeof o&&(e=>global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.includes(e))(o)){const e=new Error("Permission denied by system");return Promise.reject(e)}if(o&&"string"==typeof o&&(e=>global.DEVICES_NOT_FOUND.videoinput.includes(e))(o)){const e=(()=>{const e=new Error;return e.name="NotFoundError",e})();return Promise.reject(e)}if(o&&"string"==typeof o&&p(o)){const e=new Error("Permission denied");return Promise.reject(e)}return o&&"string"==typeof o&&"object"==typeof e.video&&"object"==typeof e.video.height&&"object"==typeof e.video.height&&e.video.height&&e.video.height.exact&&!(({deviceId:e,exactHeight:t})=>{const i=O[e];return!i||0!==i.filter((({height:e})=>e===t)).length})({deviceId:o,exactHeight:e.video.height.exact})?Promise.reject(new Error(`Resolution height:${e.video.height.exact} is not available: ${o}`)):s&&"string"==typeof s&&p(s)?Promise.reject(new Error(`Audio DeviceId is not available: ${s}`)):Promise.resolve(j(e))},this.enumerateDevices=()=>new Promise((e=>setTimeout((()=>e(b())),100))),this.addEventListener=(e,t)=>{this._events.on(e,t)},this.removeEventListener=(e,t)=>{this._events.off(e,t)},this.setCountVideoDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.videoinput=e})(e),this._events.trigger("devicechange",void 0)},this.setCountAudioInDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.audioinput=e})(e),this._events.trigger("devicechange",void 0)},this.setBusyVideoDevice=e=>{(e=>{global.DEVICES_BUSY.videoinput.includes(e)||global.DEVICES_BUSY.videoinput.push(e)})(e)},this.setNotFoundVideoDevice=e=>{(e=>{global.DEVICES_NOT_FOUND.videoinput.includes(e)||global.DEVICES_NOT_FOUND.videoinput.push(e)})(e)},this.setPermissionDeniedBySystem=e=>{(e=>{global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.includes(e)||global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.push(e)})(e)},this.setUserNotAccessVideo=(e=!0)=>{D(e)},this.setUserNotAccessAudioIn=(e=!0)=>{C(e)},this.setUserNotAccessAll=(e=!0)=>{f(e)},this.unsetAllRestrictions=()=>{global.DEVICES_BUSY.videoinput=[],global.DEVICES_NOT_FOUND.videoinput=[],global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=[],f(!1)},this.unsetBusyVideoDevice=e=>{(e=>{global.DEVICES_BUSY.videoinput=global.DEVICES_BUSY.videoinput.filter((t=>t!==e))})(e)},this.unsetNotFoundVideoDevice=e=>{(e=>{global.DEVICES_NOT_FOUND.videoinput=global.DEVICES_NOT_FOUND.videoinput.filter((t=>t!==e))})(e)},this.unsetPermissionDeniedBySystem=e=>{(e=>{global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.filter((t=>t!==e))})(e)},this._events=new n(R)}}const L=()=>{global.MediaStream=w,global.navigator.mediaDevices=new Y,global.COUNT_DEVICES_AVAILABLE={[h]:1,audioinput:1,audiooutput:1},global.DEVICES_USER_NOT_ACCESS={[h]:!1,audioinput:!1,audiooutput:!1},global.DEVICES_BUSY={[h]:[]},global.DEVICES_NOT_FOUND={[h]:[]},global.DEVICES_PERMISSION_DENIED_BY_SYSTEM={[h]:[]}};export{w as MediaStreamMock,A as MediaStreamTrackMock,c as createAudioContextAudioMediaStreamTrackMock,r as createAudioMediaStreamTrackMock,l as createCanvasVideoMediaStreamTrackMock,j as createMediaStreamMock,a as createVideoMediaStreamTrackMock,L as doMock,y as getAudioContextMediaStreamMock,b as getAvailableDevices,P as getAvailableDevicesWithResolutions,T as getCanvasMediaStreamMock,M as parseMediaStream,B as parseMediaStreamWithoutId,U as parseObject,x as parseTracks,u as resolutionsList,k as resolveParseArray};
import e from"lodash/flow";import t from"lodash/curryRight";import i from"lodash/map";import o from"lodash/sortBy";import s from"lodash/property";import n from"events-constructor";class d{constructor(e,{id:t="identifier",constraints:i={}}={}){this.contentHint="",this.readyState="live",this.isolated=!1,this.label="",this.muted=!1,this.onended=null,this.onisolationchange=null,this.onmute=null,this.onunmute=null,this.getConstraints=()=>this.constraints,this.stop=()=>{this.readyState="ended"},this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},i)}clone(){throw new Error("Method not implemented.")}getCapabilities(){throw new Error("Method not implemented.")}getSettings(){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}applyConstraints(e){return this.constraints=Object.assign({},e),Promise.resolve()}}const r=e=>new d("audio",e),a=e=>new d("video",e),c=()=>r({id:"fromAudioContext",constraints:{}}),l=()=>a({id:"fromCanvas",constraints:{}}),u=[{id:"CIF",width:352,height:288,aspectRatio:4/3},{id:"360p",width:640,height:360,aspectRatio:16/9},{id:"720p",width:1280,height:720,aspectRatio:16/9},{id:"1080p",width:1920,height:1080,aspectRatio:16/9}],h="videoinput",v=({prefix:e,postfix:t="DeviceId",index:i})=>`${e}${t}${void 0===i?"":i}`;class E{constructor(e,t){this.kind=e,this.deviceId=v({index:t,prefix:e}),this.groupId=`groupId ${e}`,this.label=`label ${e}`}toJSON(){throw new Error("Method not implemented.")}}const p=e=>{const t=e.toLowerCase();let i=!1;return t.includes(h)?i=!0===global.DEVICES_USER_NOT_ACCESS.videoinput:t.includes("audioinput")?i=!0===global.DEVICES_USER_NOT_ACCESS.audioinput:t.includes("audiooutput")&&(i=!0===global.DEVICES_USER_NOT_ACCESS.audiooutput),i},S=e=>Object.assign({},e),g=e=>S(new E(h,e)),I=e=>S(new E("audioinput",e)),_=e=>S(new E("audiooutput",e)),b=()=>{switch(global.COUNT_DEVICES_AVAILABLE.videoinput){case 0:return[];case 1:return[g()];case 2:return[g(),g(2)];case 3:return[g(),g(2),g(3)];default:return[g()]}},m=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audioinput){case 0:return[];case 1:return[I()];case 2:return[I(),I(2)];case 3:return[I(),I(2),I(3)];default:return[I()]}},D=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audiooutput){case 0:return[];case 1:return[_()];case 2:return[_(),_(2)];case 3:return[_(),_(2),_(3)];default:return[_()]}},C=()=>[...b(),...m(),...D()],f=e=>{global.DEVICES_USER_NOT_ACCESS.videoinput=e},A=e=>{global.DEVICES_USER_NOT_ACCESS.audioinput=e},N=e=>{A(e),f(e)},O=u.filter((({id:e})=>"1080p"!==e)),V={[v({prefix:h})]:u,[v({prefix:h,index:1})]:u,[v({prefix:h,index:2})]:O};class w{constructor(e,{id:t="identifier",constraints:i={}}={}){this.contentHint="",this.readyState="live",this.isolated=!1,this.label="",this.muted=!1,this.onended=null,this.onisolationchange=null,this.onmute=null,this.onunmute=null,this.getConstraints=()=>this.constraints,this.stop=()=>{this.readyState="ended"},this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},i)}clone(){throw new Error("Method not implemented.")}getCapabilities(){throw new Error("Method not implemented.")}getSettings(){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}applyConstraints(e){return this.constraints=Object.assign({},e),Promise.resolve()}}let y=0;class T{constructor(e=[]){this.active=!0,this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.getTracks=()=>this.tracks,this.getAudioTracks=()=>this.tracks.filter((({kind:e})=>"audio"===e)),this.getVideoTracks=()=>this.tracks.filter((({kind:e})=>"video"===e)),this.addTrack=e=>(this.tracks=[...this.tracks,e],this),this.id=(y+=1,`identifier-${y}`),this.tracks=e}}const j=()=>Promise.resolve(new T([c()])),U=()=>Promise.resolve(new T([l()])),k=(e,t={})=>{const{fromCanvas:i,fromAudioContext:o}=t,s=[];e.audio&&!o&&s.push(r({id:e.audio.deviceId.exact,deviceId:e.audio.deviceId,constraints:e.audio})),e.video&&!i&&s.push(a({id:e.video.deviceId.exact,deviceId:e.video.deviceId,constraints:e.video}));const n=new T(s);return i&&o?n.tracks=[l(),c()]:i?(n.addTrack(l()),delete n.video):o&&n.addTrack(c()),n},x=e=>JSON.parse(JSON.stringify(e)),B=n=>e(x,(e=>o(e,s(n))),t(i)(x)),M=B("id"),P=e=>x(Object.assign(Object.assign({},e),{tracks:M(e.tracks)})),L=e=>{const t=P(e);return delete t.id,t},R=({hasAccessDeviceAudioOutput:e=!1}={})=>C().map((t=>{let i;var o;return i="videoinput"===t.kind?Object.assign({resolutions:p(t.deviceId)?[]:(o=t.deviceId,V[o]),hasAccess:!p(t.deviceId)},t):"audioinput"===t.kind?Object.assign({hasAccess:!p(t.deviceId)},t):e?Object.assign({hasAccess:!0},t):Object.assign({},t),i})),Y=["devicechange"];class ${constructor(){this.getUserMedia=e=>{var t,i;let o,s;if(e&&e.video&&"object"==typeof e.video&&"object"==typeof e.video.deviceId&&!Array.isArray(e.video.deviceId)?o=e.video.deviceId.exact:e&&!0===e.video&&C().find((({kind:e})=>e===h))?(o=null===(t=C().find((({kind:e})=>e===h)))||void 0===t?void 0:t.deviceId,e.video={deviceId:{exact:o}}):e&&!0===e.video&&(e.video={deviceId:{exact:"notAvailableDevice"}}),e&&e.audio&&"object"==typeof e.audio&&"object"==typeof e.audio.deviceId&&!Array.isArray(e.audio.deviceId)?s=e.audio.deviceId.exact:e&&!0===e.audio&&C().find((({kind:e})=>"audioinput"===e))?(s=null===(i=C().find((({kind:e})=>"audioinput"===e)))||void 0===i?void 0:i.deviceId,e.audio={deviceId:{exact:s}}):e&&!0===e.audio&&(e.audio={deviceId:{exact:"notAvailableDevice"}}),o&&"string"==typeof o&&p(o))return Promise.reject(new Error(`Video DeviceId is not available: ${o}`));if(o&&"string"==typeof o&&(n=o,global.DEVICES_BUSY.videoinput.includes(n))){const e=(()=>{const e=new Error("Could not start video source");return e.name="NotReadableError",e})();return Promise.reject(e)}var n;if(o&&"string"==typeof o&&(e=>global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.includes(e))(o)){const e=new Error("Permission denied by system");return Promise.reject(e)}if(o&&"string"==typeof o&&(e=>global.DEVICES_NOT_FOUND.videoinput.includes(e))(o)){const e=(()=>{const e=new Error;return e.name="NotFoundError",e})();return Promise.reject(e)}if(o&&"string"==typeof o&&p(o)){const e=new Error("Permission denied");return Promise.reject(e)}return o&&"string"==typeof o&&"object"==typeof e.video&&"object"==typeof e.video.height&&"object"==typeof e.video.height&&e.video.height&&e.video.height.exact&&!(({deviceId:e,exactHeight:t})=>{const i=V[e];return!i||0!==i.filter((({height:e})=>e===t)).length})({deviceId:o,exactHeight:e.video.height.exact})?Promise.reject(new Error(`Resolution height:${e.video.height.exact} is not available: ${o}`)):s&&"string"==typeof s&&p(s)?Promise.reject(new Error(`Audio DeviceId is not available: ${s}`)):Promise.resolve(k(e))},this.enumerateDevices=()=>new Promise((e=>setTimeout((()=>e(C())),100))),this.addEventListener=(e,t)=>{this._events.on(e,t)},this.removeEventListener=(e,t)=>{this._events.off(e,t)},this.setCountVideoDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.videoinput=e})(e),this._events.trigger("devicechange",void 0)},this.setCountAudioInDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.audioinput=e})(e),this._events.trigger("devicechange",void 0)},this.setCountAudioOutDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.audiooutput=e})(e),this._events.trigger("devicechange",void 0)},this.setBusyVideoDevice=e=>{(e=>{global.DEVICES_BUSY.videoinput.includes(e)||global.DEVICES_BUSY.videoinput.push(e)})(e)},this.setNotFoundVideoDevice=e=>{(e=>{global.DEVICES_NOT_FOUND.videoinput.includes(e)||global.DEVICES_NOT_FOUND.videoinput.push(e)})(e)},this.setPermissionDeniedBySystem=e=>{(e=>{global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.includes(e)||global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.push(e)})(e)},this.setUserNotAccessVideo=(e=!0)=>{f(e)},this.setUserNotAccessAudioIn=(e=!0)=>{A(e)},this.setUserNotAccessAll=(e=!0)=>{N(e)},this.unsetAllRestrictions=()=>{global.DEVICES_BUSY.videoinput=[],global.DEVICES_NOT_FOUND.videoinput=[],global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=[],N(!1)},this.unsetBusyVideoDevice=e=>{(e=>{global.DEVICES_BUSY.videoinput=global.DEVICES_BUSY.videoinput.filter((t=>t!==e))})(e)},this.unsetNotFoundVideoDevice=e=>{(e=>{global.DEVICES_NOT_FOUND.videoinput=global.DEVICES_NOT_FOUND.videoinput.filter((t=>t!==e))})(e)},this.unsetPermissionDeniedBySystem=e=>{(e=>{global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.filter((t=>t!==e))})(e)},this._events=new n(Y)}}const F=()=>{global.MediaStream=T,global.navigator.mediaDevices=new $,global.COUNT_DEVICES_AVAILABLE={[h]:1,audioinput:1,audiooutput:1},global.DEVICES_USER_NOT_ACCESS={[h]:!1,audioinput:!1,audiooutput:!1},global.DEVICES_BUSY={[h]:[]},global.DEVICES_NOT_FOUND={[h]:[]},global.DEVICES_PERMISSION_DENIED_BY_SYSTEM={[h]:[]}};export{T as MediaStreamMock,w as MediaStreamTrackMock,c as createAudioContextAudioMediaStreamTrackMock,r as createAudioMediaStreamTrackMock,l as createCanvasVideoMediaStreamTrackMock,k as createMediaStreamMock,a as createVideoMediaStreamTrackMock,F as doMock,j as getAudioContextMediaStreamMock,C as getAvailableDevices,R as getAvailableDevicesWithResolutions,U as getCanvasMediaStreamMock,P as parseMediaStream,L as parseMediaStreamWithoutId,x as parseObject,M as parseTracks,u as resolutionsList,B as resolveParseArray};
//# sourceMappingURL=index.es5.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("lodash/flow"),require("lodash/curryRight"),require("lodash/map"),require("lodash/sortBy"),require("lodash/property"),require("events-constructor")):"function"==typeof define&&define.amd?define(["exports","lodash/flow","lodash/curryRight","lodash/map","lodash/sortBy","lodash/property","events-constructor"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).webrtcMock={},e.flow,e.curryRight,e.map,e.sortBy,e.property,e.Events)}(this,(function(e,t,i,o,s,n,r){"use strict";function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=d(t),c=d(i),l=d(o),u=d(s),h=d(n),v=d(r);class E{constructor(e,{id:t="identifier",constraints:i={}}={}){this.contentHint="",this.readyState="live",this.isolated=!1,this.label="",this.muted=!1,this.onended=null,this.onisolationchange=null,this.onmute=null,this.onunmute=null,this.getConstraints=()=>this.constraints,this.stop=()=>{this.readyState="ended"},this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},i)}clone(){throw new Error("Method not implemented.")}getCapabilities(){throw new Error("Method not implemented.")}getSettings(){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}applyConstraints(e){return this.constraints=Object.assign({},e),Promise.resolve()}}const p=e=>new E("audio",e),S=e=>new E("video",e),g=()=>p({id:"fromAudioContext",constraints:{}}),I=()=>S({id:"fromCanvas",constraints:{}}),_=[{id:"CIF",width:352,height:288,aspectRatio:4/3},{id:"360p",width:640,height:360,aspectRatio:16/9},{id:"720p",width:1280,height:720,aspectRatio:16/9},{id:"1080p",width:1920,height:1080,aspectRatio:16/9}],f="videoinput",b="audioinput",m="audiooutput",D=({prefix:e,postfix:t="DeviceId",index:i})=>`${e}${t}${void 0===i?"":i}`;class C{constructor(e,t){this.kind=e,this.deviceId=D({index:t,prefix:e}),this.groupId=`groupId ${e}`,this.label=`label ${e}`}toJSON(){throw new Error("Method not implemented.")}}const A=e=>{const t=e.toLowerCase();let i=!1;return t.includes(f)?i=!0===global.DEVICES_USER_NOT_ACCESS.videoinput:t.includes(b)?i=!0===global.DEVICES_USER_NOT_ACCESS.audioinput:t.includes(m)&&(i=!0===global.DEVICES_USER_NOT_ACCESS.audiooutput),i},y=e=>Object.assign({},e),N=e=>y(new C(f,e)),O=e=>y(new C(b,e)),M=()=>{switch(global.COUNT_DEVICES_AVAILABLE.videoinput){case 0:return[];case 1:return[N()];case 2:return[N(),N(2)];case 3:return[N(),N(2),N(3)];default:return[N()]}},w=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audioinput){case 0:return[];case 1:return[O()];case 2:return[O(),O(2)];case 3:return[O(),O(2),O(3)];default:return[O()]}},V=()=>[...M(),...w(),y(new C(m))],k=e=>{global.DEVICES_USER_NOT_ACCESS.videoinput=e},T=e=>{global.DEVICES_USER_NOT_ACCESS.audioinput=e},j=e=>{T(e),k(e)},x=_.filter((({id:e})=>"1080p"!==e)),U={[D({prefix:f})]:_,[D({prefix:f,index:1})]:_,[D({prefix:f,index:2})]:x};let B=0;class P{constructor(e=[]){this.active=!0,this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.getTracks=()=>this.tracks,this.getAudioTracks=()=>this.tracks.filter((({kind:e})=>"audio"===e)),this.getVideoTracks=()=>this.tracks.filter((({kind:e})=>"video"===e)),this.addTrack=e=>(this.tracks=[...this.tracks,e],this),this.id=(B+=1,`identifier-${B}`),this.tracks=e}}const R=(e,t={})=>{const{fromCanvas:i,fromAudioContext:o}=t,s=[];e.audio&&!o&&s.push(p({id:e.audio.deviceId.exact,deviceId:e.audio.deviceId,constraints:e.audio})),e.video&&!i&&s.push(S({id:e.video.deviceId.exact,deviceId:e.video.deviceId,constraints:e.video}));const n=new P(s);return i&&o?n.tracks=[I(),g()]:i?(n.addTrack(I()),delete n.video):o&&n.addTrack(g()),n},Y=e=>JSON.parse(JSON.stringify(e)),L=e=>a.default(Y,(t=>u.default(t,h.default(e))),c.default(l.default)(Y)),$=L("id"),F=e=>Y(Object.assign(Object.assign({},e),{tracks:$(e.tracks)})),q="devicechange",H=[q];class J{constructor(){this.getUserMedia=e=>{var t,i;let o,s;if(e&&e.video&&"object"==typeof e.video&&"object"==typeof e.video.deviceId&&!Array.isArray(e.video.deviceId)?o=e.video.deviceId.exact:e&&!0===e.video&&V().find((({kind:e})=>e===f))?(o=null===(t=V().find((({kind:e})=>e===f)))||void 0===t?void 0:t.deviceId,e.video={deviceId:{exact:o}}):e&&!0===e.video&&(e.video={deviceId:{exact:"notAvailableDevice"}}),e&&e.audio&&"object"==typeof e.audio&&"object"==typeof e.audio.deviceId&&!Array.isArray(e.audio.deviceId)?s=e.audio.deviceId.exact:e&&!0===e.audio&&V().find((({kind:e})=>e===b))?(s=null===(i=V().find((({kind:e})=>e===b)))||void 0===i?void 0:i.deviceId,e.audio={deviceId:{exact:s}}):e&&!0===e.audio&&(e.audio={deviceId:{exact:"notAvailableDevice"}}),o&&"string"==typeof o&&A(o))return Promise.reject(new Error(`Video DeviceId is not available: ${o}`));if(o&&"string"==typeof o&&(n=o,global.DEVICES_BUSY.videoinput.includes(n))){const e=(()=>{const e=new Error("Could not start video source");return e.name="NotReadableError",e})();return Promise.reject(e)}var n;if(o&&"string"==typeof o&&(e=>global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.includes(e))(o)){const e=new Error("Permission denied by system");return Promise.reject(e)}if(o&&"string"==typeof o&&(e=>global.DEVICES_NOT_FOUND.videoinput.includes(e))(o)){const e=(()=>{const e=new Error;return e.name="NotFoundError",e})();return Promise.reject(e)}if(o&&"string"==typeof o&&A(o)){const e=new Error("Permission denied");return Promise.reject(e)}return o&&"string"==typeof o&&"object"==typeof e.video&&"object"==typeof e.video.height&&"object"==typeof e.video.height&&e.video.height&&e.video.height.exact&&!(({deviceId:e,exactHeight:t})=>{const i=U[e];return!i||0!==i.filter((({height:e})=>e===t)).length})({deviceId:o,exactHeight:e.video.height.exact})?Promise.reject(new Error(`Resolution height:${e.video.height.exact} is not available: ${o}`)):s&&"string"==typeof s&&A(s)?Promise.reject(new Error(`Audio DeviceId is not available: ${s}`)):Promise.resolve(R(e))},this.enumerateDevices=()=>new Promise((e=>setTimeout((()=>e(V())),100))),this.addEventListener=(e,t)=>{this._events.on(e,t)},this.removeEventListener=(e,t)=>{this._events.off(e,t)},this.setCountVideoDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.videoinput=e})(e),this._events.trigger(q,void 0)},this.setCountAudioInDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.audioinput=e})(e),this._events.trigger(q,void 0)},this.setBusyVideoDevice=e=>{(e=>{global.DEVICES_BUSY.videoinput.includes(e)||global.DEVICES_BUSY.videoinput.push(e)})(e)},this.setNotFoundVideoDevice=e=>{(e=>{global.DEVICES_NOT_FOUND.videoinput.includes(e)||global.DEVICES_NOT_FOUND.videoinput.push(e)})(e)},this.setPermissionDeniedBySystem=e=>{(e=>{global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.includes(e)||global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.push(e)})(e)},this.setUserNotAccessVideo=(e=!0)=>{k(e)},this.setUserNotAccessAudioIn=(e=!0)=>{T(e)},this.setUserNotAccessAll=(e=!0)=>{j(e)},this.unsetAllRestrictions=()=>{global.DEVICES_BUSY.videoinput=[],global.DEVICES_NOT_FOUND.videoinput=[],global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=[],j(!1)},this.unsetBusyVideoDevice=e=>{(e=>{global.DEVICES_BUSY.videoinput=global.DEVICES_BUSY.videoinput.filter((t=>t!==e))})(e)},this.unsetNotFoundVideoDevice=e=>{(e=>{global.DEVICES_NOT_FOUND.videoinput=global.DEVICES_NOT_FOUND.videoinput.filter((t=>t!==e))})(e)},this.unsetPermissionDeniedBySystem=e=>{(e=>{global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.filter((t=>t!==e))})(e)},this._events=new v.default(H)}}e.MediaStreamMock=P,e.MediaStreamTrackMock=class{constructor(e,{id:t="identifier",constraints:i={}}={}){this.contentHint="",this.readyState="live",this.isolated=!1,this.label="",this.muted=!1,this.onended=null,this.onisolationchange=null,this.onmute=null,this.onunmute=null,this.getConstraints=()=>this.constraints,this.stop=()=>{this.readyState="ended"},this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},i)}clone(){throw new Error("Method not implemented.")}getCapabilities(){throw new Error("Method not implemented.")}getSettings(){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}applyConstraints(e){return this.constraints=Object.assign({},e),Promise.resolve()}},e.createAudioContextAudioMediaStreamTrackMock=g,e.createAudioMediaStreamTrackMock=p,e.createCanvasVideoMediaStreamTrackMock=I,e.createMediaStreamMock=R,e.createVideoMediaStreamTrackMock=S,e.doMock=()=>{global.MediaStream=P,global.navigator.mediaDevices=new J,global.COUNT_DEVICES_AVAILABLE={[f]:1,[b]:1,[m]:1},global.DEVICES_USER_NOT_ACCESS={[f]:!1,[b]:!1,[m]:!1},global.DEVICES_BUSY={[f]:[]},global.DEVICES_NOT_FOUND={[f]:[]},global.DEVICES_PERMISSION_DENIED_BY_SYSTEM={[f]:[]}},e.getAudioContextMediaStreamMock=()=>Promise.resolve(new P([g()])),e.getAvailableDevices=V,e.getAvailableDevicesWithResolutions=({hasAccessDeviceAudioOutput:e=!1}={})=>V().map((t=>{let i;var o;return i="videoinput"===t.kind?Object.assign({resolutions:A(t.deviceId)?[]:(o=t.deviceId,U[o]),hasAccess:!A(t.deviceId)},t):"audioinput"===t.kind?Object.assign({hasAccess:!A(t.deviceId)},t):e?Object.assign({hasAccess:!0},t):Object.assign({},t),i})),e.getCanvasMediaStreamMock=()=>Promise.resolve(new P([I()])),e.parseMediaStream=F,e.parseMediaStreamWithoutId=e=>{const t=F(e);return delete t.id,t},e.parseObject=Y,e.parseTracks=$,e.resolutionsList=_,e.resolveParseArray=L,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("lodash/flow"),require("lodash/curryRight"),require("lodash/map"),require("lodash/sortBy"),require("lodash/property"),require("events-constructor")):"function"==typeof define&&define.amd?define(["exports","lodash/flow","lodash/curryRight","lodash/map","lodash/sortBy","lodash/property","events-constructor"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).webrtcMock={},e.flow,e.curryRight,e.map,e.sortBy,e.property,e.Events)}(this,(function(e,t,i,o,s,n,r){"use strict";function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=d(t),c=d(i),l=d(o),u=d(s),h=d(n),v=d(r);class E{constructor(e,{id:t="identifier",constraints:i={}}={}){this.contentHint="",this.readyState="live",this.isolated=!1,this.label="",this.muted=!1,this.onended=null,this.onisolationchange=null,this.onmute=null,this.onunmute=null,this.getConstraints=()=>this.constraints,this.stop=()=>{this.readyState="ended"},this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},i)}clone(){throw new Error("Method not implemented.")}getCapabilities(){throw new Error("Method not implemented.")}getSettings(){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}applyConstraints(e){return this.constraints=Object.assign({},e),Promise.resolve()}}const p=e=>new E("audio",e),S=e=>new E("video",e),g=()=>p({id:"fromAudioContext",constraints:{}}),I=()=>S({id:"fromCanvas",constraints:{}}),_=[{id:"CIF",width:352,height:288,aspectRatio:4/3},{id:"360p",width:640,height:360,aspectRatio:16/9},{id:"720p",width:1280,height:720,aspectRatio:16/9},{id:"1080p",width:1920,height:1080,aspectRatio:16/9}],f="videoinput",b="audioinput",m="audiooutput",D=({prefix:e,postfix:t="DeviceId",index:i})=>`${e}${t}${void 0===i?"":i}`;class C{constructor(e,t){this.kind=e,this.deviceId=D({index:t,prefix:e}),this.groupId=`groupId ${e}`,this.label=`label ${e}`}toJSON(){throw new Error("Method not implemented.")}}const A=e=>{const t=e.toLowerCase();let i=!1;return t.includes(f)?i=!0===global.DEVICES_USER_NOT_ACCESS.videoinput:t.includes(b)?i=!0===global.DEVICES_USER_NOT_ACCESS.audioinput:t.includes(m)&&(i=!0===global.DEVICES_USER_NOT_ACCESS.audiooutput),i},O=e=>Object.assign({},e),N=e=>O(new C(f,e)),V=e=>O(new C(b,e)),y=e=>O(new C(m,e)),w=()=>{switch(global.COUNT_DEVICES_AVAILABLE.videoinput){case 0:return[];case 1:return[N()];case 2:return[N(),N(2)];case 3:return[N(),N(2),N(3)];default:return[N()]}},M=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audioinput){case 0:return[];case 1:return[V()];case 2:return[V(),V(2)];case 3:return[V(),V(2),V(3)];default:return[V()]}},k=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audiooutput){case 0:return[];case 1:return[y()];case 2:return[y(),y(2)];case 3:return[y(),y(2),y(3)];default:return[y()]}},T=()=>[...w(),...M(),...k()],j=e=>{global.DEVICES_USER_NOT_ACCESS.videoinput=e},U=e=>{global.DEVICES_USER_NOT_ACCESS.audioinput=e},x=e=>{U(e),j(e)},B=_.filter((({id:e})=>"1080p"!==e)),P={[D({prefix:f})]:_,[D({prefix:f,index:1})]:_,[D({prefix:f,index:2})]:B};let L=0;class R{constructor(e=[]){this.active=!0,this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.getTracks=()=>this.tracks,this.getAudioTracks=()=>this.tracks.filter((({kind:e})=>"audio"===e)),this.getVideoTracks=()=>this.tracks.filter((({kind:e})=>"video"===e)),this.addTrack=e=>(this.tracks=[...this.tracks,e],this),this.id=(L+=1,`identifier-${L}`),this.tracks=e}}const Y=(e,t={})=>{const{fromCanvas:i,fromAudioContext:o}=t,s=[];e.audio&&!o&&s.push(p({id:e.audio.deviceId.exact,deviceId:e.audio.deviceId,constraints:e.audio})),e.video&&!i&&s.push(S({id:e.video.deviceId.exact,deviceId:e.video.deviceId,constraints:e.video}));const n=new R(s);return i&&o?n.tracks=[I(),g()]:i?(n.addTrack(I()),delete n.video):o&&n.addTrack(g()),n},$=e=>JSON.parse(JSON.stringify(e)),F=e=>a.default($,(t=>u.default(t,h.default(e))),c.default(l.default)($)),q=F("id"),H=e=>$(Object.assign(Object.assign({},e),{tracks:q(e.tracks)})),J="devicechange",W=[J];class z{constructor(){this.getUserMedia=e=>{var t,i;let o,s;if(e&&e.video&&"object"==typeof e.video&&"object"==typeof e.video.deviceId&&!Array.isArray(e.video.deviceId)?o=e.video.deviceId.exact:e&&!0===e.video&&T().find((({kind:e})=>e===f))?(o=null===(t=T().find((({kind:e})=>e===f)))||void 0===t?void 0:t.deviceId,e.video={deviceId:{exact:o}}):e&&!0===e.video&&(e.video={deviceId:{exact:"notAvailableDevice"}}),e&&e.audio&&"object"==typeof e.audio&&"object"==typeof e.audio.deviceId&&!Array.isArray(e.audio.deviceId)?s=e.audio.deviceId.exact:e&&!0===e.audio&&T().find((({kind:e})=>e===b))?(s=null===(i=T().find((({kind:e})=>e===b)))||void 0===i?void 0:i.deviceId,e.audio={deviceId:{exact:s}}):e&&!0===e.audio&&(e.audio={deviceId:{exact:"notAvailableDevice"}}),o&&"string"==typeof o&&A(o))return Promise.reject(new Error(`Video DeviceId is not available: ${o}`));if(o&&"string"==typeof o&&(n=o,global.DEVICES_BUSY.videoinput.includes(n))){const e=(()=>{const e=new Error("Could not start video source");return e.name="NotReadableError",e})();return Promise.reject(e)}var n;if(o&&"string"==typeof o&&(e=>global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.includes(e))(o)){const e=new Error("Permission denied by system");return Promise.reject(e)}if(o&&"string"==typeof o&&(e=>global.DEVICES_NOT_FOUND.videoinput.includes(e))(o)){const e=(()=>{const e=new Error;return e.name="NotFoundError",e})();return Promise.reject(e)}if(o&&"string"==typeof o&&A(o)){const e=new Error("Permission denied");return Promise.reject(e)}return o&&"string"==typeof o&&"object"==typeof e.video&&"object"==typeof e.video.height&&"object"==typeof e.video.height&&e.video.height&&e.video.height.exact&&!(({deviceId:e,exactHeight:t})=>{const i=P[e];return!i||0!==i.filter((({height:e})=>e===t)).length})({deviceId:o,exactHeight:e.video.height.exact})?Promise.reject(new Error(`Resolution height:${e.video.height.exact} is not available: ${o}`)):s&&"string"==typeof s&&A(s)?Promise.reject(new Error(`Audio DeviceId is not available: ${s}`)):Promise.resolve(Y(e))},this.enumerateDevices=()=>new Promise((e=>setTimeout((()=>e(T())),100))),this.addEventListener=(e,t)=>{this._events.on(e,t)},this.removeEventListener=(e,t)=>{this._events.off(e,t)},this.setCountVideoDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.videoinput=e})(e),this._events.trigger(J,void 0)},this.setCountAudioInDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.audioinput=e})(e),this._events.trigger(J,void 0)},this.setCountAudioOutDevicesAvailable=e=>{((e=1)=>{global.COUNT_DEVICES_AVAILABLE.audiooutput=e})(e),this._events.trigger(J,void 0)},this.setBusyVideoDevice=e=>{(e=>{global.DEVICES_BUSY.videoinput.includes(e)||global.DEVICES_BUSY.videoinput.push(e)})(e)},this.setNotFoundVideoDevice=e=>{(e=>{global.DEVICES_NOT_FOUND.videoinput.includes(e)||global.DEVICES_NOT_FOUND.videoinput.push(e)})(e)},this.setPermissionDeniedBySystem=e=>{(e=>{global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.includes(e)||global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.push(e)})(e)},this.setUserNotAccessVideo=(e=!0)=>{j(e)},this.setUserNotAccessAudioIn=(e=!0)=>{U(e)},this.setUserNotAccessAll=(e=!0)=>{x(e)},this.unsetAllRestrictions=()=>{global.DEVICES_BUSY.videoinput=[],global.DEVICES_NOT_FOUND.videoinput=[],global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=[],x(!1)},this.unsetBusyVideoDevice=e=>{(e=>{global.DEVICES_BUSY.videoinput=global.DEVICES_BUSY.videoinput.filter((t=>t!==e))})(e)},this.unsetNotFoundVideoDevice=e=>{(e=>{global.DEVICES_NOT_FOUND.videoinput=global.DEVICES_NOT_FOUND.videoinput.filter((t=>t!==e))})(e)},this.unsetPermissionDeniedBySystem=e=>{(e=>{global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput.filter((t=>t!==e))})(e)},this._events=new v.default(W)}}e.MediaStreamMock=R,e.MediaStreamTrackMock=class{constructor(e,{id:t="identifier",constraints:i={}}={}){this.contentHint="",this.readyState="live",this.isolated=!1,this.label="",this.muted=!1,this.onended=null,this.onisolationchange=null,this.onmute=null,this.onunmute=null,this.getConstraints=()=>this.constraints,this.stop=()=>{this.readyState="ended"},this.addEventListener=jest.fn(),this.removeEventListener=jest.fn(),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},i)}clone(){throw new Error("Method not implemented.")}getCapabilities(){throw new Error("Method not implemented.")}getSettings(){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}applyConstraints(e){return this.constraints=Object.assign({},e),Promise.resolve()}},e.createAudioContextAudioMediaStreamTrackMock=g,e.createAudioMediaStreamTrackMock=p,e.createCanvasVideoMediaStreamTrackMock=I,e.createMediaStreamMock=Y,e.createVideoMediaStreamTrackMock=S,e.doMock=()=>{global.MediaStream=R,global.navigator.mediaDevices=new z,global.COUNT_DEVICES_AVAILABLE={[f]:1,[b]:1,[m]:1},global.DEVICES_USER_NOT_ACCESS={[f]:!1,[b]:!1,[m]:!1},global.DEVICES_BUSY={[f]:[]},global.DEVICES_NOT_FOUND={[f]:[]},global.DEVICES_PERMISSION_DENIED_BY_SYSTEM={[f]:[]}},e.getAudioContextMediaStreamMock=()=>Promise.resolve(new R([g()])),e.getAvailableDevices=T,e.getAvailableDevicesWithResolutions=({hasAccessDeviceAudioOutput:e=!1}={})=>T().map((t=>{let i;var o;return i="videoinput"===t.kind?Object.assign({resolutions:A(t.deviceId)?[]:(o=t.deviceId,P[o]),hasAccess:!A(t.deviceId)},t):"audioinput"===t.kind?Object.assign({hasAccess:!A(t.deviceId)},t):e?Object.assign({hasAccess:!0},t):Object.assign({},t),i})),e.getCanvasMediaStreamMock=()=>Promise.resolve(new R([I()])),e.parseMediaStream=H,e.parseMediaStreamWithoutId=e=>{const t=H(e);return delete t.id,t},e.parseObject=$,e.parseTracks=q,e.resolutionsList=_,e.resolveParseArray=F,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map

@@ -14,2 +14,3 @@ declare type TEventNames = typeof eventsNames;

setCountAudioInDevicesAvailable: (count: number) => void;
setCountAudioOutDevicesAvailable: (count: number) => void;
setBusyVideoDevice: (deviceId: string) => void;

@@ -16,0 +17,0 @@ setNotFoundVideoDevice: (deviceId: string) => void;

@@ -143,2 +143,6 @@ "use strict";

};
this.setCountAudioOutDevicesAvailable = (count) => {
(0, devicesMock_1.setCountAudioOutDevicesAvailable)(count);
this._events.trigger(DEVICE_CHANGE, undefined);
};
this.setBusyVideoDevice = (deviceId) => {

@@ -145,0 +149,0 @@ (0, devicesMock_1.setBusyVideoDevice)(deviceId);

{
"name": "webrtc-mock",
"version": "0.0.3",
"version": "0.0.4",
"description": "Classes and functions mock webrtc api for tests",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc