brave/brave-talk

Add calendar extension for Brave Talk on Google Calendar

mrose17 opened this issue · 9 comments

This is a fork/branch of the Jitsi calendar plugin in order to add a Brave Talk confab URL to a calendar entry. The idea is to put the CRX file on Brave Talk so folks who use Google Calendar can add a confab URL to the calendar invite, e.g.,
Screen Shot 2021-11-16 at 17 22 14
Screen Shot 2021-11-16 at 17 22 40
(Note that the icons are still Jitsi icons. These will be updated to Brave Talk icons soon.)

It turns out this is fairly straight-forward, so i've bumped the priority.

Now onto the design for phase 2: having the plugin "schedule" a room for subscribers, so they get moderator privileges!

Creating the Room with Moderator Privileges

Context

Making use of the mechanics implemented for the /talk slack plugin (i.e. passing the create=y query parameter), it is possible for this chrome extension to generate a room name which will get created on first use, without any communication with talk.brave.com. This is what @mrose17 described as "turns out this is fairly straight-forward".

However, that approach comes with a significant limitation: the first subscriber to enter the room is the one who gains moderator privileges. We would obviously prefer the person who scheduled the call to have those privileges.

In order to achieve that, due to the unique privacy-focused model of talk:

  1. the user's issued credentials need to be presented to the create room api call. These credentials are only present in talk.brave.com's localStorage.
  2. the resulting jwt and refresh token need to be stored in talk.brave.com's localStorage.

Investigation 1

Use message passing to initiate room creation within the context of talk.brave.com.

Extensions communicate between their (global) service worker and content scripts injected to specific pages using the sendMessage api as described here.

However, on talk.brave.com we want to invoke the existing code within the page that creats a room. Standard web pages cannot participate in the extension-specific sendMessage api, so we need to inject a content script to talk.brave.com and convert those messages to postMessage calls, as described here. This results in a setup like this:

image
[diagram link]

Most of this is pretty simple and I've successfully prototyped much of it. The mechanics between steps 4 and 5 are ugly and error prone as postMessage is totally asynchronous and unlike sendMessage cannot return a response, so the content script injected into talk.brave.com would need to cache callbacks in order to tie up with the request from step 3.

However, dealing with failure cases is even more complex, the most obvious being that the user is not logged in as a subscriber. We can only discover this between steps 4 and 5, at which point presenting a UI to the user to login is difficult, as the tab will be in the background.

Here is the "final" product... thank you @tackley

Screen Shot 2022-02-14 at 14 45 50

Looks and works great for me from talk.brave.software using

Brave 1.36.90 Chromium: 98.0.4758.87 (Official Build) beta (64-bit)
Revision e4cd00f135fb4d8edc64c8aa6ecbe7cc79ebb3b2-refs/branch-heads/4758@{#1002}
OS Windows 10 Version 21H2 (Build 19044.1526)
example example example example example
brave-talk-calendar-1 brave-talk-calendar-2 brave-talk-calendar-3 brave-talk-calendar-4 brave-talk-calendar-5

Fixed by #176

Filed brave/brave-talk-gcalendar-extension#13 on the Brave Talk icon-transparency issue in the Google Chrome Store.