-
-
Notifications
You must be signed in to change notification settings - Fork 551
Add Element Call to cinny #2512
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
98c90b2
dependencies
toger5 bbe53d6
copy over utils form EW
toger5 8df27ac
copy over widgetDriver from EW
toger5 e18769f
copy over StopGapWidget (ElementCallMessaging class)
toger5 65085e8
Call View template
toger5 4985de8
call view impl
toger5 c9effa0
use call view in room view
toger5 94ff2d1
Add call button to header
toger5 0f70e6f
fix widget loading vite config
toger5 c1b2902
add netlify redirect to widgets/
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |||||
| "@atlaskit/pragmatic-drag-and-drop": "1.1.6", | ||||||
| "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "1.3.0", | ||||||
| "@atlaskit/pragmatic-drag-and-drop-hitbox": "1.0.3", | ||||||
| "@element-hq/element-call-embedded": "0.16.0", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| "@fontsource/inter": "4.5.14", | ||||||
| "@tanstack/react-query": "5.24.1", | ||||||
| "@tanstack/react-query-devtools": "5.24.1", | ||||||
|
|
@@ -55,6 +56,7 @@ | |||||
| "linkify-react": "4.1.3", | ||||||
| "linkifyjs": "4.1.3", | ||||||
| "matrix-js-sdk": "38.2.0", | ||||||
| "matrix-widget-api": "1.13.1", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| "millify": "6.1.0", | ||||||
| "pdfjs-dist": "4.2.67", | ||||||
| "prismjs": "1.30.0", | ||||||
|
|
||||||
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,151 @@ | ||
| import React, { useEffect, useRef, useState } from 'react'; | ||
| import { ClientWidgetApi } from 'matrix-widget-api'; | ||
| import { Button, Text } from 'folds'; | ||
| import ElementCall from './ElementCall'; | ||
| import { useMatrixClient } from '../../hooks/useMatrixClient'; | ||
| import { useEventEmitter } from './utils'; | ||
| import { useIsDirectRoom, useRoom } from '../../hooks/useRoom'; | ||
| import { useCallOngoing } from '../../hooks/useCallOngoing'; | ||
|
|
||
| export enum CallWidgetActions { | ||
| // All of these actions are currently specific to Jitsi and Element Call | ||
| JoinCall = 'io.element.join', | ||
| HangupCall = 'im.vector.hangup', | ||
| Close = 'io.element.close', | ||
| } | ||
| export function action(type: CallWidgetActions): string { | ||
| return `action:${type}`; | ||
| } | ||
|
|
||
| const iframeFeatures = | ||
| 'microphone; camera; encrypted-media; autoplay; display-capture; clipboard-write; ' + | ||
| 'clipboard-read;'; | ||
| const sandboxFlags = | ||
| 'allow-forms allow-popups allow-popups-to-escape-sandbox ' + | ||
| 'allow-same-origin allow-scripts allow-presentation allow-downloads'; | ||
| const iframeStyles = { flex: '1 1', border: 'none' }; | ||
| const containerStyle = (hidden: boolean): React.CSSProperties => ({ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| position: 'relative', | ||
| height: '100%', | ||
| width: '100%', | ||
| ...(hidden | ||
| ? { | ||
| overflow: 'hidden', | ||
| width: 0, | ||
| height: 0, | ||
| } | ||
| : {}), | ||
| }); | ||
| const closeButtonStyle: React.CSSProperties = { | ||
| position: 'absolute', | ||
| top: 8, | ||
| right: 8, | ||
| zIndex: 100, | ||
| maxWidth: 'fit-content', | ||
| }; | ||
|
|
||
| enum State { | ||
| Preparing = 'preparing', | ||
| Lobby = 'lobby', | ||
| Joined = 'joined', | ||
| HungUp = 'hung_up', | ||
| CanClose = 'can_close', | ||
| } | ||
|
|
||
| /** | ||
| * Shows a call for this room. Rendering this component will | ||
| * automatically create a call widget and join the call in the room. | ||
| * @returns | ||
| */ | ||
| export interface IRoomCallViewProps { | ||
| onClose?: () => void; | ||
| onJoin?: () => void; | ||
| onHangup?: (errorMessage?: string) => void; | ||
| } | ||
|
|
||
| export function CallView({ | ||
| onJoin = undefined, | ||
| onClose = undefined, | ||
| onHangup = undefined, | ||
| }: IRoomCallViewProps): JSX.Element { | ||
| // Construct required variables | ||
| const room = useRoom(); | ||
| const client = useMatrixClient(); | ||
| const iframe = useRef<HTMLIFrameElement>(null); | ||
|
|
||
| // Model state | ||
| const [elementCall, setElementCall] = useState<ElementCall | null>(); | ||
| const [widgetApi, setWidgetApi] = useState<ClientWidgetApi | null>(null); | ||
| const [state, setState] = useState(State.Preparing); | ||
|
|
||
| // Initialization parameters | ||
| const isDirect = useIsDirectRoom(); | ||
| const callOngoing = useCallOngoing(room); | ||
| const initialCallOngoing = React.useRef(callOngoing); | ||
| const initialIsDirect = React.useRef(isDirect); | ||
| useEffect(() => { | ||
| if (client && room && !elementCall) { | ||
| const e = new ElementCall(client, room, initialIsDirect.current, initialCallOngoing.current); | ||
| setElementCall(e); | ||
| } | ||
| }, [client, room, setElementCall, elementCall]); | ||
|
|
||
| // Start the messaging over the widget api. | ||
| useEffect(() => { | ||
| if (iframe.current && elementCall) { | ||
| elementCall.startMessaging(iframe.current); | ||
| } | ||
| return () => { | ||
| elementCall?.stopMessaging(); | ||
| }; | ||
| }, [iframe, elementCall]); | ||
|
|
||
| // Widget api ready | ||
| useEventEmitter(elementCall, 'ready', () => { | ||
| setWidgetApi(elementCall?.widgetApi ?? null); | ||
| setState(State.Lobby); | ||
| }); | ||
|
|
||
| // Use widget api to listen for hangup/join/close actions | ||
| useEventEmitter(widgetApi, action(CallWidgetActions.HangupCall), () => { | ||
| setState(State.HungUp); | ||
| onHangup?.(); | ||
| }); | ||
| useEventEmitter(widgetApi, action(CallWidgetActions.JoinCall), () => { | ||
| setState(State.Joined); | ||
| onJoin?.(); | ||
| }); | ||
| useEventEmitter(widgetApi, action(CallWidgetActions.Close), () => { | ||
| setState(State.CanClose); | ||
| onClose?.(); | ||
| }); | ||
|
|
||
| // render component | ||
| return ( | ||
| <div style={containerStyle(state === State.HungUp)}> | ||
| {/* Exit button for lobby state */} | ||
| {state === State.Lobby && ( | ||
| <Button | ||
| variant="Secondary" | ||
| onClick={() => { | ||
| setState(State.CanClose); | ||
| onClose?.(); | ||
| }} | ||
| style={closeButtonStyle} | ||
| > | ||
| <Text size="B400">Close</Text> | ||
| </Button> | ||
| )} | ||
| <iframe | ||
| ref={iframe} | ||
| allow={iframeFeatures} | ||
| sandbox={sandboxFlags} | ||
| style={iframeStyles} | ||
| src={elementCall?.embedUrl} | ||
| title="room call" | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
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.
Remember to update the nginx config alongside this. Apparently it was still not working when I deployed it on my server.