vendor: 4,794 bytes, lines 1-148
1(function(e){if("function"==typeof bootstrap)bootstrap("hark",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeHark=e}else"undefined"!=typeof window?window.hark=e():global.hark=e()})(function(){var define,ses,bootstrap,module,exports; 2return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){ 3var WildEmitter = require('wildemitter'); 4 5function getMaxVolume (analyser, fftBins) { 6 var maxVolume = -Infinity; 7 analyser.getFloatFrequencyData(fftBins); 8 9 for(var i=4, ii=fftBins.length; i < ii; i++) { 10 if (fftBins[i] > maxVolume && fftBins[i] < 0) { 11 maxVolume = fftBins[i]; 12 } 13 }; 14 15 return maxVolume; 16} 17 18 19var audioContextType; 20if (typeof window !== 'undefined') { 21 audioContextType = window.AudioContext || window.webkitAudioContext; 22} 23// use a single audio context due to hardware limits 24var audioContext = null; 25module.exports = function(stream, options) { 26 var harker = new WildEmitter(); 27 28 // make it not break in non-supported browsers 29 if (!audioContextType) return harker; 30 31 //Config 32 var options = options || {}, 33 smoothing = (options.smoothing || 0.1), 34 interval = (options.interval || 50), 35 threshold = options.threshold, 36 play = options.play, 37 history = options.history || 10, 38 running = true; 39 40 // Ensure that just a single AudioContext is internally created 41 audioContext = options.audioContext || audioContext || new audioContextType(); 42 43 var sourceNode, fftBins, analyser; 44 45 analyser = audioContext.createAnalyser(); 46 analyser.fftSize = 512; 47 analyser.smoothingTimeConstant = smoothing; 48 fftBins = new Float32Array(analyser.frequencyBinCount); 49 50 if (stream.jquery) stream = stream[0]; 51 if (stream instanceof HTMLAudioElement || stream instanceof HTMLVideoElement) { 52 //Audio Tag 53 sourceNode = audioContext.createMediaElementSource(stream); 54 if (typeof play === 'undefined') play = true; 55 threshold = threshold || -50; 56 } else { 57 //WebRTC Stream 58 sourceNode = audioContext.createMediaStreamSource(stream); 59 threshold = threshold || -50; 60 } 61 62 sourceNode.connect(analyser); 63 if (play) analyser.connect(audioContext.destination); 64 65 harker.speaking = false; 66 67 harker.suspend = function() { 68 return audioContext.suspend(); 69 } 70 harker.resume = function() { 71 return audioContext.resume(); 72 } 73 Object.defineProperty(harker, 'state', { get: function() { 74 return audioContext.state; 75 }}); 76 audioContext.onstatechange = function() { 77 harker.emit('state_change', audioContext.state); 78 } 79 80 harker.setThreshold = function(t) { 81 threshold = t; 82 }; 83 84 harker.setInterval = function(i) { 85 interval = i; 86 }; 87 88 harker.stop = function() { 89 running = false; 90 harker.emit('volume_change', -100, threshold); 91 if (harker.speaking) { 92 harker.speaking = false; 93 harker.emit('stopped_speaking'); 94 } 95 analyser.disconnect(); 96 sourceNode.disconnect(); 97 }; 98 harker.speakingHistory = []; 99 for (var i = 0; i < history; i++) { 100 harker.speakingHistory.push(0); 101 } 102 103 // Poll the analyser node to determine if speaking 104 // and emit events if changed 105 var looper = function() { 106 setTimeout(function() { 107 108 //check if stop has been called 109 if(!running) { 110 return; 111 } 112 113 var currentVolume = getMaxVolume(analyser, fftBins); 114 115 harker.emit('volume_change', currentVolume, threshold); 116 117 var history = 0; 118 if (currentVolume > threshold && !harker.speaking) { 119 // trigger quickly, short history 120 for (var i = harker.speakingHistory.length - 3; i < harker.speakingHistory.length; i++) { 121 history += harker.speakingHistory[i]; 122 } 123 if (history >= 2) { 124 harker.speaking = true; 125 harker.emit('speaking'); 126 } 127 } else if (currentVolume < threshold && harker.speaking) { 128 for (var i = 0; i < harker.speakingHistory.length; i++) { 129 history += harker.speakingHistory[i]; 130 } 131 if (history == 0) { 132 harker.speaking = false; 133 harker.emit('stopped_speaking'); 134 } 135 } 136 harker.speakingHistory.shift(); 137 harker.speakingHistory.push(0 + (currentVolume > threshold)); 138 139 looper(); 140 }, interval); 141 }; 142 looper(); 143 144 return harker; 145} 146 147},{"wildemitter":2}],2:[function(require,module,exports){ 148/*
vendor: 4,466 bytes, lines 148-291
148 149WildEmitter.js is a slim little event emitter by @henrikjoreteg largely based 150on @visionmedia's Emitter from UI Kit. 151 152Why? I wanted it standalone. 153 154I also wanted support for wildcard emitters like this: 155 156emitter.on('*', function (eventName, other, event, payloads) { 157 158}); 159 160emitter.on('somenamespace*', function (eventName, payloads) { 161 162}); 163 164Please note that callbacks triggered by wildcard registered events also get 165the event name as the first argument. 166*/ 167 168module.exports = WildEmitter; 169 170function WildEmitter() { } 171 172WildEmitter.mixin = function (constructor) { 173 var prototype = constructor.prototype || constructor; 174 175 prototype.isWildEmitter= true; 176 177 // Listen on the given `event` with `fn`. Store a group name if present. 178 prototype.on = function (event, groupName, fn) { 179 this.callbacks = this.callbacks || {}; 180 var hasGroup = (arguments.length === 3), 181 group = hasGroup ? arguments[1] : undefined, 182 func = hasGroup ? arguments[2] : arguments[1]; 183 func._groupName = group; 184 (this.callbacks[event] = this.callbacks[event] || []).push(func); 185 return this; 186 }; 187 188 // Adds an `event` listener that will be invoked a single 189 // time then automatically removed. 190 prototype.once = function (event, groupName, fn) { 191 var self = this, 192 hasGroup = (arguments.length === 3), 193 group = hasGroup ? arguments[1] : undefined, 194 func = hasGroup ? arguments[2] : arguments[1]; 195 function on() { 196 self.off(event, on); 197 func.apply(this, arguments); 198 } 199 this.on(event, group, on); 200 return this; 201 }; 202 203 // Unbinds an entire group 204 prototype.releaseGroup = function (groupName) { 205 this.callbacks = this.callbacks || {}; 206 var item, i, len, handlers; 207 for (item in this.callbacks) { 208 handlers = this.callbacks[item]; 209 for (i = 0, len = handlers.length; i < len; i++) { 210 if (handlers[i]._groupName === groupName) { 211 //console.log('removing'); 212 // remove it and shorten the array we're looping through 213 handlers.splice(i, 1); 214 i--; 215 len--; 216 } 217 } 218 } 219 return this; 220 }; 221 222 // Remove the given callback for `event` or all 223 // registered callbacks. 224 prototype.off = function (event, fn) { 225 this.callbacks = this.callbacks || {}; 226 var callbacks = this.callbacks[event], 227 i; 228 229 if (!callbacks) return this; 230 231 // remove all handlers 232 if (arguments.length === 1) { 233 delete this.callbacks[event]; 234 return this; 235 } 236 237 // remove specific handler 238 i = callbacks.indexOf(fn); 239 callbacks.splice(i, 1); 240 if (callbacks.length === 0) { 241 delete this.callbacks[event]; 242 } 243 return this; 244 }; 245 246 /// Emit `event` with the given args. 247 // also calls any `*` handlers 248 prototype.emit = function (event) { 249 this.callbacks = this.callbacks || {}; 250 var args = [].slice.call(arguments, 1), 251 callbacks = this.callbacks[event], 252 specialCallbacks = this.getWildcardCallbacks(event), 253 i, 254 len, 255 item, 256 listeners; 257 258 if (callbacks) { 259 listeners = callbacks.slice(); 260 for (i = 0, len = listeners.length; i < len; ++i) { 261 if (!listeners[i]) { 262 break; 263 } 264 listeners[i].apply(this, args); 265 } 266 } 267 268 if (specialCallbacks) { 269 len = specialCallbacks.length; 270 listeners = specialCallbacks.slice(); 271 for (i = 0, len = listeners.length; i < len; ++i) { 272 if (!listeners[i]) { 273 break; 274 } 275 listeners[i].apply(this, [event].concat(args)); 276 } 277 } 278 279 return this; 280 }; 281 282 // Helper for for finding special wildcard event handlers that match the event 283 prototype.getWildcardCallbacks = function (eventName) { 284 this.callbacks = this.callbacks || {}; 285 var item, 286 split, 287 result = []; 288 289 for (item in this.callbacks) { 290 split = item.split('*'); 291 if (item === '*' || (split.length === 2 && eventName.slice(0, split[0].length) === split[0])
291) { 292 result = result.concat(this.callbacks[item]); 293 } 294 } 295 return result; 296 }; 297 298}; 299 300WildEmitter.mixin(WildEmitter); 301 302},{}]},{},[1])(1) 303}); 304;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.