forked from estacionckweb/ckweb-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
executable file
·10888 lines (9640 loc) · 404 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
function audioPlayer(opts) {
this.file = opts.file
this.container = opts.container
this.isPlaying = false
var audio = new Audio(opts.stream)
console.log('audio is', audio)
this.audio = audio
var buttonHolder = document.createElement('div')
buttonHolder.setAttribute('class', 'button-holder')
var self = this
buttonHolder.onclick = () => {
console.log(audio.paused)
if(audio.paused){
self.play()
} else {
self.pause()
}
}
opts.container.appendChild(buttonHolder)
this.playButton = document.createElement('div')
this.playButton.setAttribute('class', 'play-button audio-player-button')
buttonHolder.appendChild(this.playButton)
this.pauseButton = document.createElement('div')
this.pauseButton.setAttribute('class', 'pause-button audio-player-button')
buttonHolder.appendChild(this.pauseButton)
this.pause()
}
audioPlayer.prototype.play = function () {
this.pauseButton.style.display = 'block'
this.playButton.style.display = 'none'
this.audio.play()
this.onPlay()
}
audioPlayer.prototype.pause = function() {
this.playButton.style.display = 'block'
this.pauseButton.style.display = 'none'
this.audio.pause()
this.onPause()
}
audioPlayer.prototype.onPlay = () => {}
audioPlayer.prototype.onPause = () => {}
module.exports = audioPlayer
},{}],2:[function(require,module,exports){
const Hydra = require('hydra-synth')
var loop = require('raf-loop')
function hydraBackground({ canvas, initialAnimationDuration }) {
var self = this
this.hydra = new Hydra({
canvas: canvas,
autoLoop: false,
detectAudio: false
})
console.log("hydra is", this.hydra)
this.engine = loop(function(dt) {
// delta time in milliseconds
self.hydra.tick(dt)
}).start()
osc(80, 0.02, 1.4)
.rotate(0.1, -0.008)
.pixelate(50, 20)
.diff(o0)
.luma(0.1)
.scale(1.01)
.out()
setTimeout(() => this.engine.stop(), initialAnimationDuration)
//self.hydra.tick(0.01)
}
hydraBackground.prototype.play = function () {
this.engine.start()
}
hydraBackground.prototype.pause = function() {
this.engine.stop()
}
module.exports = hydraBackground
},{"hydra-synth":8,"raf-loop":29}],3:[function(require,module,exports){
const AudioPlayer = require('./audioPlayer.js')
const VideoPlayer = require('./videoPlayer.js')
const HydraBackground = require('./hydraBackground.js')
var canvas = document.getElementById("hydra")
canvas.width = window.innerWidth
canvas.height = window.innerHeight
//alert("hi")
var hydra = new HydraBackground({
canvas: canvas,
initialAnimationDuration: 300
})
var audio = new AudioPlayer({
stream: "http://domolleno2018.out.airtime.pro:8000/domolleno2018_a",
type: "application/ogg",
container: document.getElementById("player")
})
audio.onPlay = () => { hydra.play() }
audio.onPause = () => { hydra.pause() }
},{"./audioPlayer.js":1,"./hydraBackground.js":2,"./videoPlayer.js":4}],4:[function(require,module,exports){
function videoPlayer(opts) {
console.log('stream', opts)
this.stream = opts.stream
this.container = opts.container
this.isPlaying = false
this.player = document.createElement('video')
this.player.src = this.stream
this.player.controls = true
this.player.width = window.innerWidth
this.player.height = window.innerHeight
this.player.onplay = () => {
console.log("play!")
this.player.style.position = 'absolute'
this.player.style.zIndex = 100
}
this.player.onpause = () => {
console.log("pause!")
this.player.style.position = 'static'
}
this.container.appendChild(this.player)
}
// audioPlayer.prototype.play = function () {
// this.pauseButton.style.display = 'block'
// this.playButton.style.display = 'none'
// this.audio.play()
// this.onPlay()
// }
//
// audioPlayer.prototype.pause = function() {
// this.playButton.style.display = 'block'
// this.pauseButton.style.display = 'none'
// this.audio.pause()
// this.onPause()
// }
//
// audioPlayer.prototype.onPlay = () => {}
//
// audioPlayer.prototype.onPause = () => {}
module.exports = videoPlayer
},{}],5:[function(require,module,exports){
module.exports = function (cb) {
if (typeof Promise !== 'function') {
var err = new Error('Device enumeration not supported.');
err.kind = 'METHOD_NOT_AVAILABLE';
if (cb) {
console.warn('module now uses promise based api - callback is deprecated');
return cb(err);
}
throw err;
}
return new Promise(function(resolve, reject) {
var processDevices = function (devices) {
var normalizedDevices = [];
for (var i = 0; i < devices.length; i++) {
var device = devices[i];
//make chrome values match spec
var kind = device.kind || null;
if (kind && kind.toLowerCase() === 'audio') {
kind = 'audioinput';
} else if (kind && kind.toLowerCase() === 'video') {
kind = 'videoinput';
}
normalizedDevices.push({
facing: device.facing || null,
deviceId: device.id || device.deviceId || null,
label: device.label || null,
kind: kind,
groupId: device.groupId || null
});
}
resolve(normalizedDevices);
if (cb) {
console.warn('module now uses promise based api - callback is deprecated');
cb(null, normalizedDevices);
}
};
if (window.navigator && window.navigator.mediaDevices && window.navigator.mediaDevices.enumerateDevices) {
window.navigator.mediaDevices.enumerateDevices().then(processDevices);
} else if (window.MediaStreamTrack && window.MediaStreamTrack.getSources) {
window.MediaStreamTrack.getSources(processDevices);
} else {
var err = new Error('Device enumeration not supported.');
err.kind = 'METHOD_NOT_AVAILABLE';
reject(err);
if (cb) {
console.warn('module now uses promise based api - callback is deprecated');
cb(err);
}
}
});
};
},{}],6:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var objectCreate = Object.create || objectCreatePolyfill
var objectKeys = Object.keys || objectKeysPolyfill
var bind = Function.prototype.bind || functionBindPolyfill
function EventEmitter() {
if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
this._events = objectCreate(null);
this._eventsCount = 0;
}
this._maxListeners = this._maxListeners || undefined;
}
module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
var defaultMaxListeners = 10;
var hasDefineProperty;
try {
var o = {};
if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
hasDefineProperty = o.x === 0;
} catch (err) { hasDefineProperty = false }
if (hasDefineProperty) {
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
enumerable: true,
get: function() {
return defaultMaxListeners;
},
set: function(arg) {
// check whether the input is a positive number (whose value is zero or
// greater and not a NaN).
if (typeof arg !== 'number' || arg < 0 || arg !== arg)
throw new TypeError('"defaultMaxListeners" must be a positive number');
defaultMaxListeners = arg;
}
});
} else {
EventEmitter.defaultMaxListeners = defaultMaxListeners;
}
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
if (typeof n !== 'number' || n < 0 || isNaN(n))
throw new TypeError('"n" argument must be a positive number');
this._maxListeners = n;
return this;
};
function $getMaxListeners(that) {
if (that._maxListeners === undefined)
return EventEmitter.defaultMaxListeners;
return that._maxListeners;
}
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
return $getMaxListeners(this);
};
// These standalone emit* functions are used to optimize calling of event
// handlers for fast cases because emit() itself often has a variable number of
// arguments and can be deoptimized because of that. These functions always have
// the same number of arguments and thus do not get deoptimized, so the code
// inside them can execute faster.
function emitNone(handler, isFn, self) {
if (isFn)
handler.call(self);
else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
listeners[i].call(self);
}
}
function emitOne(handler, isFn, self, arg1) {
if (isFn)
handler.call(self, arg1);
else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
listeners[i].call(self, arg1);
}
}
function emitTwo(handler, isFn, self, arg1, arg2) {
if (isFn)
handler.call(self, arg1, arg2);
else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
listeners[i].call(self, arg1, arg2);
}
}
function emitThree(handler, isFn, self, arg1, arg2, arg3) {
if (isFn)
handler.call(self, arg1, arg2, arg3);
else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
listeners[i].call(self, arg1, arg2, arg3);
}
}
function emitMany(handler, isFn, self, args) {
if (isFn)
handler.apply(self, args);
else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
listeners[i].apply(self, args);
}
}
EventEmitter.prototype.emit = function emit(type) {
var er, handler, len, args, i, events;
var doError = (type === 'error');
events = this._events;
if (events)
doError = (doError && events.error == null);
else if (!doError)
return false;
// If there is no 'error' event listener then throw.
if (doError) {
if (arguments.length > 1)
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
} else {
// At least give some kind of context to the user
var err = new Error('Unhandled "error" event. (' + er + ')');
err.context = er;
throw err;
}
return false;
}
handler = events[type];
if (!handler)
return false;
var isFn = typeof handler === 'function';
len = arguments.length;
switch (len) {
// fast cases
case 1:
emitNone(handler, isFn, this);
break;
case 2:
emitOne(handler, isFn, this, arguments[1]);
break;
case 3:
emitTwo(handler, isFn, this, arguments[1], arguments[2]);
break;
case 4:
emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
break;
// slower
default:
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
emitMany(handler, isFn, this, args);
}
return true;
};
function _addListener(target, type, listener, prepend) {
var m;
var events;
var existing;
if (typeof listener !== 'function')
throw new TypeError('"listener" argument must be a function');
events = target._events;
if (!events) {
events = target._events = objectCreate(null);
target._eventsCount = 0;
} else {
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (events.newListener) {
target.emit('newListener', type,
listener.listener ? listener.listener : listener);
// Re-assign `events` because a newListener handler could have caused the
// this._events to be assigned to a new object
events = target._events;
}
existing = events[type];
}
if (!existing) {
// Optimize the case of one listener. Don't need the extra array object.
existing = events[type] = listener;
++target._eventsCount;
} else {
if (typeof existing === 'function') {
// Adding the second element, need to change to array.
existing = events[type] =
prepend ? [listener, existing] : [existing, listener];
} else {
// If we've already got an array, just append.
if (prepend) {
existing.unshift(listener);
} else {
existing.push(listener);
}
}
// Check for listener leak
if (!existing.warned) {
m = $getMaxListeners(target);
if (m && m > 0 && existing.length > m) {
existing.warned = true;
var w = new Error('Possible EventEmitter memory leak detected. ' +
existing.length + ' "' + String(type) + '" listeners ' +
'added. Use emitter.setMaxListeners() to ' +
'increase limit.');
w.name = 'MaxListenersExceededWarning';
w.emitter = target;
w.type = type;
w.count = existing.length;
if (typeof console === 'object' && console.warn) {
console.warn('%s: %s', w.name, w.message);
}
}
}
}
return target;
}
EventEmitter.prototype.addListener = function addListener(type, listener) {
return _addListener(this, type, listener, false);
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.prependListener =
function prependListener(type, listener) {
return _addListener(this, type, listener, true);
};
function onceWrapper() {
if (!this.fired) {
this.target.removeListener(this.type, this.wrapFn);
this.fired = true;
switch (arguments.length) {
case 0:
return this.listener.call(this.target);
case 1:
return this.listener.call(this.target, arguments[0]);
case 2:
return this.listener.call(this.target, arguments[0], arguments[1]);
case 3:
return this.listener.call(this.target, arguments[0], arguments[1],
arguments[2]);
default:
var args = new Array(arguments.length);
for (var i = 0; i < args.length; ++i)
args[i] = arguments[i];
this.listener.apply(this.target, args);
}
}
}
function _onceWrap(target, type, listener) {
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
var wrapped = bind.call(onceWrapper, state);
wrapped.listener = listener;
state.wrapFn = wrapped;
return wrapped;
}
EventEmitter.prototype.once = function once(type, listener) {
if (typeof listener !== 'function')
throw new TypeError('"listener" argument must be a function');
this.on(type, _onceWrap(this, type, listener));
return this;
};
EventEmitter.prototype.prependOnceListener =
function prependOnceListener(type, listener) {
if (typeof listener !== 'function')
throw new TypeError('"listener" argument must be a function');
this.prependListener(type, _onceWrap(this, type, listener));
return this;
};
// Emits a 'removeListener' event if and only if the listener was removed.
EventEmitter.prototype.removeListener =
function removeListener(type, listener) {
var list, events, position, i, originalListener;
if (typeof listener !== 'function')
throw new TypeError('"listener" argument must be a function');
events = this._events;
if (!events)
return this;
list = events[type];
if (!list)
return this;
if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
this._events = objectCreate(null);
else {
delete events[type];
if (events.removeListener)
this.emit('removeListener', type, list.listener || listener);
}
} else if (typeof list !== 'function') {
position = -1;
for (i = list.length - 1; i >= 0; i--) {
if (list[i] === listener || list[i].listener === listener) {
originalListener = list[i].listener;
position = i;
break;
}
}
if (position < 0)
return this;
if (position === 0)
list.shift();
else
spliceOne(list, position);
if (list.length === 1)
events[type] = list[0];
if (events.removeListener)
this.emit('removeListener', type, originalListener || listener);
}
return this;
};
EventEmitter.prototype.removeAllListeners =
function removeAllListeners(type) {
var listeners, events, i;
events = this._events;
if (!events)
return this;
// not listening for removeListener, no need to emit
if (!events.removeListener) {
if (arguments.length === 0) {
this._events = objectCreate(null);
this._eventsCount = 0;
} else if (events[type]) {
if (--this._eventsCount === 0)
this._events = objectCreate(null);
else
delete events[type];
}
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
var keys = objectKeys(events);
var key;
for (i = 0; i < keys.length; ++i) {
key = keys[i];
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = objectCreate(null);
this._eventsCount = 0;
return this;
}
listeners = events[type];
if (typeof listeners === 'function') {
this.removeListener(type, listeners);
} else if (listeners) {
// LIFO order
for (i = listeners.length - 1; i >= 0; i--) {
this.removeListener(type, listeners[i]);
}
}
return this;
};
function _listeners(target, type, unwrap) {
var events = target._events;
if (!events)
return [];
var evlistener = events[type];
if (!evlistener)
return [];
if (typeof evlistener === 'function')
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
}
EventEmitter.prototype.listeners = function listeners(type) {
return _listeners(this, type, true);
};
EventEmitter.prototype.rawListeners = function rawListeners(type) {
return _listeners(this, type, false);
};
EventEmitter.listenerCount = function(emitter, type) {
if (typeof emitter.listenerCount === 'function') {
return emitter.listenerCount(type);
} else {
return listenerCount.call(emitter, type);
}
};
EventEmitter.prototype.listenerCount = listenerCount;
function listenerCount(type) {
var events = this._events;
if (events) {
var evlistener = events[type];
if (typeof evlistener === 'function') {
return 1;
} else if (evlistener) {
return evlistener.length;
}
}
return 0;
}
EventEmitter.prototype.eventNames = function eventNames() {
return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
};
// About 1.5x faster than the two-arg version of Array#splice().
function spliceOne(list, index) {
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
list[i] = list[k];
list.pop();
}
function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
copy[i] = arr[i];
return copy;
}
function unwrapListeners(arr) {
var ret = new Array(arr.length);
for (var i = 0; i < ret.length; ++i) {
ret[i] = arr[i].listener || arr[i];
}
return ret;
}
function objectCreatePolyfill(proto) {
var F = function() {};
F.prototype = proto;
return new F;
}
function objectKeysPolyfill(obj) {
var keys = [];
for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
keys.push(k);
}
return k;
}
function functionBindPolyfill(context) {
var fn = this;
return function () {
return fn.apply(context, arguments);
};
}
},{}],7:[function(require,module,exports){
// getUserMedia helper by @HenrikJoreteg used for navigator.getUserMedia shim
var adapter = require('webrtc-adapter');
module.exports = function (constraints, cb) {
var error;
var haveOpts = arguments.length === 2;
var defaultOpts = {video: true, audio: true};
var denied = 'PermissionDeniedError';
var altDenied = 'PERMISSION_DENIED';
var notSatisfied = 'ConstraintNotSatisfiedError';
// make constraints optional
if (!haveOpts) {
cb = constraints;
constraints = defaultOpts;
}
// treat lack of browser support like an error
if (typeof navigator === 'undefined' || !navigator.getUserMedia) {
// throw proper error per spec
error = new Error('MediaStreamError');
error.name = 'NotSupportedError';
// keep all callbacks async
return setTimeout(function () {
cb(error);
}, 0);
}
// normalize error handling when no media types are requested
if (!constraints.audio && !constraints.video) {
error = new Error('MediaStreamError');
error.name = 'NoMediaRequestedError';
// keep all callbacks async
return setTimeout(function () {
cb(error);
}, 0);
}
navigator.mediaDevices.getUserMedia(constraints)
.then(function (stream) {
cb(null, stream);
}).catch(function (err) {
var error;
// coerce into an error object since FF gives us a string
// there are only two valid names according to the spec
// we coerce all non-denied to "constraint not satisfied".
if (typeof err === 'string') {
error = new Error('MediaStreamError');
if (err === denied || err === altDenied) {
error.name = denied;
} else {
error.name = notSatisfied;
}
} else {
// if we get an error object make sure '.name' property is set
// according to spec: http://dev.w3.org/2011/webrtc/editor/getusermedia.html#navigatorusermediaerror-and-navigatorusermediaerrorcallback
error = err;
if (!error.name) {
// this is likely chrome which
// sets a property called "ERROR_DENIED" on the error object
// if so we make sure to set a name
if (error[denied]) {
err.name = denied;
} else {
err.name = notSatisfied;
}
}
}
cb(error);
});
};
},{"webrtc-adapter":34}],8:[function(require,module,exports){
const Output = require('./src/output.js')
const loop = require('raf-loop')
const Source = require('./src/hydra-source.js')
const GeneratorFactory = require('./src/GeneratorFactory.js')
const getUserMedia = require('getusermedia')
const mouse = require('mouse-change')()
const Audio = require('./src/audio.js')
const VidRecorder = require('./src/video-recorder.js')
// to do: add ability to pass in certain uniforms and transforms
class HydraSynth {
constructor ({
pb = null,
width = 1280,
height = 720,
numSources = 4,
numOutputs = 4,
makeGlobal = true,
autoLoop = true,
detectAudio = true,
enableStreamCapture = true,
canvas
} = {}) {
this.bpm = 60
this.pb = pb
this.width = width
this.height = height
this.time = 0
this.makeGlobal = makeGlobal
this.renderAll = false
this.detectAudio = detectAudio
// boolean to store when to save screenshot
this.saveFrame = false
// if stream capture is enabled, this object contains the capture stream
this.captureStream = null
this._initCanvas(canvas)
this._initRegl()
this._initOutputs(numOutputs)
this._initSources(numSources)
this._generateGlslTransforms()
window.screencap = () => {
this.saveFrame = true
}
if (enableStreamCapture) {
this.captureStream = this.canvas.captureStream(25)
// to do: enable capture stream of specific sources and outputs
window.vidRecorder = new VidRecorder(this.captureStream)
}
if(detectAudio) this._initAudio()
//if(makeGlobal) {
window.mouse = mouse
window.time = this.time
window['render'] = this.render.bind(this)
// window.bpm = this.bpm
window.bpm = this._setBpm.bind(this)
// }
if(autoLoop) loop(this.tick.bind(this)).start()
}
getScreenImage(callback) {
this.imageCallback = callback
this.saveFrame = true
}
canvasToImage (callback) {
const a = document.createElement('a')
a.style.display = 'none'
let d = new Date()
a.download = `hydra-${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}-${d.getHours()}.${d.getMinutes()}.${d.getSeconds()}.png`
document.body.appendChild(a)
var self = this
this.canvas.toBlob( (blob) => {
// var url = window.URL.createObjectURL(blob)
if(self.imageCallback){
self.imageCallback(blob)
delete self.imageCallback
} else {
a.href = URL.createObjectURL(blob)
console.log(a.href)
a.click()
}
}, 'image/png')
setTimeout(() => {
document.body.removeChild(a);
window.URL.revokeObjectURL(a.href);
}, 300);
}
_initAudio () {
this.audio = new Audio({
numBins: 4
})
if(this.makeGlobal) window.a = this.audio
}
// create main output canvas and add to screen
_initCanvas (canvas) {
if (canvas) {
this.canvas = canvas
this.width = canvas.width
this.height = canvas.height
} else {
this.canvas = document.createElement('canvas')
this.canvas.width = this.width
this.canvas.height = this.height
this.canvas.style.width = '100%'
this.canvas.style.height = '100%'
document.body.appendChild(this.canvas)
}
}
_initRegl () {
this.regl = require('regl')({
canvas: this.canvas,
pixelRatio: 1,
extensions: [
'oes_texture_half_float',
'oes_texture_half_float_linear'
],
optionalExtensions: [
'oes_texture_float',
'oes_texture_float_linear'
]})
// This clears the color buffer to black and the depth buffer to 1
this.regl.clear({
color: [0, 0, 0, 1]
})
this.renderAll = this.regl({
frag: `
precision mediump float;
varying vec2 uv;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;
void main () {
vec2 st = vec2(1.0 - uv.x, uv.y);
st*= vec2(2);
vec2 q = floor(st).xy*(vec2(2.0, 1.0));
int quad = int(q.x) + int(q.y);
st.x += step(1., mod(st.y,2.0));
st.y += step(1., mod(st.x,2.0));
st = fract(st);
if(quad==0){
gl_FragColor = texture2D(tex0, st);
} else if(quad==1){
gl_FragColor = texture2D(tex1, st);
} else if (quad==2){
gl_FragColor = texture2D(tex2, st);
} else {
gl_FragColor = texture2D(tex3, st);
}
}
`,
vert: `
precision mediump float;
attribute vec2 position;
varying vec2 uv;
void main () {