]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/js/unlimited_pizza/pepperoni.js
1 Class(UnlimitedPizza
, "Pepperoni").inherits(Widget
)({
3 <a class="record-button">⬤</a> \
4 <div class="record-info"> \
5 <div class="record-progress"> \
6 <div class="record-progress-bar-container"> \
7 <div class="record-progress-bar"></div> \
9 <a class="record-clear">X</a> \
11 <audio class="record-preview" controls></audio> \
14 PAUSE : '▐▐',
22 workerPath : '/js/vendor/recorderjs/recorderWorker.js',
23 init : function init(config
) {
24 Widget
.prototype.init
.call(this, config
);
27 this.context
= new (window
.AudioContext
|| window
.webkitAudioContext
)();
33 }, this._onUserMedia
.bind(this), this._onUserMediaError
.bind(this))
36 this.element
.html(this.constructor.INNER_HTML
);
38 this.controlButton
= this.element
.find('.record-button');
39 this.clearButton
= this.element
.find('.record-clear');
40 this.audioElement
= this.element
.find('audio');
41 this.progressBarContainer
= this.element
.find('.record-progress-bar-container');
42 this.progressBar
= this.element
.find('.record-progress-bar');
47 record : function record() {
48 if (this.recorder
&& !this.recording
) {
49 this._canRecord(function handleCanRecord(canRecord
) {
51 this.recording
= true;
52 this.controlButton
.addClass('recording')
53 this.controlButton
.html(this.constructor.PAUSE
);
54 this._interval
= setInterval(this._onRecordCheck
.bind(this), 100);
55 this.recorder
.record();
61 stop : function stop() {
62 if (this.recorder
&& this.recording
) {
63 this.recording
= false;
64 this.controlButton
.removeClass('recording')
65 this.controlButton
.html(this.constructor.RECORD
);
66 clearInterval(this._interval
);
68 this.recorder
.exportWAV();
72 clear : function clear() {
74 this.progressBar
.width(0);
75 this.audioElement
.attr('src', '');
76 this.audioElement
[0].load();
81 finalize : function finalize(callback
) {
83 this.recorder
.exportWAV(callback
);
87 getBuffer : function getBuffer(callback
) {
89 this.recorder
.getBuffer(callback
);
93 _bindEvents : function bindEvents() {
94 this.controlButton
.on('click', function () {
102 this.clearButton
.on('click', function () {
103 if (!this.recording
) {
109 _onRecording : function _onRecording(buffer
) {
110 this._buffer
= buffer
;
112 this.audioElement
.attr('src', URL
.createObjectURL(buffer
));
113 this.audioElement
[0].load();
116 _onUserMedia : function _onUserMedia(localMediaStream
) {
117 this.source
= this.context
.createMediaStreamSource(localMediaStream
);
118 this.recorder
= new Recorder(this.source
, {
119 workerPath : this.workerPath
,
120 callback : this._onRecording
.bind(this)
124 _onUserMediaError : function _onUserMediaError(error
) {
125 console
.log("Something went wrong", error
);
129 _onRecordCheck : function _onRecordCheck() {
130 this._canRecord(function (canRecord
, bufferSize
) {
131 var width
= bufferSize
* this.progressBarContainer
.width() / this.maxSize
;
132 this.progressBar
.width(width
);
139 _canRecord : function _canRecord(callback
) {
140 this.recorder
.getBuffer(function getBuffer(buffer
) {
141 var bufferSize
= buffer
[0].length
+ buffer
[1].length
;
142 callback
&& callback(bufferSize
<= this.maxSize
, bufferSize
);
146 // Normalize get user media
147 _getUserMedia : (navigator
.getUserMedia
||
148 navigator
.webkitGetUserMedia
||
149 navigator
.mozGetUserMedia
||
150 navigator
.msGetUserMedia
).bind(navigator
)