Files

1 line
80 KiB
JavaScript
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
Janus.sessions={};Janus.isExtensionEnabled=function(){if(navigator.getDisplayMedia){return true}if(window.navigator.userAgent.match("Chrome")){var chromever=parseInt(window.navigator.userAgent.match(/Chrome\/(.*) /)[1],10);var maxver=33;if(window.navigator.userAgent.match("Linux"))maxver=35;if(chromever>=26&&chromever<=maxver){return true}return Janus.extension.isInstalled()}else{return true}};var defaultExtension={extensionId:"hapfgfdkleiggjjpfpenajgdnfckjpaj",isInstalled:function(){return document.querySelector("#janus-extension-installed")!==null},getScreen:function(callback){var pending=window.setTimeout(function(){error=new Error("NavigatorUserMediaError");error.name='The required Chrome extension is not installed: click <a href="#">here</a> to install it. (NOTE: this will need you to refresh the page)';return callback(error)},1e3);this.cache[pending]=callback;window.postMessage({type:"janusGetScreen",id:pending},"*")},init:function(){var cache={};this.cache=cache;window.addEventListener("message",function(event){if(event.origin!=window.location.origin)return;if(event.data.type=="janusGotScreen"&&cache[event.data.id]){var callback=cache[event.data.id];delete cache[event.data.id];if(event.data.sourceId===""){var error=new Error("NavigatorUserMediaError");error.name="You cancelled the request for permission, giving up...";callback(error)}else{callback(null,event.data.sourceId)}}else if(event.data.type=="janusGetScreenPending"){console.log("clearing ",event.data.id);window.clearTimeout(event.data.id)}})}};Janus.useDefaultDependencies=function(deps){var f=deps&&deps.fetch||fetch;var p=deps&&deps.Promise||Promise;var socketCls=deps&&deps.WebSocket||WebSocket;return{newWebSocket:function(server,proto){return new socketCls(server,proto)},extension:deps&&deps.extension||defaultExtension,isArray:function(arr){return Array.isArray(arr)},webRTCAdapter:deps&&deps.adapter||adapter,httpAPICall:function(url,options){var fetchOptions={method:options.verb,headers:{Accept:"application/json, text/plain, */*"},cache:"no-cache"};if(options.verb==="POST"){fetchOptions.headers["Content-Type"]="application/json"}if(options.withCredentials!==undefined){fetchOptions.credentials=options.withCredentials===true?"include":options.withCredentials?options.withCredentials:"omit"}if(options.body!==undefined){fetchOptions.body=JSON.stringify(options.body)}var fetching=f(url,fetchOptions).catch(function(error){return p.reject({message:"Probably a network error, is the server down?",error:error})});if(options.timeout!==undefined){var timeout=new p(function(resolve,reject){var timerId=setTimeout(function(){clearTimeout(timerId);return reject({message:"Request timed out",timeout:options.timeout})},options.timeout)});fetching=p.race([fetching,timeout])}fetching.then(function(response){if(response.ok){if(typeof options.success===typeof Janus.noop){return response.json().then(function(parsed){options.success(parsed)}).catch(function(error){return p.reject({message:"Failed to parse response body",error:error,response:response})})}}else{return p.reject({message:"API call failed",response:response})}}).catch(function(error){if(typeof options.error===typeof Janus.noop){options.error(error.message||"<< internal error >>",error)}});return fetching}}};Janus.useOldDependencies=function(deps){var jq=deps&&deps.jQuery||jQuery;var socketCls=deps&&deps.WebSocket||WebSocket;return{newWebSocket:function(server,proto){return new socketCls(server,proto)},isArray:function(arr){return jq.isArray(arr)},extension:deps&&deps.extension||defaultExtension,webRTCAdapter:deps&&deps.adapter||adapter,httpAPICall:function(url,options){var payload=options.body!==undefined?{contentType:"application/json",data:JSON.stringify(options.body)}:{};var credentials=options.withCredentials!==undefined?{xhrFields:{withCredentials:options.withCredentials}}:{};return jq.ajax(jq.extend(payload,credentials,{url:url,type:options.verb,cache:false,dataType:"json",async:options.async,timeout:options.timeout,success:function(result){if(typeof options.success===typeof Janus.noop){options.success(result)}},