Siddhant commited on
Commit
02e9ffc
1 Parent(s): 856ae16

Delete recorder.js

Browse files
Files changed (1) hide show
  1. recorder.js +0 -112
recorder.js DELETED
@@ -1,112 +0,0 @@
1
- // recorder.js
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- const BLOB_TYPE = "video/webm";
12
- class ScreenCastRecorder {
13
- /** True if the current browser likely supports screencasts. */
14
- static isSupportedBrowser() {
15
- return (navigator.mediaDevices != null &&
16
- navigator.mediaDevices.getUserMedia != null &&
17
- navigator.mediaDevices.getDisplayMedia != null &&
18
- MediaRecorder.isTypeSupported(BLOB_TYPE));
19
- }
20
- constructor({ recordAudio, onErrorOrStop }) {
21
- this.recordAudio = recordAudio;
22
- this.onErrorOrStopCallback = onErrorOrStop;
23
- this.inputStream = null;
24
- this.recordedChunks = [];
25
- this.mediaRecorder = null;
26
- }
27
- /**
28
- * This asynchronous method will initialize the screen recording object asking
29
- * for permissions to the user which are needed to start recording.
30
- */
31
- initialize() {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const desktopStream = yield navigator.mediaDevices.getDisplayMedia({
34
- video: true,
35
- });
36
- let tracks = desktopStream.getTracks();
37
- if (this.recordAudio) {
38
- const voiceStream = yield navigator.mediaDevices.getUserMedia({
39
- video: false,
40
- audio: true,
41
- });
42
- tracks = tracks.concat(voiceStream.getAudioTracks());
43
- }
44
- this.recordedChunks = [];
45
- this.inputStream = new MediaStream(tracks);
46
- this.mediaRecorder = new MediaRecorder(this.inputStream, {
47
- mimeType: BLOB_TYPE,
48
- });
49
- this.mediaRecorder.ondataavailable = e => this.recordedChunks.push(e.data);
50
- });
51
- }
52
- getState() {
53
- if (this.mediaRecorder) {
54
- return this.mediaRecorder.state;
55
- }
56
- return "inactive";
57
- }
58
- /**
59
- * This method will start the screen recording if the user has granted permissions
60
- * and the mediaRecorder has been initialized
61
- *
62
- * @returns {boolean}
63
- */
64
- start() {
65
- if (!this.mediaRecorder) {
66
- console.warn(`ScreenCastRecorder.start: mediaRecorder is null`);
67
- return false;
68
- }
69
- const logRecorderError = (e) => {
70
- console.warn(`mediaRecorder.start threw an error: ${e}`);
71
- };
72
- this.mediaRecorder.onerror = (e) => {
73
- logRecorderError(e);
74
- this.onErrorOrStopCallback();
75
- };
76
- this.mediaRecorder.onstop = () => this.onErrorOrStopCallback();
77
- try {
78
- this.mediaRecorder.start();
79
- }
80
- catch (e) {
81
- logRecorderError(e);
82
- return false;
83
- }
84
- return true;
85
- }
86
- /**
87
- * This method will stop recording and then return the generated Blob
88
- *
89
- * @returns {(Promise|undefined)}
90
- * A Promise which will return the generated Blob
91
- * Undefined if the MediaRecorder could not initialize
92
- */
93
- stop() {
94
- if (!this.mediaRecorder) {
95
- return undefined;
96
- }
97
- let resolver;
98
- const promise = new Promise(r => {
99
- resolver = r;
100
- });
101
- this.mediaRecorder.onstop = () => resolver();
102
- this.mediaRecorder.stop();
103
- if (this.inputStream) {
104
- this.inputStream.getTracks().forEach(s => s.stop());
105
- this.inputStream = null;
106
- }
107
- return promise.then(() => this.buildOutputBlob());
108
- }
109
- buildOutputBlob() {
110
- return new Blob(this.recordedChunks, { type: BLOB_TYPE });
111
- }
112
- }