1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
// @flow
import React, { Component } from 'react';
import type { Dispatch } from 'redux';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import {
RemoteControl,
setupScreenSharingForWindow,
setupAlwaysOnTopRender,
initPopupsConfigurationRender,
setupWiFiStats
} from 'jitsi-meet-electron-utils';
import config from '../../config';
import { Wrapper } from '../styled';
type Props = {
/**
* React Router match object.
* This contains parameters passed through <Route /> component.
*/
match: Object;
/**
* Redux dispatch.
*/
dispatch: Dispatch<*>;
};
/**
* Conference component.
*/
class Conference extends Component<Props, *> {
/**
* Reference to the element of this component.
*/
_ref: Object;
/**
* External API object.
*/
_api: Object;
/**
* Initializes a new {@code Conference} instance.
*
* @inheritdoc
*/
constructor() {
super();
this._ref = React.createRef();
}
/**
* Attach the script to this component.
*
* @returns {void}
*/
componentDidMount() {
const parentNode = this._ref.current;
const room = this.props.match.params.room;
const domain = this.props.match.params.domain || config.defaultDomain;
const script = document.createElement('script');
script.async = true;
script.onload = () => this._onScriptLoad(parentNode, room, domain);
script.onerror = () => this._navigateToHome();
script.src = `https://${domain}/external_api.js`;
this._ref.current.appendChild(script);
}
/**
* Remove conference on unmounting.
*
* @returns {void}
*/
componentWillUnmount() {
if (this._api) {
this._api.dispose();
}
}
/**
* Implements React's {@link Component#render()}.
*
* @returns {ReactElement}
*/
render() {
return <Wrapper innerRef = { this._ref } />;
}
/**
* Navigates to home screen (Welcome).
*
* @returns {void}
*/
_navigateToHome() {
this.props.dispatch(push('/'));
}
/**
* When the script is loaded create the iframe element in this component
* and attach utils from jitsi-meet-electron-utils.
*
* @param {Object} parentNode - Node to which iframe has to be attached.
* @param {string} roomName - Conference room name to be joined.
* @param {string} domain - Jitsi Meet server domain.
* @returns {void}
*/
_onScriptLoad(parentNode: Object, roomName: string, domain: string) {
const JitsiMeetExternalAPI = window.JitsiMeetExternalAPI;
this._api = new JitsiMeetExternalAPI(domain, {
parentNode,
roomName
});
initPopupsConfigurationRender(this._api);
const iframe = this._api.getIFrame();
setupScreenSharingForWindow(iframe);
new RemoteControl(iframe); // eslint-disable-line no-new
setupAlwaysOnTopRender(this._api);
setupWiFiStats(iframe);
this._api.on('readyToClose', () => this._navigateToHome());
}
}
export default connect()(Conference);
|