Преглед изворни кода

Fixed a e2ee issues

	* Move application from Typescript to plain javascript
	* Change secret key creation mechanism
develop
Silvestr Predko пре 2 година
родитељ
комит
21b64fe0b6

+ 11
- 0
example/.babelrc Прегледај датотеку

1
+{
2
+    "presets": [
3
+        "@babel/preset-env",
4
+        [
5
+            "@babel/preset-react",
6
+            {
7
+                "runtime": "automatic"
8
+            }
9
+        ]
10
+    ]
11
+}

+ 968
- 13575
example/package-lock.json
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 5
- 2
example/package.json Прегледај датотеку

3
   "version": "1.0.0",
3
   "version": "1.0.0",
4
   "description": "",
4
   "description": "",
5
   "private": true,
5
   "private": true,
6
+  "main": "index.js",
6
   "scripts": {
7
   "scripts": {
7
     "test": "echo \"Error: no test specified\" && exit 1",
8
     "test": "echo \"Error: no test specified\" && exit 1",
8
     "build": "webpack",
9
     "build": "webpack",
12
   "author": "",
13
   "author": "",
13
   "license": "ISC",
14
   "license": "ISC",
14
   "devDependencies": {
15
   "devDependencies": {
16
+    "@babel/core": "^7.20.5",
17
+    "@babel/preset-env": "^7.20.2",
18
+    "@babel/preset-react": "^7.18.6",
15
     "@types/lodash": "^4.14.184",
19
     "@types/lodash": "^4.14.184",
16
     "@types/react": "^18.0.25",
20
     "@types/react": "^18.0.25",
17
     "@types/react-dom": "^18.0.8",
21
     "@types/react-dom": "^18.0.8",
18
     "@wasm-tool/wasm-pack-plugin": "^1.6.0",
22
     "@wasm-tool/wasm-pack-plugin": "^1.6.0",
23
+    "babel-loader": "^9.1.0",
19
     "copy-webpack-plugin": "^11.0.0",
24
     "copy-webpack-plugin": "^11.0.0",
20
     "css-loader": "^6.7.1",
25
     "css-loader": "^6.7.1",
21
     "html-webpack-plugin": "^5.5.0",
26
     "html-webpack-plugin": "^5.5.0",
23
     "sass": "^1.55.0",
28
     "sass": "^1.55.0",
24
     "sass-loader": "^13.0.2",
29
     "sass-loader": "^13.0.2",
25
     "style-loader": "^3.3.1",
30
     "style-loader": "^3.3.1",
26
-    "ts-loader": "^9.3.1",
27
-    "typescript": "^4.8.2",
28
     "webpack": "^5.74.0",
31
     "webpack": "^5.74.0",
29
     "webpack-cli": "^4.10.0",
32
     "webpack-cli": "^4.10.0",
30
     "webpack-dev-server": "^4.10.0"
33
     "webpack-dev-server": "^4.10.0"

example/src/App.tsx → example/src/App.jsx Прегледај датотеку

4
 import Meeting from './components/Meeting'
4
 import Meeting from './components/Meeting'
5
 import Wallet from './components/Wallet';
5
 import Wallet from './components/Wallet';
6
 
6
 
7
-interface Props {
8
-}
9
-
10
-interface State {
11
-  secretKey: string,
12
-  meetingId: string
13
-}
14
-
15
-class App extends React.Component<Props, State> {
16
-  constructor(props: Props) {
7
+class App extends React.Component {
8
+  constructor(props) {
17
     super(props);
9
     super(props);
18
     this.setSecretKey = this.setSecretKey.bind(this);
10
     this.setSecretKey = this.setSecretKey.bind(this);
19
     this.setMeetingId = this.setMeetingId.bind(this);
11
     this.setMeetingId = this.setMeetingId.bind(this);
24
     }
16
     }
25
   }
17
   }
26
 
18
 
27
-  setSecretKey(secretKey: string) {
19
+  setSecretKey(secretKey) {
28
     this.setState({ secretKey });
20
     this.setState({ secretKey });
29
   };
21
   };
30
-  setMeetingId(meetingId: string) {
22
+  setMeetingId(meetingId) {
31
     this.setState({ meetingId });
23
     this.setState({ meetingId });
32
   };
24
   };
33
 
25
 

+ 54
- 0
example/src/components/Meeting.jsx Прегледај датотеку

1
+import React, { PropsWithChildren } from 'react'
2
+import { JitsiMeeting } from "@jitsi/react-sdk";
3
+
4
+class Meeting extends React.Component {
5
+    render() {
6
+        return (
7
+            <JitsiMeeting
8
+                roomName={this.props.meetingId}
9
+                getIFrameRef={handleJitsiIFrameRef2}
10
+                configOverwrite={{
11
+                    e2ee: {
12
+                        externallyManagedKey: true
13
+                    }
14
+                }}
15
+                onApiReady={externalApi => {
16
+                    externalApi.on("videoConferenceJoined", async (event) => {
17
+                        let secretKey = new Uint8Array(Buffer.from(this.props.secretKeyBase64, 'base64'));
18
+                        let index = 0;
19
+
20
+                        let key = await window.crypto.subtle.importKey(
21
+                            "raw",
22
+                            secretKey,
23
+                            "AES-GCM",
24
+                            true,
25
+                            ["encrypt", "decrypt"]
26
+                        );
27
+
28
+                        await externalApi.setMediaEncryptionKey({
29
+                            key,
30
+                            index
31
+                        }).then(() => {
32
+                            console.log("SET MEDIA ENCRYPTION KEY");
33
+                        });
34
+
35
+                        setTimeout(() => {
36
+                            externalApi.toggleE2EE(true);
37
+                        }, 1_000);
38
+
39
+                        console.log('Jitsi Meet External API', externalApi);
40
+                    })
41
+                }}
42
+            />
43
+        )
44
+    }
45
+}
46
+
47
+const handleJitsiIFrameRef2 = (iframeRef) => {
48
+    iframeRef.style.marginTop = '10px';
49
+    iframeRef.style.border = '10px #df486f';
50
+    iframeRef.style.padding = '5px';
51
+    iframeRef.style.height = '50em';
52
+};
53
+
54
+export default Meeting;

+ 0
- 57
example/src/components/Meeting.tsx Прегледај датотеку

1
-import React, { PropsWithChildren } from 'react'
2
-import { JitsiMeeting } from "@jitsi/react-sdk";
3
-
4
-interface Props {
5
-    secretKeyBase64: string,
6
-    meetingId: string
7
-}
8
-interface State {
9
-}
10
-
11
-class Meeting extends React.Component<Props, State> {
12
-    render() {
13
-        return(
14
-            <JitsiMeeting
15
-                roomName={this.props.meetingId}
16
-                getIFrameRef = { handleJitsiIFrameRef2 }
17
-                configOverwrite = {{
18
-                    e2ee: {
19
-                    externallyManagedKey: true
20
-                    }
21
-                }}
22
-                onApiReady = { externalApi => {
23
-                    externalApi.on("videoConferenceJoined", async (event) => {
24
-                        let secretKey: Uint8Array = new Uint8Array(Buffer.from(this.props.secretKeyBase64, 'base64'));
25
-
26
-                        let index = 0;
27
-                        externalApi.executeCommand('setMediaEncryptionKey', JSON.stringify({
28
-                            exportedKey: Array.from(secretKey),
29
-                            index
30
-                        }));
31
-
32
-                        externalApi.executeCommand("toggleE2EE", true);
33
-                        console.log('Jitsi Meet External API', externalApi);
34
-                    })
35
-                } }
36
-            />
37
-        )
38
-    }
39
-}
40
-
41
-const handleJitsiIFrameRef2 = (iframeRef: IIframeStyle) => {
42
-  iframeRef.style.marginTop = '10px';
43
-  iframeRef.style.border = '10px #df486f';
44
-  iframeRef.style.padding = '5px';
45
-  iframeRef.style.height = '50em';
46
-};
47
-
48
-interface IIframeStyle {
49
-  style: {
50
-    marginTop: string,
51
-    border: string,
52
-    padding: string,
53
-    height: string
54
-  }
55
-}
56
-
57
-export default Meeting;

example/src/components/Wallet.tsx → example/src/components/Wallet.jsx Прегледај датотеку

1
 import React from "react";
1
 import React from "react";
2
 
2
 
3
-// import "../assets/style.scss";
4
 import * as _ from "lodash";
3
 import * as _ from "lodash";
5
 import { connect, WalletConnection, keyStores, Near } from 'near-api-js';
4
 import { connect, WalletConnection, keyStores, Near } from 'near-api-js';
6
-import { BrowserLocalStorageKeyStore } from "near-api-js/lib/key_stores";
7
 const { KeyProvisioner, ProvisionerConfig } = await import("../../../pkg/web_client");
5
 const { KeyProvisioner, ProvisionerConfig } = await import("../../../pkg/web_client");
8
 
6
 
9
-interface State {
10
-    isSignedIn: boolean,
11
-    keyStore: BrowserLocalStorageKeyStore,
12
-    accountId: string | null,
13
-    walletConnection: WalletConnection | null,
14
-    nearConnection: Near | null,
15
-    timeouts: {
16
-        default_ms: number,
17
-        interaction_ms: number
18
-    }
19
-    provisioner: any,
20
-    secretKey: string | null,
21
-    meetingId: string | null,
22
-    participants: string[],
23
-}
24
-
25
-interface Props {
26
-    setSecretKey: (key: string) => void,
27
-    setMeetingId: (id: string) => void
28
-}
29
-
30
-class Wallet extends React.Component<Props, State> {
31
-    constructor(props: Props) {
7
+class Wallet extends React.Component {
8
+    constructor(props) {
32
         super(props);
9
         super(props);
33
         this.state = {
10
         this.state = {
34
             isSignedIn: false,
11
             isSignedIn: false,
47
         };
24
         };
48
     }
25
     }
49
 
26
 
50
-    setStateAsync(state: State) {
51
-        return new Promise((resolve: any) => {
27
+    setStateAsync(state) {
28
+        return new Promise((resolve) => {
52
             this.setState(state, resolve)
29
             this.setState(state, resolve)
53
         });
30
         });
54
     }
31
     }
55
 
32
 
56
-    async componentDidMount(): Promise<void> {
33
+    async componentDidMount() {
57
         let keyStore = this.state.keyStore;
34
         let keyStore = this.state.keyStore;
58
 
35
 
59
         let nearConnectionCall = async () => {
36
         let nearConnectionCall = async () => {
60
-            let headers: { [key: string]: (string | number) };
61
             let connectionConfig = {
37
             let connectionConfig = {
62
                 networkId: "testnet",
38
                 networkId: "testnet",
63
                 keyStore,
39
                 keyStore,
65
                 walletUrl: "https://wallet.testnet.near.org",
41
                 walletUrl: "https://wallet.testnet.near.org",
66
                 helperUrl: "https://helper.testnet.near.org",
42
                 helperUrl: "https://helper.testnet.near.org",
67
                 explorerUrl: "https://explorer.testnet.near.org",
43
                 explorerUrl: "https://explorer.testnet.near.org",
68
-                headers
69
             };
44
             };
70
 
45
 
71
             let nearConnection = await connect(connectionConfig);
46
             let nearConnection = await connect(connectionConfig);
90
     }
65
     }
91
 
66
 
92
     async handleWallet() {
67
     async handleWallet() {
93
-        let accountId: string = this.state.accountId;
68
+        let accountId = this.state.accountId;
94
         let account = await this.state.nearConnection.account(accountId);
69
         let account = await this.state.nearConnection.account(accountId);
95
         let accessKeys = await account.getAccessKeys();
70
         let accessKeys = await account.getAccessKeys();
96
         let keypair = await this.state.keyStore.getKey("testnet", accountId);
71
         let keypair = await this.state.keyStore.getKey("testnet", accountId);
111
     async handleMeetingStart() {
86
     async handleMeetingStart() {
112
         let participants = this.state.participants;
87
         let participants = this.state.participants;
113
         let provisioner = this.state.provisioner;
88
         let provisioner = this.state.provisioner;
89
+        let default_ms = this.state.timeouts.default_ms;
90
+        let interaction_ms = this.state.timeouts.interaction_ms;
114
 
91
 
115
         if (participants.length > 0) {
92
         if (participants.length > 0) {
116
             console.log("Participants: " + participants);
93
             console.log("Participants: " + participants);
117
-            provisioner.init_meeting(new Set(participants), this.state.timeouts.default_ms)
118
-                .then((meetingId: string) => {
119
-                    this.props.setMeetingId(meetingId);
94
+            provisioner.init_meeting(new Set(participants), default_ms)
95
+                .then((meeting) => {
96
+                    this.props.setMeetingId(meeting.meet_id);
97
+                    let meetingId = meeting.meet_id;
120
                     this.setState({ ...this.state, meetingId });
98
                     this.setState({ ...this.state, meetingId });
121
-                    console.log("Meeting Id:", meetingId);
122
-                    provisioner.send_keys(meetingId, this.state.timeouts.interaction_ms)
123
-                        .then((secretKey: string) => {
99
+                    console.log("Meeting Id:", meeting.meet_id);
100
+                    provisioner.send_keys(meeting.meet_id, interaction_ms)
101
+                        .then((secretKey) => {
124
                             this.setState({ ...this.state, secretKey });
102
                             this.setState({ ...this.state, secretKey });
125
                             this.props.setSecretKey(secretKey);
103
                             this.props.setSecretKey(secretKey);
126
                             console.log("Secret Key" + secretKey);
104
                             console.log("Secret Key" + secretKey);
127
                         })
105
                         })
128
                         .then(() => console.log("Send keys is ok"))
106
                         .then(() => console.log("Send keys is ok"))
129
-                        .catch((err: any) => {
130
-                            console.log("Error: " + err.err_msg());
107
+                        .catch((err) => {
108
+                            console.log("Error: ", err);
131
                         });
109
                         });
132
                 })
110
                 })
133
                 .then(() => console.log("Init is ok"))
111
                 .then(() => console.log("Init is ok"))
134
-                .catch((err: any) => {
135
-                    console.log("Error: " + err.err_msg());
112
+                .catch((err) => {
113
+                    console.log("Error: ", err);
136
                 });
114
                 });
137
         }
115
         }
138
     }
116
     }
146
         let default_ms = this.state.timeouts.default_ms;
124
         let default_ms = this.state.timeouts.default_ms;
147
         this.props.setMeetingId(meetingId);
125
         this.props.setMeetingId(meetingId);
148
 
126
 
149
-        provisioner.get_key(meetingId, default_ms).then((secretKey: any) => {
127
+        provisioner.get_key(meetingId, default_ms).then((secretKey) => {
150
             this.props.setSecretKey(secretKey);
128
             this.props.setSecretKey(secretKey);
151
             this.setState({ ...this.state, secretKey });
129
             this.setState({ ...this.state, secretKey });
152
             console.log("Secret Key" + secretKey);
130
             console.log("Secret Key" + secretKey);
153
-        }).catch((err: any) => {
154
-            console.log("ErrorType: " + ErrorType[err.err_type()]);
155
-            console.log("Error: " + err.err_msg());
131
+        }).catch((err) => {
132
+            console.log("Error: ", err);
156
         });
133
         });
157
     }
134
     }
158
 
135
 

example/src/index.tsx → example/src/index.js Прегледај датотеку

1
 import React from 'react';
1
 import React from 'react';
2
 import ReactDOM from 'react-dom/client';
2
 import ReactDOM from 'react-dom/client';
3
 import './index.css';
3
 import './index.css';
4
-import App from './App';
4
+import App from './App.jsx';
5
 
5
 
6
 const root = ReactDOM.createRoot(
6
 const root = ReactDOM.createRoot(
7
-  document.getElementById('root') as HTMLElement
7
+  document.getElementById('root')
8
 );
8
 );
9
 root.render(
9
 root.render(
10
   <React.StrictMode>
10
   <React.StrictMode>

+ 0
- 22
example/tsconfig.json Прегледај датотеку

1
-{
2
-    "compilerOptions": {
3
-        "outDir": "dist/",
4
-        "noImplicitAny": true,
5
-        "sourceMap": true,
6
-        "jsx": "react",
7
-        "allowJs": true,
8
-        "moduleResolution": "node",
9
-        "module": "es2022",
10
-        "lib": [
11
-            "es2022", "DOM", "DOM.Iterable"
12
-        ],
13
-        "target": "es2022",
14
-        "preserveConstEnums": true,
15
-        "esModuleInterop": true,
16
-        "paths": {
17
-            "client/*": [
18
-                "../pkg/*"
19
-            ]
20
-        }
21
-    }
22
-}

+ 11
- 11
example/webpack.config.js Прегледај датотеку

3
 const HtmlWebpackPlugin = require('html-webpack-plugin');
3
 const HtmlWebpackPlugin = require('html-webpack-plugin');
4
 
4
 
5
 module.exports = {
5
 module.exports = {
6
-    entry: './src/index.tsx',
6
+    entry: path.join(__dirname, "src", "index.js"),
7
     output: {
7
     output: {
8
         filename: 'main.js',
8
         filename: 'main.js',
9
         path: path.resolve(__dirname, 'dist'),
9
         path: path.resolve(__dirname, 'dist'),
11
     },
11
     },
12
     resolve: {
12
     resolve: {
13
         alias: {
13
         alias: {
14
-            'client': path.join(__dirname, '../pkg/')
14
+            'client': path.join(__dirname, '../pkg/'),
15
+            'react-dom': path.resolve('./node_modules/react-dom'),
16
+            react: path.resolve('./node_modules/react')
15
         },
17
         },
16
         fallback: {
18
         fallback: {
17
-            "buffer": require.resolve("buffer")
18
-        }
19
+            "buffer": require.resolve("buffer"),
20
+        },
21
+        extensions: ['*', '.js', '.jsx'],
19
     },
22
     },
20
     mode: "development",
23
     mode: "development",
21
     devServer: {
24
     devServer: {
33
             }
36
             }
34
         },
37
         },
35
     },
38
     },
36
-    resolve: {
37
-        extensions: ['.tsx', '.ts', '.js'],
38
-    },
39
     module: {
39
     module: {
40
         rules: [
40
         rules: [
41
             {
41
             {
42
-                test: /\.tsx?$/,
43
-                use: 'ts-loader',
42
+                test: /\.(js|jsx)$/,
44
                 exclude: /node_modules/,
43
                 exclude: /node_modules/,
44
+                use: ["babel-loader"],
45
             },
45
             },
46
             {
46
             {
47
                 test: /\.css?$/,
47
                 test: /\.css?$/,
54
             Buffer: ['buffer', 'Buffer'],
54
             Buffer: ['buffer', 'Buffer'],
55
         }),
55
         }),
56
         new HtmlWebpackPlugin({
56
         new HtmlWebpackPlugin({
57
-            template: 'public/index.html',
58
-        })
57
+            template: path.join(__dirname, "public", "index.html"),
58
+        }),
59
     ],
59
     ],
60
     experiments: {
60
     experiments: {
61
         asyncWebAssembly: true,
61
         asyncWebAssembly: true,

Loading…
Откажи
Сачувај