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.11 to 0.0.13

2

dist/index.es5.js

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

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

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

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

@@ -1,4 +0,4 @@

declare type TEventNames = typeof eventsNames;
declare type TEventName = TEventNames[number];
declare type THandler = (event: Event) => void;
type TEventNames = typeof eventsNames;
type TEventName = TEventNames[number];
type THandler = (event: Event) => void;
declare const eventsNames: readonly ["devicechange"];

@@ -5,0 +5,0 @@ declare class MediaDevicesMock {

import type MediaStreamTrackMock from './mediaStreamTrackMock';
declare const eventsNames: readonly ["addtrack", "removetrack"];
declare type TEventNames = typeof eventsNames;
declare type TEventName = TEventNames[number];
declare type THandler = (event: Event) => void;
type TEventNames = typeof eventsNames;
type TEventName = TEventNames[number];
type THandler = (event: Event) => void;
declare class MediaStreamMock implements MediaStream {

@@ -7,0 +7,0 @@ private _events;

declare const eventsNames: readonly ["ended", "mute", "unmute", "isolationchange", "overconstrained"];
declare type TEventNames = typeof eventsNames;
declare type TEventName = TEventNames[number];
declare type THandler = (event: Event) => void;
type TEventNames = typeof eventsNames;
type TEventName = TEventNames[number];
type THandler = (event: Event) => void;
declare class MediaStreamTrackMock implements MediaStreamTrack {

@@ -6,0 +6,0 @@ private _events;

import type MediaStreamMock from '../MediaStreamMock';
declare const parseMediaStreamWithoutId: (mediaStream: MediaStreamMock) => Omit<MediaStreamMock, 'id'>;
type TMediaStreamMockWithoutId = Omit<MediaStreamMock, 'id'>;
declare const parseMediaStreamWithoutId: (mediaStream: MediaStreamMock) => TMediaStreamMockWithoutId;
export default parseMediaStreamWithoutId;
//# sourceMappingURL=parseMediaStreamWithoutId.d.ts.map
{
"name": "webrtc-mock",
"version": "0.0.11",
"version": "0.0.13",
"description": "Classes and functions mock webrtc api for tests",

@@ -23,2 +23,3 @@ "keywords": [

},
"type": "module",
"main": "dist/index.umd.js",

@@ -38,2 +39,3 @@ "module": "dist/index.es5.js",

"lint": "eslint src/. --ext .ts",
"lint:ts": "tsc --noEmit",
"prepare": "npm run build",

@@ -45,30 +47,30 @@ "prepublishOnly": "npm run lint",

"dependencies": {
"lodash": "^4.17.21",
"events-constructor": "^1.2.0"
"events-constructor": "^1.2.0",
"lodash": "^4.17.21"
},
"devDependencies": {
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/jest": "^28.1.2",
"@types/lodash": "^4.14.182",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"eslint": "^8.18.0",
"@commitlint/cli": "^17.2.0",
"@commitlint/config-conventional": "^17.2.0",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@types/jest": "^29.2.3",
"@types/lodash": "^4.14.189",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.1",
"jest": "28.1.1",
"lint-staged": "^13.0.2",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.2",
"jest": "29.3.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"promise-delay": "^2.1.0",
"rollup": "^2.75.7",
"rollup": "^3.3.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "0.32.1",
"rollup-plugin-typescript2": "0.34.1",
"standard-version": "^9.5.0",
"ts-jest": "^28.0.5",
"typescript": "^4.7.4"
"ts-jest": "^29.0.3",
"typescript": "^4.9.3"
},

@@ -75,0 +77,0 @@ "main:src": "src/index.ts",

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

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