cleanup changes godot->sdk add docs

This commit is contained in:
Timo K
2025-12-01 14:05:41 +01:00
parent 0664af0f1b
commit 1490359e4c
12 changed files with 66 additions and 38 deletions

View File

@@ -1,14 +0,0 @@
## url parameters
widgetId = $matrix_widget_id
perParticipantE2EE = true
userId = $matrix_user_id
deviceId = $org.matrix.msc3819.matrix_device_id
baseUrl = $org.matrix.msc4039.matrix_base_url
parentUrl = // will be inserted automatically
http://localhost?widgetId=&perParticipantE2EE=true&userId=&deviceId=&baseUrl=&roomId=
->
http://localhost:3000?widgetId=$matrix_widget_id&perParticipantE2EE=true&userId=$matrix_user_id&deviceId=$org.matrix.msc3819.matrix_device_id&baseUrl=$org.matrix.msc4039.matrix_base_url&roomId=$matrix_room_id

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -43,15 +43,5 @@
<% if (packageType !== "full") { %> <% if (packageType !== "full") { %>
<div id="root"></div> <div id="root"></div>
<% } %> <% } %>
<!-- Godot export -->
<% if (packageType === "godot") { %>
<canvas id="canvas"></canvas>
<script src="$GODOT_URL"></script>
<script>
var engine = new Engine($GODOT_CONFIG);
engine.startGame();
</script>
<% } %>
</body> </body>
</html> </html>

View File

@@ -13,8 +13,8 @@
"build:embedded": "yarn build:full --config vite-embedded.config.js", "build:embedded": "yarn build:full --config vite-embedded.config.js",
"build:embedded:production": "yarn build:embedded", "build:embedded:production": "yarn build:embedded",
"build:embedded:development": "yarn build:embedded --mode development", "build:embedded:development": "yarn build:embedded --mode development",
"build:godot": "yarn build:full --config vite-godot.config.js", "build:sdk": "yarn build:full --config vite-sdk.config.js",
"build:godot:development": "yarn build:godot --mode development", "build:sdk:development": "yarn build:sdk --mode development",
"serve": "vite preview", "serve": "vite preview",
"prettier:check": "prettier -c .", "prettier:check": "prettier -c .",
"prettier:format": "prettier -w .", "prettier:format": "prettier -w .",

35
sdk/README.md Normal file
View File

@@ -0,0 +1,35 @@
# SDK mode
EC can be build in sdk mode. This will result in a compiled js file that can be imported in very simple webapps.
It allows to use matrixRTC in combination with livekit without relying on element call.
This is done by instantiating the call view model and exposing some useful behaviors (observables) and methods.
This folder contains an example index.html file that showcases the sdk in use (hosted on localhost:8123 with a webserver ellowing cors (for example `npx serve -l 81234 --cors`)) as a godot engine HTML export template.
## Widgets
The sdk mode is particularly interesting to be used in widgets where you do not need to pay attention to matrix login/cs api ...
To create a widget see the example index.html file in this folder. And add it to EW via:
`/addwidget <widgetUrl>` (see **url parameters** for more details on `<widgetUrl>`)
### url parameters
```
widgetId = $matrix_widget_id
perParticipantE2EE = true
userId = $matrix_user_id
deviceId = $org.matrix.msc3819.matrix_device_id
baseUrl = $org.matrix.msc4039.matrix_base_url
```
`parentUrl = // will be inserted automatically`
Full template use as `<widgetUrl>`:
```
http://localhost:3000?widgetId=$matrix_widget_id&perParticipantE2EE=true&userId=$matrix_user_id&deviceId=$org.matrix.msc3819.matrix_device_id&baseUrl=$org.matrix.msc4039.matrix_base_url&roomId=$matrix_room_id
```
the `$` prefixed variables will be replaced by EW on widget instantiation. (e.g. `$matrix_user_id` -> `@user:example.com` (url encoding will also be applied automatically by EW) -> `%40user%3Aexample.com`)

View File

@@ -5,6 +5,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details. Please see LICENSE in the repository root for full details.
*/ */
/**
* This file contains helper functions and types for the MatrixRTC SDK.
*/
import { logger as rootLogger } from "matrix-js-sdk/lib/logger"; import { logger as rootLogger } from "matrix-js-sdk/lib/logger";
import { scan } from "rxjs"; import { scan } from "rxjs";

View File

@@ -4,8 +4,8 @@
<title>Godot MatrixRTC Widget</title> <title>Godot MatrixRTC Widget</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<script type="module"> <script type="module">
// TODO use the url where the matrixrtc-ec-godot.js file from dist is hosted // TODO use the url where the matrixrtc-sdk.js file from dist is hosted
import { createMatrixRTCSdk } from "http://localhost:8123/matrixrtc-ec-godot.js"; import { createMatrixRTCSdk } from "http://localhost:8123/matrixrtc-sdk.js";
try { try {
console.log("Hello from index.html"); console.log("Hello from index.html");

View File

@@ -5,7 +5,19 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details. Please see LICENSE in the repository root for full details.
*/ */
// import { type InitResult } from "../src/ClientContext"; /**
* This file is the entrypoint for the sdk build of element call: `yarn build:sdk`
* use in widgets.
* It exposes the `createMatrixRTCSdk` which creates the `MatrixRTCSdk` interface (see below) that
* can be used to join a rtc session and exchange realtime data.
* It takes care of all the tricky bits:
* - sending delayed events
* - finding the right sfu
* - handling the media stream
* - sending join/leave state or sticky events
* - setting up encryption and scharing keys
*/
import { map, type Observable, of, Subject, switchMap, tap } from "rxjs"; import { map, type Observable, of, Subject, switchMap, tap } from "rxjs";
import { MatrixRTCSessionEvent } from "matrix-js-sdk/lib/matrixrtc"; import { MatrixRTCSessionEvent } from "matrix-js-sdk/lib/matrixrtc";
import { type TextStreamInfo } from "livekit-client/dist/src/room/types"; import { type TextStreamInfo } from "livekit-client/dist/src/room/types";
@@ -40,6 +52,7 @@ interface MatrixRTCSdk {
members$: Behavior<MatrixLivekitMember[]>; members$: Behavior<MatrixLivekitMember[]>;
sendData?: (data: unknown) => Promise<void>; sendData?: (data: unknown) => Promise<void>;
} }
export async function createMatrixRTCSdk(): Promise<MatrixRTCSdk> { export async function createMatrixRTCSdk(): Promise<MatrixRTCSdk> {
logger.info("Hello"); logger.info("Hello");
const client = await widget.client; const client = await widget.client;

View File

@@ -262,8 +262,8 @@ export interface CallViewModel {
participantCount$: Behavior<number>; participantCount$: Behavior<number>;
/** Participants sorted by livekit room so they can be used in the audio rendering */ /** Participants sorted by livekit room so they can be used in the audio rendering */
livekitRoomItems$: Behavior<LivekitRoomItem[]>; livekitRoomItems$: Behavior<LivekitRoomItem[]>;
/** use the layout instead, this is just for the godot export. */
userMedia$: Behavior<UserMedia[]>; userMedia$: Behavior<UserMedia[]>;
/** use the layout instead, this is just for the sdk export. */
matrixLivekitMembers$: Behavior<MatrixLivekitMember[]>; matrixLivekitMembers$: Behavior<MatrixLivekitMember[]>;
localMatrixLivekitMember$: Behavior<LocalMatrixLivekitMember | null>; localMatrixLivekitMember$: Behavior<LocalMatrixLivekitMember | null>;
/** List of participants raising their hand */ /** List of participants raising their hand */

View File

@@ -54,7 +54,7 @@
"./src/**/*.ts", "./src/**/*.ts",
"./src/**/*.tsx", "./src/**/*.tsx",
"./playwright/**/*.ts", "./playwright/**/*.ts",
"./godot/**/*.ts" "./sdk/**/*.ts"
], ],
"exclude": ["**.test.ts"] "exclude": ["**.test.ts"]
} }

View File

@@ -14,17 +14,17 @@ const base = "./";
// Config for embedded deployments (possibly hosted under a non-root path) // Config for embedded deployments (possibly hosted under a non-root path)
export default defineConfig((env) => export default defineConfig((env) =>
mergeConfig( mergeConfig(
fullConfig({ ...env, packageType: "godot" }), fullConfig({ ...env, packageType: "sdk" }),
defineConfig({ defineConfig({
base, // Use relative URLs to allow the app to be hosted under any path base, // Use relative URLs to allow the app to be hosted under any path
// publicDir: false, // Don't serve the public directory which only contains the favicon // publicDir: false, // Don't serve the public directory which only contains the favicon
build: { build: {
manifest: true, manifest: true,
lib: { lib: {
entry: "./godot/main.ts", entry: "./sdk/main.ts",
name: "matrixrtc-ec-godot", name: "matrixrtc-sdk",
// the proper extensions will be added // the proper extensions will be added
fileName: "matrixrtc-ec-godot", fileName: "matrixrtc-sdk",
}, },
}, },
plugins: [nodePolyfills()], plugins: [nodePolyfills()],

View File

@@ -27,7 +27,7 @@ import * as fs from "node:fs";
export default ({ export default ({
mode, mode,
packageType, packageType,
}: ConfigEnv & { packageType?: "full" | "embedded" | "godot" }): UserConfig => { }: ConfigEnv & { packageType?: "full" | "embedded" | "sdk" }): UserConfig => {
const env = loadEnv(mode, process.cwd()); const env = loadEnv(mode, process.cwd());
// Environment variables with the VITE_ prefix are accessible at runtime. // Environment variables with the VITE_ prefix are accessible at runtime.
// So, we set this to allow for build/package specific behavior. // So, we set this to allow for build/package specific behavior.
@@ -68,7 +68,7 @@ export default ({
plugins.push( plugins.push(
createHtmlPlugin({ createHtmlPlugin({
entry: packageType === "godot" ? "godot/main.ts" : "src/main.tsx", entry: packageType === "sdk" ? "sdk/main.ts" : "src/main.tsx",
inject: { inject: {
data: { data: {
brand: env.VITE_PRODUCT_NAME || "Element Call", brand: env.VITE_PRODUCT_NAME || "Element Call",
@@ -126,7 +126,7 @@ export default ({
return "assets/[name]-[hash][extname]"; return "assets/[name]-[hash][extname]";
}, },
manualChunks: manualChunks:
packageType !== "godot" packageType !== "sdk"
? { ? {
// we should be able to remove this one https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/167 lands // we should be able to remove this one https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/167 lands
"matrix-sdk-crypto-wasm": [ "matrix-sdk-crypto-wasm": [