Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
importScripts("sessionGrabber.js");
// Chrome runs this file as a service worker, which pulls in its siblings itself.
// Firefox has no background service workers and runs it as an event page
// instead, with sessionGrabber.js already loaded from background.scripts.
if (typeof importScripts === "function") {
importScripts("sessionGrabber.js");
}

chrome.runtime.onMessageExternal.addListener(function (msg, sender, sendResponse) {
if (msg.ping && msg.ping == 'hello') {
sendResponse({pong: "hello"});
// Messages from remote-sli.de. Chrome lets the site send them here directly
// (externally_connectable); Firefox doesn't let web pages message an extension
// at all, so there util/siteBridge.js relays what the site posts to its window.
function handleSiteMessage(msg, sendResponse) {
if (msg.session) {
grabSession(msg.session);
}
// Always answer: the site closes the tab it opened for a session once it hears back
sendResponse(msg.ping == 'hello' ? {pong: "hello"} : {});
}

function isSiteSender(sender) {
try {
var host = new URL(sender.url).hostname;
return host == "remote-sli.de" || host.endsWith(".remote-sli.de");
} catch (ignored) {
return false;
}
}

chrome.runtime.onMessageExternal.addListener(function (msg, sender, sendResponse) {
handleSiteMessage(msg, sendResponse);
});

// The badge belongs to the tab the controller runs in. Messages from the injected
Expand All @@ -27,6 +50,9 @@ function setRemoteCountBadge(sender, data) {

// Handle messages from the pageController script
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.action == 'siteMessage' && isSiteSender(sender)) {
handleSiteMessage(msg.message || {}, sendResponse);
}
if (msg.action == 'socketEvent') {
var event = msg.event;
var data = msg.data;
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
var app = angular.module("app", []);

// Shown in the session's connection info, so tell the two builds apart
var INJECTOR = chrome.runtime.getURL("").indexOf("moz-extension:") === 0 ? "extension_firefox" : "extension_chrome";

// chrome.tabs.getSelected is gone in MV3; the popup always belongs to the current window.
function withActiveTab(callback) {
chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
Expand Down Expand Up @@ -71,7 +74,7 @@ app.controller("mainCtrl", function ($scope, $timeout) {
},
args: [{
session: $scope.session.session,
injector: 'extension_chrome'
injector: INJECTOR
}]
});
}).then(function () {
Expand Down
2 changes: 1 addition & 1 deletion inject/controller
Submodule controller updated 1 files
+5 −0 pageController.js
28 changes: 26 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
"version": "1.2.0",
"author": "inventivetalent",
"homepage_url": "https://remote-sli.de",
"minimum_chrome_version": "102",
"minimum_chrome_version": "121",
"browser_specific_settings": {
"gecko": {
"id": "remoteslide@inventivetalent.org",
"strict_min_version": "140.0",
"data_collection_permissions": {
"required": [
"websiteContent"
]
}
}
},
"action": {
"default_icon": "img/logo-128.png",
"default_popup": "index.html"
Expand All @@ -32,7 +43,11 @@
"extension_pages": "script-src 'self'; object-src 'self'"
},
"background": {
"service_worker": "background.js"
"service_worker": "background.js",
"scripts": [
"sessionGrabber.js",
"background.js"
]
},
"content_scripts": [
{
Expand All @@ -54,6 +69,15 @@
"util/preziInjector.js"
],
"all_frames": true
},
{
"matches": [
"*://*.remote-sli.de/*"
],
"js": [
"util/siteBridge.js"
],
"run_at": "document_start"
}
],
"web_accessible_resources": [
Expand Down
44 changes: 21 additions & 23 deletions sessionGrabber.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
console.log("Waiting for session message...")
chrome.runtime.onMessageExternal.addListener(function (msg, sender, sendResponse) {
if (msg.session) {
console.log("Session msg: " + JSON.stringify(msg))
chrome.storage.local.get(["session"], function (items) {
var oldSession = items.session;
// Stores a session that remote-sli.de handed over (see handleSiteMessage in background.js)
function grabSession(session) {
console.log("Session msg: " + JSON.stringify(session))
chrome.storage.local.get(["session"], function (items) {
var oldSession = items.session;

msg.session.sessionTime = new Date().valueOf();
chrome.storage.local.set({"session": msg.session});
if (!oldSession || oldSession.session != msg.session.session) {
console.log("notification created")
chrome.notifications.create('new-session-created-notification', {
type: 'basic',
iconUrl: 'img/logo-128.png',
title: 'Session Updated',
message: 'A new session has been created\n' +
'Click the icon to start presenting!',
contextMessage: msg.session.session
}, function (notificationId) {
});
}
});
}
});
session.sessionTime = new Date().valueOf();
chrome.storage.local.set({"session": session});
if (!oldSession || oldSession.session != session.session) {
console.log("notification created")
chrome.notifications.create('new-session-created-notification', {
type: 'basic',
iconUrl: 'img/logo-128.png',
title: 'Session Updated',
message: 'A new session has been created\n' +
'Click the icon to start presenting!',
contextMessage: session.session
}, function (notificationId) {
});
}
});
}
20 changes: 20 additions & 0 deletions util/siteBridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Firefox has no externally_connectable, so remote-sli.de can't message the
// extension the way it does in Chrome. Instead it posts the same messages to its
// own window, and this relays them to the background and posts the answers back:
// page -> {channel: "remoteslide", direction: "to-extension", id, message}
// page <- {channel: "remoteslide", direction: "to-page", id, response}
window.addEventListener("message", function (event) {
var data = event.data;
if (event.source !== window || !data || data.channel !== "remoteslide" || data.direction !== "to-extension") {
return;
}
chrome.runtime.sendMessage({action: "siteMessage", message: data.message}, function (response) {
void chrome.runtime.lastError;
window.postMessage({
channel: "remoteslide",
direction: "to-page",
id: data.id,
response: response
}, window.location.origin);
});
});