Socket
Socket
Sign inDemoInstall

webrtc-mock

Package Overview
Dependencies
1
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.13 to 0.0.14

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"];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};
import t from"events-constructor";const i="ended",e=[i,"mute","unmute","isolationchange","overconstrained"];let s=class{constructor(s,{id:n="identifier",constraints:o={}}={}){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(i));this._events.trigger(i,t),this.readyState=i,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=`${n}-${s}-track`,this.kind=s,this.enabled=!0,this.constraints=Object.assign({},o),this._events=new t(e)}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 n=t=>new s("audio",t),o=t=>new s("video",t),d=()=>n({id:"fromAudioContext",constraints:{}}),r=()=>o({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}],c="videoinput",h=({prefix:t,postfix:i="DeviceId",index:e})=>`${t}${i}${void 0===e?"":e}`;class l{constructor(t,i){this.kind=t,this.deviceId=h({index:i,prefix:t}),this.groupId=h({index:i,prefix:"groupId",postfix:t}),this.label=h({index:i,prefix:"label ",postfix:t})}toJSON(){return JSON.stringify(this)}}const u=t=>{const i=t.toLowerCase();let e=!1;return i.includes(c)?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},v=t=>Object.assign({},t),g=t=>v(new l(c,t)),E=t=>v(new l("audioinput",t)),p=t=>v(new l("audiooutput",t)),_=()=>{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()]}},S=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audioinput){case 0:return[];case 1:return[E()];case 2:return[E(),E(2)];case 3:return[E(),E(2),E(3)];default:return[E()]}},I=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audiooutput){case 0:return[];case 1:return[p()];case 2:return[p(),p(2)];case 3:return[p(),p(2),p(3)];default:return[p()]}},b=()=>[..._(),...S(),...I()],f=t=>{global.DEVICES_USER_NOT_ACCESS.videoinput=t},D=t=>{global.DEVICES_USER_NOT_ACCESS.audioinput=t},C=t=>{D(t),f(t)},m=a.filter((({id:t})=>"1080p"!==t)),O={[h({prefix:c})]:a,[h({prefix:c,index:1})]:a,[h({prefix:c,index:2})]:m},w=[i,"mute","unmute","isolationchange","overconstrained"];class A{constructor(e,{id:s="identifier",constraints:n={}}={}){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(i));this._events.trigger(i,t),this.readyState=i,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=`${s}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints=Object.assign({},n),this._events=new t(w)}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 N=["addtrack","removetrack"];let y=0;class V{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=(y+=1,`identifier-${y}`),this.tracks=i,this._events=new t(N),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 k=()=>Promise.resolve(new V([d()])),x=()=>Promise.resolve(new V([r()])),j=(t,i={})=>{const{fromCanvas:e,fromAudioContext:s}=i,a=[];t.audio&&!s&&a.push(n({id:t.audio.deviceId.exact,deviceId:t.audio.deviceId,constraints:t.audio})),t.video&&!e&&a.push(o({id:t.video.deviceId.exact,deviceId:t.video.deviceId,constraints:t.video}));let c=new V(a);return e&&s?c=new V([r(),d()]):e?c.addTrack(r()):s&&c.addTrack(d()),c},T=t=>JSON.parse(JSON.stringify(t)),U=t=>i=>{const e=i.map(T);return e.sort(((i,e)=>parseFloat(i[t])-parseFloat(e[t]))),e},B=U("id"),L=t=>T(Object.assign(Object.assign({},t),{tracks:B(t.getTracks())})),P=t=>{const i=L(t);return delete i.id,i},Y=({hasAccessDeviceAudioOutput:t=!1}={})=>b().map((i=>{let e;var s;return e="videoinput"===i.kind?Object.assign({resolutions:u(i.deviceId)?[]:(s=i.deviceId,O[s]),hasAccess:!u(i.deviceId)},i):"audioinput"===i.kind?Object.assign({hasAccess:!u(i.deviceId)},i):t?Object.assign({hasAccess:!0},i):Object.assign({},i),e})),R=["devicechange"];class M{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&&b().find((({kind:t})=>t===c))?(s=null===(i=b().find((({kind:t})=>t===c)))||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&&b().find((({kind:t})=>"audioinput"===t))?(n=null===(e=b().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&&u(s)||n&&"string"==typeof n&&u(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=O[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(j(t))},this.enumerateDevices=()=>new Promise((t=>setTimeout((()=>{const i=b();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)=>{f(t)},this.setUserNotAccessAudioIn=(t=!0)=>{D(t)},this.setUserNotAccessAll=(t=!0)=>{C(t)},this.unsetAllRestrictions=()=>{global.DEVICES_BUSY.videoinput=[],global.DEVICES_NOT_FOUND.videoinput=[],global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=[],C(!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(R),this.getDisplayMedia=this.getUserMedia}}const F=()=>{global.MediaStream=V,global.navigator.mediaDevices=new M,global.COUNT_DEVICES_AVAILABLE={[c]:1,audioinput:1,audiooutput:1},global.DEVICES_USER_NOT_ACCESS={[c]:!1,audioinput:!1,audiooutput:!1},global.DEVICES_BUSY={[c]:[]},global.DEVICES_NOT_FOUND={[c]:[]},global.DEVICES_PERMISSION_DENIED_BY_SYSTEM={[c]:[]}};export{V as MediaStreamMock,A as MediaStreamTrackMock,d as createAudioContextAudioMediaStreamTrackMock,n as createAudioMediaStreamTrackMock,r as createCanvasVideoMediaStreamTrackMock,j as createMediaStreamMock,o as createVideoMediaStreamTrackMock,F as doMock,k as getAudioContextMediaStreamMock,b as getAvailableDevices,Y as getAvailableDevicesWithResolutions,x as getCanvasMediaStreamMock,L as parseMediaStream,P as parseMediaStreamWithoutId,T as parseObject,B as parseTracks,a as resolutionsList,U 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";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}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("events-constructor")):"function"==typeof define&&define.amd?define(["exports","events-constructor"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).webrtcMock={},t.Events)}(this,(function(t,e){"use strict";const i="ended",s="mute",n="isolationchange",o="overconstrained",d="unmute",r="devicechange",a="addtrack",c="removetrack",h=[i,s,d,n,o];let l=class{constructor(t,{id:s="identifier",constraints:n={}}={}){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(i));this._events.trigger(i,t),this.readyState=i,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=`${s}-${t}-track`,this.kind=t,this.enabled=!0,this.constraints=Object.assign({},n),this._events=new e(h)}clone(){return Object.assign({},this)}getCapabilities(){return{width:{min:352,max:4096},height:{min:288,max:2160}}}getSettings(){var t,e,i,s,n,o,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===(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)?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 u=t=>new l("audio",t),v=t=>new l("video",t),g=()=>u({id:"fromAudioContext",constraints:{}}),E=()=>v({id:"fromCanvas",constraints:{}}),p=[{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}],S="videoinput",_="audioinput",b="audiooutput",I=({prefix:t,postfix:e="DeviceId",index:i})=>`${t}${e}${void 0===i?"":i}`;class f{constructor(t,e){this.kind=t,this.deviceId=I({index:e,prefix:t}),this.groupId=I({index:e,prefix:"groupId",postfix:t}),this.label=I({index:e,prefix:"label ",postfix:t})}toJSON(){return JSON.stringify(this)}}const C=t=>{const e=t.toLowerCase();let i=!1;return e.includes(S)?i=!0===global.DEVICES_USER_NOT_ACCESS.videoinput:e.includes(_)?i=!0===global.DEVICES_USER_NOT_ACCESS.audioinput:e.includes(b)&&(i=!0===global.DEVICES_USER_NOT_ACCESS.audiooutput),i},D=t=>Object.assign({},t),m=t=>D(new f(S,t)),O=t=>D(new f(_,t)),k=t=>D(new f(b,t)),A=()=>{switch(global.COUNT_DEVICES_AVAILABLE.videoinput){case 0:return[];case 1:return[m()];case 2:return[m(),m(2)];case 3:return[m(),m(2),m(3)];default:return[m()]}},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()]}},y=()=>{switch(global.COUNT_DEVICES_AVAILABLE.audiooutput){case 0:return[];case 1:return[k()];case 2:return[k(),k(2)];case 3:return[k(),k(2),k(3)];default:return[k()]}},N=()=>[...A(),...w(),...y()],V=t=>{global.DEVICES_USER_NOT_ACCESS.videoinput=t},x=t=>{global.DEVICES_USER_NOT_ACCESS.audioinput=t},T=t=>{x(t),V(t)},j=p.filter((({id:t})=>"1080p"!==t)),M={[I({prefix:S})]:p,[I({prefix:S,index:1})]:p,[I({prefix:S,index:2})]:j},U=[i,s,d,n,o];const B=[a,c];let L=0;class P{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(a)),{track:t});return this._events.trigger(a,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=(L+=1,`identifier-${L}`),this.tracks=t,this._events=new e(B),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(c)),{track:t});return this._events.trigger(c,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 R=(t,e={})=>{const{fromCanvas:i,fromAudioContext:s}=e,n=[];t.audio&&!s&&n.push(u({id:t.audio.deviceId.exact,deviceId:t.audio.deviceId,constraints:t.audio})),t.video&&!i&&n.push(v({id:t.video.deviceId.exact,deviceId:t.video.deviceId,constraints:t.video}));let o=new P(n);return i&&s?o=new P([E(),g()]):i?o.addTrack(E()):s&&o.addTrack(g()),o},Y=t=>JSON.parse(JSON.stringify(t)),F=t=>e=>{const i=e.map(Y);return i.sort(((e,i)=>parseFloat(e[t])-parseFloat(i[t]))),i},$=F("id"),H=t=>Y(Object.assign(Object.assign({},t),{tracks:$(t.getTracks())})),J=[r];class W{constructor(){this.getUserMedia=t=>{var e,i;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&&N().find((({kind:t})=>t===S))?(s=null===(e=N().find((({kind:t})=>t===S)))||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)?n=t.audio.deviceId.exact:t&&!0===t.audio&&N().find((({kind:t})=>t===_))?(n=null===(i=N().find((({kind:t})=>t===_)))||void 0===i?void 0:i.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&&C(s)||n&&"string"==typeof n&&C(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:e})=>{const i=M[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(R(t))},this.enumerateDevices=()=>new Promise((t=>setTimeout((()=>{const e=N();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(r,void 0)},this.setCountAudioInDevicesAvailable=t=>{((t=1)=>{global.COUNT_DEVICES_AVAILABLE.audioinput=t})(t),this._events.trigger(r,void 0)},this.setCountAudioOutDevicesAvailable=t=>{((t=1)=>{global.COUNT_DEVICES_AVAILABLE.audiooutput=t})(t),this._events.trigger(r,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)=>{V(t)},this.setUserNotAccessAudioIn=(t=!0)=>{x(t)},this.setUserNotAccessAll=(t=!0)=>{T(t)},this.unsetAllRestrictions=()=>{global.DEVICES_BUSY.videoinput=[],global.DEVICES_NOT_FOUND.videoinput=[],global.DEVICES_PERMISSION_DENIED_BY_SYSTEM.videoinput=[],T(!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(J),this.getDisplayMedia=this.getUserMedia}}t.MediaStreamMock=P,t.MediaStreamTrackMock=class{constructor(t,{id:s="identifier",constraints:n={}}={}){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(i));this._events.trigger(i,t),this.readyState=i,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=`${s}-${t}-track`,this.kind=t,this.enabled=!0,this.constraints=Object.assign({},n),this._events=new e(U)}clone(){return Object.assign({},this)}getCapabilities(){return{width:{min:352,max:4096},height:{min:288,max:2160}}}getSettings(){var t,e,i,s,n,o,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===(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)?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=g,t.createAudioMediaStreamTrackMock=u,t.createCanvasVideoMediaStreamTrackMock=E,t.createMediaStreamMock=R,t.createVideoMediaStreamTrackMock=v,t.doMock=()=>{global.MediaStream=P,global.navigator.mediaDevices=new W,global.COUNT_DEVICES_AVAILABLE={[S]:1,[_]:1,[b]:1},global.DEVICES_USER_NOT_ACCESS={[S]:!1,[_]:!1,[b]:!1},global.DEVICES_BUSY={[S]:[]},global.DEVICES_NOT_FOUND={[S]:[]},global.DEVICES_PERMISSION_DENIED_BY_SYSTEM={[S]:[]}},t.getAudioContextMediaStreamMock=()=>Promise.resolve(new P([g()])),t.getAvailableDevices=N,t.getAvailableDevicesWithResolutions=({hasAccessDeviceAudioOutput:t=!1}={})=>N().map((e=>{let i;var s;return i="videoinput"===e.kind?Object.assign({resolutions:C(e.deviceId)?[]:(s=e.deviceId,M[s]),hasAccess:!C(e.deviceId)},e):"audioinput"===e.kind?Object.assign({hasAccess:!C(e.deviceId)},e):t?Object.assign({hasAccess:!0},e):Object.assign({},e),i})),t.getCanvasMediaStreamMock=()=>Promise.resolve(new P([E()])),t.parseMediaStream=H,t.parseMediaStreamWithoutId=t=>{const e=H(t);return delete e.id,e},t.parseObject=Y,t.parseTracks=$,t.resolutionsList=p,t.resolveParseArray=F}));
//# sourceMappingURL=index.umd.js.map

@@ -1,3 +0,3 @@

declare const resolveParseArray: <T = any>(prop: string) => (array: T[]) => T[];
declare const resolveParseArray: <T>(prop: string) => (array: T[]) => T[];
export default resolveParseArray;
//# sourceMappingURL=resolveParseArray.d.ts.map

@@ -7,14 +7,11 @@ "use strict";

// @ts-nocheck
const flow_1 = __importDefault(require("lodash/flow"));
const curryRight_1 = __importDefault(require("lodash/curryRight"));
const map_1 = __importDefault(require("lodash/map"));
const sortBy_1 = __importDefault(require("lodash/sortBy"));
const property_1 = __importDefault(require("lodash/property"));
const parseObject_1 = __importDefault(require("./parseObject"));
const resolveParseArray = (prop) => {
const parseArray = (0, flow_1.default)(parseObject_1.default, (arr) => {
return (0, sortBy_1.default)(arr, (0, property_1.default)(prop));
},
// @ts-ignore
(0, curryRight_1.default)(map_1.default)(parseObject_1.default));
const parseArray = (array) => {
const parsedArray = array.map(parseObject_1.default);
parsedArray.sort((a, b) => {
return parseFloat(a[prop]) - parseFloat(b[prop]);
});
return parsedArray;
};
return parseArray;

@@ -21,0 +18,0 @@ };

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

@@ -41,34 +41,27 @@ "keywords": [

"prepublishOnly": "npm run lint",
"release": "standard-version",
"test": "jest"
"release": "standard-version"
},
"dependencies": {
"events-constructor": "^1.2.0",
"lodash": "^4.17.21"
"events-constructor": "^1.2.0"
},
"devDependencies": {
"@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": "^27.1.5",
"@commitlint/cli": "^17.6.6",
"@commitlint/config-conventional": "^17.6.6",
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-node-resolve": "^15.1.0",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.2",
"jest": "29.3.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"promise-delay": "^2.1.0",
"rollup": "^3.3.0",
"rollup": "^3.25.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "0.34.1",
"rollup-plugin-typescript2": "0.35.0",
"standard-version": "^9.5.0",
"ts-jest": "^29.0.3",
"typescript": "^4.9.3"
"typescript": "^5.1.3"
},

@@ -75,0 +68,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

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc