-
Notifications
You must be signed in to change notification settings - Fork 181
Element Call SDK target #3600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Element Call SDK target #3600
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
28158bf
temp
toger5 2d8ffc0
almost mvp
toger5 284a52c
mvp
toger5 0664af0
log cleanup and expose members$
toger5 1490359
cleanup changes `godot`->`sdk` add docs
toger5 af47002
Refactor local membership publisher and connectionState related logic
toger5 43266e6
Merge branch 'livekit' into toger5/lib-ec-version
toger5 ab675cf
fix test caused by `remoteParticipantsWithTracks`->`remoteParticipants`
toger5 f76a6cb
cleanup unnecassary packages + add connected indicator
toger5 93de12d
cleanup vite.configs and simplify exported sdk props.
toger5 8110d22
fix lint
toger5 b34a75d
fix knip
toger5 e4fee45
allow to use custom applications
toger5 68a32fd
Merge branch 'livekit' into toger5/lib-ec-version
toger5 c1c73b0
lint
toger5 e78f37a
Merge branch 'livekit' into toger5/lib-ec-version
toger5 852d2ee
after merge cleanup
toger5 725ff31
reduce PR diff
toger5 150dda1
fix lint
toger5 9bd7888
copyright.
toger5 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 hidden or 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 hidden or 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 hidden or 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,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`) |
This file contains hidden or 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,55 @@ | ||
| /* | ||
| Copyright 2025 New Vector Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
| 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 { scan } from "rxjs"; | ||
|
|
||
| import { widget as _widget } from "../src/widget"; | ||
| import { type LivekitRoomItem } from "../src/state/CallViewModel/CallViewModel"; | ||
|
|
||
| export const logger = rootLogger.getChild("[MatrixRTCSdk]"); | ||
|
|
||
| if (!_widget) throw Error("No widget. This webapp can only start as a widget"); | ||
| export const widget = _widget; | ||
|
|
||
| export const tryMakeSticky = (): void => { | ||
| logger.info("try making sticky MatrixRTCSdk"); | ||
| void widget.api | ||
| .setAlwaysOnScreen(true) | ||
| .then(() => { | ||
| logger.info("sticky MatrixRTCSdk"); | ||
| }) | ||
| .catch((error) => { | ||
| logger.error("failed to make sticky MatrixRTCSdk", error); | ||
| }); | ||
| }; | ||
| export const TEXT_LK_TOPIC = "matrixRTC"; | ||
| /** | ||
| * simple helper operator to combine the last emitted and the current emitted value of a rxjs observable | ||
| * | ||
| * I think there should be a builtin for this but i did not find it... | ||
| */ | ||
| export const currentAndPrev = scan< | ||
| LivekitRoomItem[], | ||
| { | ||
| prev: LivekitRoomItem[]; | ||
| current: LivekitRoomItem[]; | ||
| } | ||
| >( | ||
| ({ current: lastCurrentVal }, items) => ({ | ||
| prev: lastCurrentVal, | ||
| current: items, | ||
| }), | ||
| { | ||
| prev: [], | ||
| current: [], | ||
| }, | ||
| ); | ||
This file contains hidden or 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,87 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>Godot MatrixRTC Widget</title> | ||
| <meta charset="utf-8" /> | ||
| <script type="module"> | ||
| // TODO use the url where the matrixrtc-sdk.js file from dist is hosted | ||
| import { createMatrixRTCSdk } from "http://localhost:8123/matrixrtc-sdk.js"; | ||
|
|
||
| try { | ||
| window.matrixRTCSdk = await createMatrixRTCSdk( | ||
| "com.github.toger5.godot-game", | ||
| ); | ||
| console.info("createMatrixRTCSdk was created!"); | ||
| } catch (e) { | ||
| console.error("createMatrixRTCSdk", e); | ||
| } | ||
| const sdk = window.matrixRTCSdk; | ||
|
|
||
| // This is the main bridging interface to godot | ||
| window.matrixRTCSdkGodot = { | ||
| dataObs: sdk.data$, | ||
| memberObs: sdk.members$, | ||
| // join: sdk.join, // lets stick with autojoin for now | ||
| sendData: sdk.sendData, | ||
| leave: sdk.leave, | ||
| connectedObs: sdk.connected$, | ||
| }; | ||
|
|
||
| console.info("matrixRTCSdk join ", sdk); | ||
| const connectionState = sdk.join(); | ||
| console.info("matrixRTCSdk joined"); | ||
|
|
||
| const div = document.getElementById("data"); | ||
| div.innerHTML = "<h3>Data:</h3>"; | ||
|
|
||
| sdk.data$.subscribe((data) => { | ||
| const child = document.createElement("p"); | ||
| child.innerHTML = JSON.stringify(data); | ||
| div.appendChild(child); | ||
| // TODO forward to godot | ||
| }); | ||
|
|
||
| sdk.members$.subscribe((memberObjects) => { | ||
| // reset div | ||
| const div = document.getElementById("members"); | ||
| div.innerHTML = "<h3>Members:</h3>"; | ||
|
|
||
| // create member list | ||
| const members = memberObjects.map((member) => member.membership.sender); | ||
| console.info("members changed", members); | ||
| for (const m of members) { | ||
| console.info("member", m); | ||
| const child = document.createElement("p"); | ||
| child.innerHTML = m; | ||
| div.appendChild(child); | ||
| } | ||
| }); | ||
|
|
||
| sdk.connected$.subscribe((connected) => { | ||
| console.info("connected changed", connected); | ||
| const div = document.getElementById("connect_status"); | ||
| div.innerHTML = connected ? "Connected" : "Disconnected"; | ||
| }); | ||
|
|
||
| let engine = new Engine($GODOT_CONFIG); | ||
| engine.startGame(); | ||
| </script> | ||
| <!--// TODO use it as godot HTML template--> | ||
| <script src="$GODOT_URL"></script> | ||
| </head> | ||
| <body> | ||
| <canvas id="canvas"></canvas> | ||
| <div | ||
| id="overlay" | ||
| style="position: absolute; top: 0; right: 0; background-color: #ffffff10" | ||
| > | ||
| <div id="connect_status"></div> | ||
| <button onclick="window.matrixRTCSdk.leave();">Leave</button> | ||
| <button onclick="window.matrixRTCSdk.sendData({prop: 'Hello, world!'});"> | ||
| Send Text | ||
| </button> | ||
| <div id="members"></div> | ||
| <div id="data"></div> | ||
| </div> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
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.
Copyright 2025 Element Creations Ltd.