PageSourceSearch

https://app.ringostat.com/static/js/vendors/audio/recorder/recorder.js?version=20210920

js ringostat.com collected 2026-09-24 08:41:43 UTC 2,644 bytes, 89 lines download raw bytes

1(function(window) {
2
3    var WORKER_PATH = '/static/js/vendors/audio/recorder/recorderWorker.js';
4
5    var Recorder = function(source, cfg) {
6        var config = cfg || {};
7        var bufferLen = config.bufferLen || 4096;
8        this.context = source.context;
9        this.node = this.context.createScriptProcessor(bufferLen, 2, 2);
10        var worker = new Worker(config.workerPath || WORKER_PATH);
11        worker.postMessage({
12            command: 'init',
13            config: {
14                sampleRate: this.context.sampleRate
15            }
16        });
17        var recording = false,
18                currCallback;
19
20        this.node.onaudioprocess = function(e) {
21            if (!recording)
22                return;
23            worker.postMessage({
24                command: 'record',
25                buffer: [
26                    e.inputBuffer.getChannelData(0),
27                    e.inputBuffer.getChannelData(1)
28                ]
29            });
30        };
31
32        this.configure = function(cfg) {
33            for (var prop in cfg) {
34                if (cfg.hasOwnProperty(prop)) {
35                    config[prop] = cfg[prop];
36                }
37            }
38        };
39
40        this.record = function() {
41            recording = true;
42        };
43
44        this.stop = function() {
45            recording = false;
46        };
47
48        this.clear = function() {
49            worker.postMessage({command: 'clear'});
50        };
51
52        this.getBuffer = function(cb) {
53            currCallback = cb || config.callback;
54            worker.postMessage({command: 'getBuffer'});
55        };
56
57        this.exportWAV = function(cb, type) {
58            currCallback = cb || config.callback;
59            type = type || config.type || 'audio/wav';
60            if (!currCallback)
61                throw new Error('Callback not set');
62            worker.postMessage({
63                command: 'exportWAV',
64                type: type
65            });
66        };
67
68        worker.onmessage = function(e) {
69            var blob = e.data;
70            currCallback(blob);
71        };
72
73        source.connect(this.node);
74        this.node.connect(this.context.destination);    //this should not be necessary
75    };
76
77    Recorder.forceDownload = function(blob, filename) {
78        var url = (window.URL || window.webkitURL).createObjectURL(blob);
79        var link = window.document.createElement('a');
80        link.href = url;
81        link.download = filename || 'output.wav';
82        var click = document.createEvent("Event");
83        click.initEvent("click", true, true);
84        link.dispatchEvent(click);
85    };
86
87    window.Recorder = Recorder;
88
89})(window);

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.