This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 829
Use a local wrapper for Jitsi calls #4234
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Jitsi Wrapper | ||
|
||
**Note**: These are developer docs. Please consult your client's documentation for | ||
instructions on setting up Jitsi. | ||
|
||
The react-sdk wraps all Jitsi call widgets in a local wrapper called `jitsi.html` | ||
which takes several parameters: | ||
|
||
*Query string*: | ||
* `widgetId`: The ID of the widget. This is needed for communication back to the | ||
react-sdk. | ||
* `parentUrl`: The URL of the parent window. This is also needed for | ||
communication back to the react-sdk. | ||
|
||
*Hash/fragment (formatted as a query string)*: | ||
* `conferenceDomain`: The domain to connect Jitsi Meet to. | ||
* `conferenceId`: The room or conference ID to connect Jitsi Meet to. | ||
* `isAudioOnly`: Boolean for whether this is a voice-only conference. May not | ||
be present, should default to `false`. | ||
* `displayName`: The display name of the user viewing the widget. May not | ||
be present or could be null. | ||
* `avatarUrl`: The HTTP(S) URL for the avatar of the user viewing the widget. May | ||
not be present or could be null. | ||
* `userId`: The MXID of the user viewing the widget. May not be present or could | ||
be null. | ||
|
||
The react-sdk will assume that `jitsi.html` is at the path of wherever it is currently | ||
being served. For example, `https://riot.im/develop/jitsi.html` or `vector://webapp/jitsi.html`. | ||
|
||
The `jitsi.html` wrapper can use the react-sdk's `WidgetApi` to communicate, making | ||
it easier to actually implement the feature. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
Copyright 2020 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Dev note: This is largely inspired by Dimension. Used with permission. | ||
// /~https://github.com/turt2live/matrix-dimension/blob/4f92d560266635e5a3c824606215b84e8c0b19f5/web/app/shared/services/scalar/scalar-widget.api.ts | ||
|
||
import { randomString } from "matrix-js-sdk/src/randomstring"; | ||
|
||
export enum Capability { | ||
Screenshot = "m.capability.screenshot", | ||
Sticker = "m.sticker", | ||
AlwaysOnScreen = "m.always_on_screen", | ||
} | ||
|
||
export enum KnownWidgetActions { | ||
GetSupportedApiVersions = "supported_api_versions", | ||
TakeScreenshot = "screenshot", | ||
GetCapabilities = "capabilities", | ||
SendEvent = "send_event", | ||
UpdateVisibility = "visibility", | ||
ReceiveOpenIDCredentials = "openid_credentials", | ||
SetAlwaysOnScreen = "set_always_on_screen", | ||
} | ||
export type WidgetAction = KnownWidgetActions | string; | ||
|
||
export enum WidgetApiType { | ||
ToWidget = "toWidget", | ||
FromWidget = "fromWidget", | ||
} | ||
|
||
export interface WidgetRequest { | ||
api: WidgetApiType; | ||
widgetId: string; | ||
requestId: string; | ||
data: any; | ||
action: WidgetAction; | ||
} | ||
|
||
export interface ToWidgetRequest extends WidgetRequest { | ||
api: WidgetApiType.ToWidget; | ||
} | ||
|
||
export interface FromWidgetRequest extends WidgetRequest { | ||
api: WidgetApiType.FromWidget; | ||
response: any; | ||
} | ||
|
||
/** | ||
* Handles Riot <--> Widget interactions for embedded/standalone widgets. | ||
*/ | ||
export class WidgetApi { | ||
private origin: string; | ||
private inFlightRequests: {[requestId: string]: (reply: FromWidgetRequest) => void} = {}; | ||
private readyPromise: Promise<any>; | ||
private readyPromiseResolve: () => void; | ||
|
||
constructor(currentUrl: string, private widgetId: string, private requestedCapabilities: string[]) { | ||
this.origin = new URL(currentUrl).origin; | ||
|
||
this.readyPromise = new Promise<any>(resolve => this.readyPromiseResolve = resolve); | ||
|
||
window.addEventListener("message", event => { | ||
if (event.origin !== this.origin) return; // ignore: invalid origin | ||
if (!event.data) return; // invalid schema | ||
if (event.data.widgetId !== this.widgetId) return; // not for us | ||
|
||
const payload = <WidgetRequest>event.data; | ||
if (payload.api === WidgetApiType.ToWidget && payload.action) { | ||
console.log(`[WidgetAPI] Got request: ${JSON.stringify(payload)}`); | ||
|
||
if (payload.action === KnownWidgetActions.GetCapabilities) { | ||
this.onCapabilitiesRequest(<ToWidgetRequest>payload); | ||
this.readyPromiseResolve(); | ||
} else { | ||
console.warn(`[WidgetAPI] Got unexpected action: ${payload.action}`); | ||
} | ||
} else if (payload.api === WidgetApiType.FromWidget && this.inFlightRequests[payload.requestId]) { | ||
console.log(`[WidgetAPI] Got reply: ${JSON.stringify(payload)}`); | ||
const handler = this.inFlightRequests[payload.requestId]; | ||
delete this.inFlightRequests[payload.requestId]; | ||
handler(<FromWidgetRequest>payload); | ||
} else { | ||
console.warn(`[WidgetAPI] Unhandled payload: ${JSON.stringify(payload)}`); | ||
} | ||
}); | ||
} | ||
|
||
public waitReady(): Promise<any> { | ||
return this.readyPromise; | ||
} | ||
|
||
private replyToRequest(payload: ToWidgetRequest, reply: any) { | ||
if (!window.parent) return; | ||
|
||
const request = JSON.parse(JSON.stringify(payload)); | ||
request.response = reply; | ||
|
||
window.parent.postMessage(request, this.origin); | ||
} | ||
|
||
private onCapabilitiesRequest(payload: ToWidgetRequest) { | ||
return this.replyToRequest(payload, {capabilities: this.requestedCapabilities}); | ||
} | ||
|
||
public callAction(action: WidgetAction, payload: any, callback: (reply: FromWidgetRequest) => void) { | ||
if (!window.parent) return; | ||
|
||
const request: FromWidgetRequest = { | ||
api: WidgetApiType.FromWidget, | ||
widgetId: this.widgetId, | ||
action: action, | ||
requestId: randomString(160), | ||
data: payload, | ||
response: {}, // Not used at this layer - it's used when the client responds | ||
}; | ||
this.inFlightRequests[request.requestId] = callback; | ||
|
||
console.log(`[WidgetAPI] Sending request: `, request); | ||
window.parent.postMessage(request, "*"); | ||
} | ||
|
||
public setAlwaysOnScreen(onScreen: boolean): Promise<any> { | ||
return new Promise<any>(resolve => { | ||
this.callAction(KnownWidgetActions.SetAlwaysOnScreen, {value: onScreen}, resolve); | ||
}); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these logs safe to keep in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they're already made by existing managers and Riot.