-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
60 lines (49 loc) · 1.78 KB
/
main.js
File metadata and controls
60 lines (49 loc) · 1.78 KB
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
window.addEventListener("load", () => {
let rpcExtensionId = config.rpcExtension.id.chrome;
if (typeof browser !== "undefined" && typeof chrome !== "undefined") {
rpcExtensionId = config.rpcExtension.id.firefox;
}
// Register Presence
chrome.runtime.sendMessage(rpcExtensionId, { mode: "active" }, function(response) {
console.log("Presence registered", response);
});
// Wait for presence Requests
chrome.runtime.onMessage.addListener(function(info, sender, sendResponse) {
if (info.action == messageType.RPC) {
console.info("Presence requested", info);
let buttons = [];
let isPaused = getIsPaused();
let endTimestamp = undefined;
if (!(isPaused ?? true)) {
let remainingTime = getRemainingTime();
if (remainingTime !== undefined) endTimestamp = Math.round(Date.now() + remainingTime);
}
let stateImageKey = undefined, stateImageText = undefined;
if (endTimestamp !== undefined) {
stateImageKey = config.echo360_app.imageKeys.state.playing;
stateImageText = "playing";
} else if (isPaused) {
stateImageKey = config.echo360_app.imageKeys.state.paused;
stateImageText = "paused";
}
let viewURL = getLectureLink();
if (viewURL !== undefined) buttons.push({
label: "View Lecture",
url: viewURL,
});
sendResponse({
clientId: config.echo360_app.id,
presence: {
details: getCourseName(),
state: getLectureName(),
largeImageKey: "echo360",
largeImageText: "echo360",
smallImageKey: stateImageKey,
smallImageText: stateImageText,
endTimestamp: endTimestamp,
buttons: buttons.length > 0 ? buttons : undefined,
},
});
}
});
});