@eyevinn/whpp-client
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,1 +0,1 @@ | ||
exports.WHPPClient=/*#__PURE__*/function(){function e(e,t,n){this.localPeer=void 0,this.whppUrl=void 0,this.iceGatheringTimeout=void 0,this.waitingForCandidates=!1,this.resourceUrl=void 0,this.opts=void 0,this.localPeer=e,this.whppUrl=t,this.opts=n,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.localPeer.onicecandidateerror=this.onIceCandidateError.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}var t=e.prototype;return t.getPeer=function(){return this.localPeer},t.connect=function(){try{var e,t=this;return Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:"{}"})).then(function(e){var n;function o(o){return n?o:Promise.resolve(e.json()).then(function(n){var o=e.headers.get("location");return t.resourceUrl=new URL(o),t.supportsTrickleIce()||(t.waitingForCandidates=!0),Promise.resolve(t.localPeer.setRemoteDescription({type:"offer",sdp:n.offer})).then(function(){return Promise.resolve(t.localPeer.createAnswer()).then(function(e){return Promise.resolve(t.localPeer.setLocalDescription(e)).then(function(){var e=function(){if(t.supportsTrickleIce())return Promise.resolve(t.sendAnswer()).then(function(){});var e;t.iceGatheringTimeout=setTimeout(t.onIceGatheringTimeout.bind(t),(null==(e=t.opts)?void 0:e.timeout)||2e3)}();if(e&&e.then)return e.then(function(){})})})})})}var i=function(){if(!e.ok)return function(){if(415===e.status)return t.opts.useLegacyContentType=!0,Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})).then(function(t){e=t});n=1}()}();return i&&i.then?i.then(o):o(i)})}catch(e){return Promise.reject(e)}},t.log=function(){var e,t;null!=(e=this.opts)&&e.debug&&(t=console).log.apply(t,["whpp-client"].concat([].slice.call(arguments)))},t.error=function(){var e;(e=console).error.apply(e,["whpp-client"].concat([].slice.call(arguments)))},t.onIceGatheringStateChange=function(e){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.onIceConnectionStateChange=function(e){this.log("IceConnectionState",this.localPeer.iceConnectionState),"failed"===this.localPeer.iceConnectionState&&this.localPeer.close()},t.onIceCandidate=function(e){try{var t=this;if("icecandidate"!==e.type)return Promise.resolve();var n=e.candidate;return n?(t.log("IceCandidate",n.candidate),t.supportsTrickleIce()?(t.sendCandidate(n),Promise.resolve()):Promise.resolve()):Promise.resolve()}catch(e){return Promise.reject(e)}},t.onIceCandidateError=function(e){this.log("IceCandidateError",e)},t.onIceGatheringTimeout=function(){this.log("IceGatheringTimeout"),!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.supportsTrickleIce=function(){return this.opts&&!this.opts.noIceTrickle},t.onDoneWaitingForCandidates=function(){try{var e=this;return e.waitingForCandidates=!1,clearTimeout(e.iceGatheringTimeout),Promise.resolve(e.sendAnswer()).then(function(){})}catch(e){return Promise.reject(e)}},t.sendCandidate=function(e){try{var t,n=this;return Promise.resolve(fetch(n.resourceUrl.href,{method:"PATCH",headers:{"Content-Type":null!=(t=n.opts)&&t.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify({candidate:e.candidate})})).then(function(e){e.ok||n.error("sendCandidate response: "+e.status)})}catch(e){return Promise.reject(e)}},t.sendAnswer=function(){try{var e,t=this;return Promise.resolve(fetch(t.resourceUrl.href,{method:"PUT",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify({answer:t.localPeer.localDescription.sdp})})).then(function(e){e.ok||t.error("sendAnswer response: "+e.status)})}catch(e){return Promise.reject(e)}},e}(); | ||
exports.WHPPClient=/*#__PURE__*/function(){function e(e,t,n){this.localPeer=void 0,this.whppUrl=void 0,this.iceGatheringTimeout=void 0,this.waitingForCandidates=!1,this.resourceUrl=void 0,this.opts=void 0,this.localPeer=e,this.whppUrl=t,this.opts=n,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.localPeer.onicecandidateerror=this.onIceCandidateError.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}var t=e.prototype;return t.getPeer=function(){return this.localPeer},t.connect=function(){try{var e,t=this;return Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:"{}"})).then(function(e){var n;function o(o){return n?o:Promise.resolve(e.json()).then(function(n){var o=e.headers.get("location");return t.resourceUrl=new URL(o),t.log(n.offer),Promise.resolve(function(e){try{return Promise.resolve(fetch(e.href,{method:"OPTIONS"})).then(function(e){return!(!e.ok||!e.headers.get("Allow")||!e.headers.get("Allow").split(",").find(function(e){return"PATCH"===e.trimStart()}))})}catch(e){return Promise.reject(e)}}(t.resourceUrl)).then(function(e){return t.log("ICE trickle supported by endpoint: "+e),t.opts||(t.opts={}),t.opts.noIceTrickle=!e,t.supportsTrickleIce()||(t.waitingForCandidates=!0),Promise.resolve(t.localPeer.setRemoteDescription({type:"offer",sdp:n.offer})).then(function(){return Promise.resolve(t.localPeer.createAnswer()).then(function(e){return Promise.resolve(t.localPeer.setLocalDescription(e)).then(function(){var e=function(){if(t.supportsTrickleIce())return t.log("ICE trickle supported, sending answer"),Promise.resolve(t.sendAnswer()).then(function(){});var e;t.iceGatheringTimeout=setTimeout(t.onIceGatheringTimeout.bind(t),(null==(e=t.opts)?void 0:e.timeout)||2e3)}();if(e&&e.then)return e.then(function(){})})})})})})}var r=function(){if(!e.ok)return function(){if(415===e.status)return t.opts.useLegacyContentType=!0,Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})).then(function(t){e=t});n=1}()}();return r&&r.then?r.then(o):o(r)})}catch(e){return Promise.reject(e)}},t.log=function(){var e,t;null!=(e=this.opts)&&e.debug&&(t=console).log.apply(t,["whpp-client"].concat([].slice.call(arguments)))},t.error=function(){var e;(e=console).error.apply(e,["whpp-client"].concat([].slice.call(arguments)))},t.onIceGatheringStateChange=function(e){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.onIceConnectionStateChange=function(e){this.log("IceConnectionState",this.localPeer.iceConnectionState),"failed"===this.localPeer.iceConnectionState&&this.localPeer.close()},t.onIceCandidate=function(e){try{var t=this;if("icecandidate"!==e.type)return Promise.resolve();var n=e.candidate;return n?(t.log("IceCandidate",n.candidate),t.supportsTrickleIce()?(t.sendCandidate(n),Promise.resolve()):Promise.resolve()):Promise.resolve()}catch(e){return Promise.reject(e)}},t.onIceCandidateError=function(e){this.log("IceCandidateError",e)},t.onIceGatheringTimeout=function(){this.log("IceGatheringTimeout"),!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.supportsTrickleIce=function(){return this.opts&&!this.opts.noIceTrickle},t.onDoneWaitingForCandidates=function(){try{var e=this;return e.waitingForCandidates=!1,clearTimeout(e.iceGatheringTimeout),Promise.resolve(e.sendAnswer()).then(function(){})}catch(e){return Promise.reject(e)}},t.sendCandidate=function(e){try{var t,n=this;return Promise.resolve(fetch(n.resourceUrl.href,{method:"PATCH",headers:{"Content-Type":null!=(t=n.opts)&&t.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify({candidate:e.candidate})})).then(function(e){e.ok||(n.error("sendCandidate response: "+e.status),405===e.status&&n.log("ICE trickle not supported by endpoint"))})}catch(e){return Promise.reject(e)}},t.sendAnswer=function(){try{var e,t=this,n={answer:t.localPeer.localDescription.sdp};return t.log(n.answer),Promise.resolve(fetch(t.resourceUrl.href,{method:"PUT",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify(n)})).then(function(e){e.ok||t.error("sendAnswer response: "+e.status)})}catch(e){return Promise.reject(e)}},e}(); |
@@ -1,1 +0,1 @@ | ||
var e=/*#__PURE__*/function(){function e(e,t,n){this.localPeer=void 0,this.whppUrl=void 0,this.iceGatheringTimeout=void 0,this.waitingForCandidates=!1,this.resourceUrl=void 0,this.opts=void 0,this.localPeer=e,this.whppUrl=t,this.opts=n,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.localPeer.onicecandidateerror=this.onIceCandidateError.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}var t=e.prototype;return t.getPeer=function(){return this.localPeer},t.connect=function(){try{var e,t=this;return Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:"{}"})).then(function(e){var n;function o(o){return n?o:Promise.resolve(e.json()).then(function(n){var o=e.headers.get("location");return t.resourceUrl=new URL(o),t.supportsTrickleIce()||(t.waitingForCandidates=!0),Promise.resolve(t.localPeer.setRemoteDescription({type:"offer",sdp:n.offer})).then(function(){return Promise.resolve(t.localPeer.createAnswer()).then(function(e){return Promise.resolve(t.localPeer.setLocalDescription(e)).then(function(){var e=function(){if(t.supportsTrickleIce())return Promise.resolve(t.sendAnswer()).then(function(){});var e;t.iceGatheringTimeout=setTimeout(t.onIceGatheringTimeout.bind(t),(null==(e=t.opts)?void 0:e.timeout)||2e3)}();if(e&&e.then)return e.then(function(){})})})})})}var i=function(){if(!e.ok)return function(){if(415===e.status)return t.opts.useLegacyContentType=!0,Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})).then(function(t){e=t});n=1}()}();return i&&i.then?i.then(o):o(i)})}catch(e){return Promise.reject(e)}},t.log=function(){var e,t;null!=(e=this.opts)&&e.debug&&(t=console).log.apply(t,["whpp-client"].concat([].slice.call(arguments)))},t.error=function(){var e;(e=console).error.apply(e,["whpp-client"].concat([].slice.call(arguments)))},t.onIceGatheringStateChange=function(e){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.onIceConnectionStateChange=function(e){this.log("IceConnectionState",this.localPeer.iceConnectionState),"failed"===this.localPeer.iceConnectionState&&this.localPeer.close()},t.onIceCandidate=function(e){try{var t=this;if("icecandidate"!==e.type)return Promise.resolve();var n=e.candidate;return n?(t.log("IceCandidate",n.candidate),t.supportsTrickleIce()?(t.sendCandidate(n),Promise.resolve()):Promise.resolve()):Promise.resolve()}catch(e){return Promise.reject(e)}},t.onIceCandidateError=function(e){this.log("IceCandidateError",e)},t.onIceGatheringTimeout=function(){this.log("IceGatheringTimeout"),!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.supportsTrickleIce=function(){return this.opts&&!this.opts.noIceTrickle},t.onDoneWaitingForCandidates=function(){try{var e=this;return e.waitingForCandidates=!1,clearTimeout(e.iceGatheringTimeout),Promise.resolve(e.sendAnswer()).then(function(){})}catch(e){return Promise.reject(e)}},t.sendCandidate=function(e){try{var t,n=this;return Promise.resolve(fetch(n.resourceUrl.href,{method:"PATCH",headers:{"Content-Type":null!=(t=n.opts)&&t.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify({candidate:e.candidate})})).then(function(e){e.ok||n.error("sendCandidate response: "+e.status)})}catch(e){return Promise.reject(e)}},t.sendAnswer=function(){try{var e,t=this;return Promise.resolve(fetch(t.resourceUrl.href,{method:"PUT",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify({answer:t.localPeer.localDescription.sdp})})).then(function(e){e.ok||t.error("sendAnswer response: "+e.status)})}catch(e){return Promise.reject(e)}},e}();export{e as WHPPClient}; | ||
var e=/*#__PURE__*/function(){function e(e,t,n){this.localPeer=void 0,this.whppUrl=void 0,this.iceGatheringTimeout=void 0,this.waitingForCandidates=!1,this.resourceUrl=void 0,this.opts=void 0,this.localPeer=e,this.whppUrl=t,this.opts=n,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.localPeer.onicecandidateerror=this.onIceCandidateError.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}var t=e.prototype;return t.getPeer=function(){return this.localPeer},t.connect=function(){try{var e,t=this;return Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:"{}"})).then(function(e){var n;function o(o){return n?o:Promise.resolve(e.json()).then(function(n){var o=e.headers.get("location");return t.resourceUrl=new URL(o),t.log(n.offer),Promise.resolve(function(e){try{return Promise.resolve(fetch(e.href,{method:"OPTIONS"})).then(function(e){return!(!e.ok||!e.headers.get("Allow")||!e.headers.get("Allow").split(",").find(function(e){return"PATCH"===e.trimStart()}))})}catch(e){return Promise.reject(e)}}(t.resourceUrl)).then(function(e){return t.log("ICE trickle supported by endpoint: "+e),t.opts||(t.opts={}),t.opts.noIceTrickle=!e,t.supportsTrickleIce()||(t.waitingForCandidates=!0),Promise.resolve(t.localPeer.setRemoteDescription({type:"offer",sdp:n.offer})).then(function(){return Promise.resolve(t.localPeer.createAnswer()).then(function(e){return Promise.resolve(t.localPeer.setLocalDescription(e)).then(function(){var e=function(){if(t.supportsTrickleIce())return t.log("ICE trickle supported, sending answer"),Promise.resolve(t.sendAnswer()).then(function(){});var e;t.iceGatheringTimeout=setTimeout(t.onIceGatheringTimeout.bind(t),(null==(e=t.opts)?void 0:e.timeout)||2e3)}();if(e&&e.then)return e.then(function(){})})})})})})}var r=function(){if(!e.ok)return function(){if(415===e.status)return t.opts.useLegacyContentType=!0,Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})).then(function(t){e=t});n=1}()}();return r&&r.then?r.then(o):o(r)})}catch(e){return Promise.reject(e)}},t.log=function(){var e,t;null!=(e=this.opts)&&e.debug&&(t=console).log.apply(t,["whpp-client"].concat([].slice.call(arguments)))},t.error=function(){var e;(e=console).error.apply(e,["whpp-client"].concat([].slice.call(arguments)))},t.onIceGatheringStateChange=function(e){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.onIceConnectionStateChange=function(e){this.log("IceConnectionState",this.localPeer.iceConnectionState),"failed"===this.localPeer.iceConnectionState&&this.localPeer.close()},t.onIceCandidate=function(e){try{var t=this;if("icecandidate"!==e.type)return Promise.resolve();var n=e.candidate;return n?(t.log("IceCandidate",n.candidate),t.supportsTrickleIce()?(t.sendCandidate(n),Promise.resolve()):Promise.resolve()):Promise.resolve()}catch(e){return Promise.reject(e)}},t.onIceCandidateError=function(e){this.log("IceCandidateError",e)},t.onIceGatheringTimeout=function(){this.log("IceGatheringTimeout"),!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.supportsTrickleIce=function(){return this.opts&&!this.opts.noIceTrickle},t.onDoneWaitingForCandidates=function(){try{var e=this;return e.waitingForCandidates=!1,clearTimeout(e.iceGatheringTimeout),Promise.resolve(e.sendAnswer()).then(function(){})}catch(e){return Promise.reject(e)}},t.sendCandidate=function(e){try{var t,n=this;return Promise.resolve(fetch(n.resourceUrl.href,{method:"PATCH",headers:{"Content-Type":null!=(t=n.opts)&&t.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify({candidate:e.candidate})})).then(function(e){e.ok||(n.error("sendCandidate response: "+e.status),405===e.status&&n.log("ICE trickle not supported by endpoint"))})}catch(e){return Promise.reject(e)}},t.sendAnswer=function(){try{var e,t=this,n={answer:t.localPeer.localDescription.sdp};return t.log(n.answer),Promise.resolve(fetch(t.resourceUrl.href,{method:"PUT",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify(n)})).then(function(e){e.ok||t.error("sendAnswer response: "+e.status)})}catch(e){return Promise.reject(e)}},e}();export{e as WHPPClient}; |
@@ -1,1 +0,1 @@ | ||
class e{constructor(e,t,i){this.localPeer=void 0,this.whppUrl=void 0,this.iceGatheringTimeout=void 0,this.waitingForCandidates=!1,this.resourceUrl=void 0,this.opts=void 0,this.localPeer=e,this.whppUrl=t,this.opts=i,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.localPeer.onicecandidateerror=this.onIceCandidateError.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}getPeer(){return this.localPeer}async connect(){var e;let t=await fetch(this.whppUrl.href,{method:"POST",headers:{"Content-Type":null!=(e=this.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:"{}"});if(!t.ok){if(415!==t.status)return;this.opts.useLegacyContentType=!0,t=await fetch(this.whppUrl.href,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})}const i=await t.json(),n=t.headers.get("location");this.resourceUrl=new URL(n),this.supportsTrickleIce()||(this.waitingForCandidates=!0),await this.localPeer.setRemoteDescription({type:"offer",sdp:i.offer});const s=await this.localPeer.createAnswer();var o;await this.localPeer.setLocalDescription(s),this.supportsTrickleIce()?await this.sendAnswer():this.iceGatheringTimeout=setTimeout(this.onIceGatheringTimeout.bind(this),(null==(o=this.opts)?void 0:o.timeout)||2e3)}log(...e){var t;null!=(t=this.opts)&&t.debug&&console.log("whpp-client",...e)}error(...e){console.error("whpp-client",...e)}onIceGatheringStateChange(e){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()}onIceConnectionStateChange(e){this.log("IceConnectionState",this.localPeer.iceConnectionState),"failed"===this.localPeer.iceConnectionState&&this.localPeer.close()}async onIceCandidate(e){if("icecandidate"!==e.type)return;const t=e.candidate;t&&(this.log("IceCandidate",t.candidate),this.supportsTrickleIce()&&this.sendCandidate(t))}onIceCandidateError(e){this.log("IceCandidateError",e)}onIceGatheringTimeout(){this.log("IceGatheringTimeout"),!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()}supportsTrickleIce(){return this.opts&&!this.opts.noIceTrickle}async onDoneWaitingForCandidates(){this.waitingForCandidates=!1,clearTimeout(this.iceGatheringTimeout),await this.sendAnswer()}async sendCandidate(e){var t;const i={candidate:e.candidate},n=await fetch(this.resourceUrl.href,{method:"PATCH",headers:{"Content-Type":null!=(t=this.opts)&&t.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify(i)});n.ok||this.error(`sendCandidate response: ${n.status}`)}async sendAnswer(){var e;const t={answer:this.localPeer.localDescription.sdp},i=await fetch(this.resourceUrl.href,{method:"PUT",headers:{"Content-Type":null!=(e=this.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify(t)});i.ok||this.error(`sendAnswer response: ${i.status}`)}}export{e as WHPPClient}; | ||
class t{constructor(t,e,i){this.localPeer=void 0,this.whppUrl=void 0,this.iceGatheringTimeout=void 0,this.waitingForCandidates=!1,this.resourceUrl=void 0,this.opts=void 0,this.localPeer=t,this.whppUrl=e,this.opts=i,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.localPeer.onicecandidateerror=this.onIceCandidateError.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}getPeer(){return this.localPeer}async connect(){var t;let e=await fetch(this.whppUrl.href,{method:"POST",headers:{"Content-Type":null!=(t=this.opts)&&t.useLegacyContentType?"application/json":"application/whpp+json"},body:"{}"});if(!e.ok){if(415!==e.status)return;this.opts.useLegacyContentType=!0,e=await fetch(this.whppUrl.href,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})}const i=await e.json(),s=e.headers.get("location");this.resourceUrl=new URL(s),this.log(i.offer);const o=await async function(t){let e=await fetch(t.href,{method:"OPTIONS"});return!(!e.ok||!e.headers.get("Allow")||!e.headers.get("Allow").split(",").find(t=>"PATCH"===t.trimStart()))}(this.resourceUrl);this.log("ICE trickle supported by endpoint: "+o),this.opts||(this.opts={}),this.opts.noIceTrickle=!o,this.supportsTrickleIce()||(this.waitingForCandidates=!0),await this.localPeer.setRemoteDescription({type:"offer",sdp:i.offer});const n=await this.localPeer.createAnswer();var a;await this.localPeer.setLocalDescription(n),this.supportsTrickleIce()?(this.log("ICE trickle supported, sending answer"),await this.sendAnswer()):this.iceGatheringTimeout=setTimeout(this.onIceGatheringTimeout.bind(this),(null==(a=this.opts)?void 0:a.timeout)||2e3)}log(...t){var e;null!=(e=this.opts)&&e.debug&&console.log("whpp-client",...t)}error(...t){console.error("whpp-client",...t)}onIceGatheringStateChange(t){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()}onIceConnectionStateChange(t){this.log("IceConnectionState",this.localPeer.iceConnectionState),"failed"===this.localPeer.iceConnectionState&&this.localPeer.close()}async onIceCandidate(t){if("icecandidate"!==t.type)return;const e=t.candidate;e&&(this.log("IceCandidate",e.candidate),this.supportsTrickleIce()&&this.sendCandidate(e))}onIceCandidateError(t){this.log("IceCandidateError",t)}onIceGatheringTimeout(){this.log("IceGatheringTimeout"),!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()}supportsTrickleIce(){return this.opts&&!this.opts.noIceTrickle}async onDoneWaitingForCandidates(){this.waitingForCandidates=!1,clearTimeout(this.iceGatheringTimeout),await this.sendAnswer()}async sendCandidate(t){var e;const i={candidate:t.candidate},s=await fetch(this.resourceUrl.href,{method:"PATCH",headers:{"Content-Type":null!=(e=this.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify(i)});s.ok||(this.error(`sendCandidate response: ${s.status}`),405===s.status&&this.log("ICE trickle not supported by endpoint"))}async sendAnswer(){var t;const e={answer:this.localPeer.localDescription.sdp};this.log(e.answer);const i=await fetch(this.resourceUrl.href,{method:"PUT",headers:{"Content-Type":null!=(t=this.opts)&&t.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify(e)});i.ok||this.error(`sendAnswer response: ${i.status}`)}}export{t as WHPPClient}; |
{ | ||
"name": "@eyevinn/whpp-client", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "WebRTC HTTP Playback Protocol client library", | ||
@@ -5,0 +5,0 @@ "main": "dist/whpp-client.js", |
# WHPP Client Library | ||
A node / JS library for WebRTC HTTP Playback Protocol | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Slack](http://slack.streamingtech.se/badge.svg)](http://slack.streamingtech.se) | ||
A Node / JS library for [WebRTC HTTP Playback Protocol](https://github.com/Eyevinn/webrtc-http-playback-protocol/blob/master/webrtc-http-playback-protocol.md) | ||
For more information about WHIP and WHPP read [this blog post](https://medium.com/@eyevinntechnology/whip-whpp-for-webrtc-based-broadcast-streaming-2cf469e95299). | ||
## Usage | ||
@@ -28,4 +32,15 @@ | ||
### Examples | ||
## Options | ||
``` | ||
{ | ||
debug?: boolean; // Use debug logging | ||
noIceTrickle?: boolean; // Wait for all ICE candidates to be gathered | ||
timeout?: number; // Timeout for gathering ICE candidates | ||
useLegacyContentType?: boolean; // WHPP endpoints that does not support the `whpp+json` content type | ||
} | ||
``` | ||
## Examples | ||
| Example | Description | Source | | ||
@@ -32,0 +47,0 @@ | ------- | ----------- | ------ | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18343
92
56
15