This repository has been archived by the owner on May 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
169 lines (159 loc) · 5.7 KB
/
background.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
async function start(videoId) {
function setRecorder(videoId, recorder) {
try {
if (GlobalRecorder == undefined || GlobalRecorder == null) {
GlobalRecorder = new Object()
}
} catch (e) {
if (e instanceof ReferenceError) {
GlobalRecorder = new Object()
}
}
GlobalRecorder[videoId] = recorder
}
let videos = document.querySelector(`div[data-ssrc="${videoId}"]`)
let video
if (videos == null) {
return false
}
videos = videos.childNodes
if (videos.length == 0) {
return false
}
if (videos.length == 2) {
if (videos[0] == undefined && videos[1] == undefined) {
return false
}
video = videos[0] != undefined ? videos[0].srcObject : videos[1].srcObject
} else {
video = videos[0].srcObject
}
const recorder = new RecordRTCPromisesHandler(video, {
type: 'video',
mimeType: 'video/webm;codecs=vp8,opus'
})
recorder.startRecording()
setRecorder(videoId, recorder)
chrome.storage.local.get('recordingIds', function (result) {
if (result.recordingIds == undefined) {
chrome.storage.local.set({ recordingIds: [videoId] }, () => { });
} else {
if (typeof result.recordingIds != 'object') {
chrome.storage.local.remove(['recordingIds'], function () {
const error = chrome.runtime.lastError;
if (error) {
console.error(error);
return
}
chrome.storage.local.set({ recordingIds: [videoId] }, () => { });
})
} else {
const ids = result.recordingIds
console.log(ids);
ids.push(videoId)
chrome.storage.local.set({ recordingIds: ids }, () => { });
}
}
});
return true
}
async function stop(videoId) {
function getRecorder(videoId) {
if (GlobalRecorder != undefined || GlobalRecorder != null) {
return GlobalRecorder[videoId]
}
return null
}
const recorder = getRecorder(videoId)
if (recorder != null) {
await recorder.stopRecording()
getSeekableBlob(await recorder.getBlob(), function (seekableBlob) {
invokeSaveAsDialog(seekableBlob);
})
chrome.storage.local.get(['recordingIds'], function (result) {
const ids = result.recordingIds
var index = ids.indexOf(videoId);
if (index >= 0) {
ids.splice(index, 1);
}
chrome.storage.local.set({ recordingIds: ids });
});
return true
} else {
sendResponse({
resp: `Video Not On for ${request.videoId}`,
isRecording: false
});
}
return false
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch (request.task) {
case 'get_participants':
chrome.windows.getCurrent(w => {
chrome.tabs.query({ active: true, windowId: w.id }, tabs => {
const currTab = tabs[0];
if (currTab) {
chrome.scripting.executeScript({
target: { tabId: currTab.id },
files: ['content-script.js']
});
}
});
});
sendResponse({ resp: 'Sending Participants' });
break;
case 'start_recording':
chrome.windows.getCurrent(w => {
chrome.tabs.query({ active: true, windowId: w.id }, tabs => {
const currTab = tabs[0];
if (currTab) {
chrome.storage.local.remove('recordingIds')
chrome.scripting.executeScript({
target: { tabId: currTab.id },
func: start,
args: [request.videoId]
}, async (res) => {
if (!res) {
sendResponse({
resp: `Video Not On for ${request.videoId}`,
isRecording: false
});
} else {
sendResponse({
resp: `Video Recording On for ${request.videoId}`,
isRecording: true
});
}
});
}
});
});
break;
case 'stop_recording':
chrome.windows.getCurrent(w => {
chrome.tabs.query({ active: true, windowId: w.id }, tabs => {
const currTab = tabs[0];
if (currTab) {
chrome.scripting.executeScript({
target: { tabId: currTab.id },
func: stop,
args: [request.videoId]
}, async (res) => {
if (res) {
sendResponse({
resp: `Video stopped for ${request.videoId}`,
isRecording: false
});
} else {
}
});
}
});
});
break;
default:
break;
}
return true
});