Skip to content

Instantly share code, notes, and snippets.

@bthesorceror
Forked from DamonOehlman/index.js
Created September 9, 2013 14:02
Show Gist options
  • Save bthesorceror/6495992 to your computer and use it in GitHub Desktop.
Save bthesorceror/6495992 to your computer and use it in GitHub Desktop.
requirebin sketch
// require the media capture helper from rtc.io
var media = require('rtc-media');
// capture video and render it to the document body
media().render(document.body);
require=function(e,t,n){function r(n,o){if(!t[n]){if(!e[n]){var s="function"==typeof require&&require;if(!o&&s)return s(n,!0);if(i)return i(n,!0);throw Error("Cannot find module '"+n+"'")}var a=t[n]={exports:{}};e[n][0].call(a.exports,function(t){var i=e[n][1][t];return r(i?i:t)},a,a.exports)}return t[n].exports}for(var i="function"==typeof require&&require,o=0;n.length>o;o++)r(n[o]);return r}({1:[function(e,t){var n=t.exports={};n.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){if(e.source===window&&"process-tick"===e.data&&(e.stopPropagation(),n.length>0)){var t=n.shift();t()}},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw Error("process.chdir is not supported")}},{}],2:[function(e,t,n){(function(e){function t(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0;e.length>n;n++)if(t===e[n])return n;return-1}e.EventEmitter||(e.EventEmitter=function(){});var r=n.EventEmitter=e.EventEmitter,i="function"==typeof Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},o=10;r.prototype.setMaxListeners=function(e){this._events||(this._events={}),this._events.maxListeners=e},r.prototype.emit=function(e){if("error"===e&&(!this._events||!this._events.error||i(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var t=this._events[e];if(!t)return!1;if("function"==typeof t){switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:var n=Array.prototype.slice.call(arguments,1);t.apply(this,n)}return!0}if(i(t)){for(var n=Array.prototype.slice.call(arguments,1),r=t.slice(),o=0,s=r.length;s>o;o++)r[o].apply(this,n);return!0}return!1},r.prototype.addListener=function(e,t){if("function"!=typeof t)throw Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",e,t),this._events[e])if(i(this._events[e])){if(!this._events[e].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:o,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),console.trace())}this._events[e].push(t)}else this._events[e]=[this._events[e],t];else this._events[e]=t;return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){var n=this;return n.on(e,function r(){n.removeListener(e,r),t.apply(this,arguments)}),this},r.prototype.removeListener=function(e,n){if("function"!=typeof n)throw Error("removeListener only takes instances of Function");if(!this._events||!this._events[e])return this;var r=this._events[e];if(i(r)){var o=t(r,n);if(0>o)return this;r.splice(o,1),0==r.length&&delete this._events[e]}else this._events[e]===n&&delete this._events[e];return this},r.prototype.removeAllListeners=function(e){return 0===arguments.length?(this._events={},this):(e&&this._events&&this._events[e]&&(this._events[e]=null),this)},r.prototype.listeners=function(e){return this._events||(this._events={}),this._events[e]||(this._events[e]=[]),i(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]}})(e("__browserify_process"))},{__browserify_process:1}],"rtc-media":[function(e,t){t.exports=e("Mmah7H")},{}],Mmah7H:[function(e,t){(function(){"use strict";function n(e){return this instanceof n?(s.call(this),e&&e instanceof MediaStream&&(e={stream:e,capture:!1,muted:!1}),e=r({},{capture:!0,muted:!0,constraints:{video:{mandatory:{},optional:[]},audio:!0}},e),this.constraints=e.constraints,this.name=e.name,this.stream=e.stream||null,this.muted=e.muted===void 0||e.muted,this._bindings=[],e.capture&&setTimeout(this.capture.bind(this),0),void 0):new n(e)}e("cog/logger")("media");var r=e("cog/extend"),i=e("cog/qsa"),o=e("rtc-core/detect"),s=e("events").EventEmitter,a=e("util");navigator.getUserMedia=o.call(navigator,"getUserMedia"),window.URL=window.URL||o("URL"),window.MediaStream=o("MediaStream"),a.inherits(n,s),t.exports=n,n.prototype.capture=function(e,t){var n=this,r=this.emit.bind(this,"end");this.stream||("function"==typeof e&&(t=e,e=this.constraints),"function"==typeof t&&this.once("capture",t.bind(this)),navigator.getUserMedia(e||this.constraints,function(e){"function"==typeof e.addEventListener?e.addEventListener("ended",r):e.onended=r,n.stream=e,n.emit("capture",e)},this._handleFail.bind(this)))},n.prototype.render=function(e,t,n){var r;return"function"==typeof t&&(n=t,t={}),t=t||{},e="string"==typeof e||e instanceof String?i(e):[].concat(e||[]),r=e.filter(Boolean).map(this._prepareElements.bind(this,t)),this.stream?this._bindStream(this.stream):this.once("capture",this._bindStream.bind(this)),"function"==typeof n&&this.once("render",n),r},n.prototype.start=function(){console.log("start method has been deprecated, please use capture instead"),this.capture.apply(this,arguments)},n.prototype.stop=function(e){var t=this;this.stream&&(this._unbind(e),this.stream.stop(),this.once("capture",t._bindStream.bind(t)),this.stream=null)},n.prototype._prepareElements=function(e,t){var n,r=t instanceof HTMLVideoElement||t instanceof HTMLAudioElement,i=e.preserveAspectRatio===void 0||e.preserveAspectRatio;return r=r||"function"==typeof t.play&&(t.mozSrcObject!==void 0||t.src!==void 0),r||(n=t,t=document.createElement("video"),i&&t.setAttribute("preserveAspectRatio",""),this.muted&&t.setAttribute("muted",""),n.appendChild(t),t.setAttribute("data-playing",!1)),this._bindings.push({el:t,opts:e}),t},n.prototype._bindStream=function(e){function t(){0===o.length&&i.length>0&&(r.emit("render",i),i.map(function(e){e.setAttribute("data-playing",!0)}))}function n(e){var r=i.indexOf(e.srcElement);r>=0&&o.splice(r,1),e.srcElement.removeEventListener("playing",n),t()}var r=this,i=[],o=[];i=this._bindings.map(function(t){return t.el.mozSrcObject!==void 0?t.el.mozSrcObject=e:t.el.src=r._createObjectURL(e)||e,"function"==typeof t.el.play&&t.el.play(),t.el}),o=i.filter(function(e){return 3>e.readyState}),o.map(function(e){e.addEventListener("playing",n,!1)}),t()},n.prototype._unbind=function(e){e=e||{},this._bindings.forEach(function(e){var t=e.el;t.src=null,t.mozSrcObject&&(t.mozSrcObject=null),t.currentSrc&&(t.currentSrc=null)})},n.prototype._createObjectURL=function(e){try{return window.URL.createObjectURL(e)}catch(t){}},n.prototype._handleSuccess=function(e){this.stream=e,this.emit("stream",e)},n.prototype._handleFail=function(){this.emit("error",Error("Unable to capture requested media"))}})()},{events:2,util:3,"cog/qsa":4,"cog/extend":5,"rtc-core/detect":6,"cog/logger":7}],3:[function(e,t,n){function r(e){return e instanceof Array||Array.isArray(e)||e&&e!==Object.prototype&&r(e.__proto__)}function i(e){return e instanceof RegExp||"object"==typeof e&&"[object RegExp]"===Object.prototype.toString.call(e)}function o(e){if(e instanceof Date)return!0;if("object"!=typeof e)return!1;var t=Date.prototype&&a(Date.prototype),n=e.__proto__&&a(e.__proto__);return JSON.stringify(n)===JSON.stringify(t)}e("events"),n.isArray=r,n.isDate=function(e){return"[object Date]"===Object.prototype.toString.call(e)},n.isRegExp=function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},n.print=function(){},n.puts=function(){},n.debug=function(){},n.inspect=function(e,t,c,u){function p(e,c){if(e&&"function"==typeof e.inspect&&e!==n&&(!e.constructor||e.constructor.prototype!==e))return e.inspect(c);switch(typeof e){case"undefined":return l("undefined","undefined");case"string":var u="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return l(u,"string");case"number":return l(""+e,"number");case"boolean":return l(""+e,"boolean")}if(null===e)return l("null","null");var d=s(e),h=t?a(e):d;if("function"==typeof e&&0===h.length){if(i(e))return l(""+e,"regexp");var v=e.name?": "+e.name:"";return l("[Function"+v+"]","special")}if(o(e)&&0===h.length)return l(e.toUTCString(),"date");var m,g,y;if(r(e)?(g="Array",y=["[","]"]):(g="Object",y=["{","}"]),"function"==typeof e){var _=e.name?": "+e.name:"";m=i(e)?" "+e:" [Function"+_+"]"}else m="";if(o(e)&&(m=" "+e.toUTCString()),0===h.length)return y[0]+m+y[1];if(0>c)return i(e)?l(""+e,"regexp"):l("[Object]","special");f.push(e);var b=h.map(function(t){var n,i;if(e.__lookupGetter__&&(e.__lookupGetter__(t)?i=e.__lookupSetter__(t)?l("[Getter/Setter]","special"):l("[Getter]","special"):e.__lookupSetter__(t)&&(i=l("[Setter]","special"))),0>d.indexOf(t)&&(n="["+t+"]"),i||(0>f.indexOf(e[t])?(i=null===c?p(e[t]):p(e[t],c-1),i.indexOf("\n")>-1&&(i=r(e)?i.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+i.split("\n").map(function(e){return" "+e}).join("\n"))):i=l("[Circular]","special")),n===void 0){if("Array"===g&&t.match(/^\d+$/))return i;n=JSON.stringify(""+t),n.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(n=n.substr(1,n.length-2),n=l(n,"name")):(n=n.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),n=l(n,"string"))}return n+": "+i});f.pop();var w=0,E=b.reduce(function(e,t){return w++,t.indexOf("\n")>=0&&w++,e+t.length+1},0);return b=E>50?y[0]+(""===m?"":m+"\n ")+" "+b.join(",\n ")+" "+y[1]:y[0]+m+" "+b.join(", ")+" "+y[1]}var f=[],l=function(e,t){var n={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},r={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[t];return r?"["+n[r][0]+"m"+e+"["+n[r][1]+"m":e};return u||(l=function(e){return e}),p(e,c===void 0?2:c)},n.log=function(){},n.pump=null;var s=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t},a=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.hasOwnProperty.call(e,n)&&t.push(n);return t},c=Object.create||function(e,t){var n;if(null===e)n={__proto__:null};else{if("object"!=typeof e)throw new TypeError("typeof prototype["+typeof e+"] != 'object'");var r=function(){};r.prototype=e,n=new r,n.__proto__=e}return t!==void 0&&Object.defineProperties&&Object.defineProperties(n,t),n};n.inherits=function(e,t){e.super_=t,e.prototype=c(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})};var u=/%[sdj%]/g;n.format=function(e){if("string"!=typeof e){for(var t=[],r=0;arguments.length>r;r++)t.push(n.inspect(arguments[r]));return t.join(" ")}for(var r=1,i=arguments,o=i.length,s=(e+"").replace(u,function(e){if("%%"===e)return"%";if(r>=o)return e;switch(e){case"%s":return i[r++]+"";case"%d":return Number(i[r++]);case"%j":return JSON.stringify(i[r++]);default:return e}}),a=i[r];o>r;a=i[++r])s+=null===a||"object"!=typeof a?" "+a:" "+n.inspect(a);return s}},{events:2}],4:[function(e,t){(function(){"use strict";var e=/^\.([\w\-]+)$/,n=/^#([\w\-]+)$/,r=/^[\w\-]+$/;t.exports=function(t,i){var o;return i=i||document,o=i===document&&n.test(t),o?[i.getElementById(RegExp.$1)]:Array.prototype.slice.call(e.test(t)?i.getElementsByClassName(RegExp.$1):r.test(t)?i.getElementsByTagName(t):i.querySelectorAll(t))}})()},{}],5:[function(e,t){"use strict";t.exports=function(e){return[].slice.call(arguments,1).forEach(function(t){if(t)for(var n in t)e[n]=t[n]}),e}},{}],6:[function(e,t){(function(){"use strict";var e=t.exports=function(t,n){var r,i,o,s=this||window;for(n=(n||["ms","o","moz","webkit"]).concat(""),r=n.length;r--;)if(i=n[r],o=i+(i?t.charAt(0).toUpperCase()+t.slice(1):t),s[o]!==void 0)return e.browser=e.browser||i.toLowerCase(),s[o]};e.moz=!!navigator.mozGetUserMedia,e.browser=void 0})()},{}],7:[function(e,t){"use strict";var n=[],r=[],i=[console],o=t.exports=function(e){function t(){return o=n.indexOf("*")>=0||n.indexOf(e)>=0}var o=t();return r[r.length]=t,function(){var t=[].slice.call(arguments);("string"==typeof t[0]||t[0]instanceof String)&&(t[0]=e+": "+t[0]),o&&i.forEach(function(e){e.log.apply(e,t)})}};o.reset=function(){return i=[],n=[],o.enable()},o.to=function(e){return i=i.concat(e||[]),o},o.enable=function(){return n=n.concat([].slice.call(arguments)),r.forEach(function(e){e()}),o}},{}]},{},[]);var media=require("rtc-media");media().render(document.body);
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment