You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-16 18:21:59 +03:00
move new example to own directory
This commit is contained in:
2
examples/crypto-browser/lib/.gitignore
vendored
Normal file
2
examples/crypto-browser/lib/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
olm.js
|
||||||
|
olm.wasm
|
1
examples/crypto-browser/lib/matrix.js
Symbolic link
1
examples/crypto-browser/lib/matrix.js
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../dist/browser-matrix.js
|
59
examples/crypto-browser/olm-device-export-import.html
Normal file
59
examples/crypto-browser/olm-device-export-import.html
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>Test Crypto in Browser</title>
|
||||||
|
<script src="lib/olm.js"></script>
|
||||||
|
<script src="lib/matrix.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Testing export/import of Olm devices in the browser</h1>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
Make sure you built the current version of the Matrix JS SDK
|
||||||
|
(<code>yarn build</code>)
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
copy <code>olm.js</code> and <code>olm.wasm</code>
|
||||||
|
from a recent release of Olm (was tested with version 3.1.4)
|
||||||
|
in directory <code>lib/</code>
|
||||||
|
</li>
|
||||||
|
<li>start a local Matrix homeserver (on port 8008, or change the port in the code)</li>
|
||||||
|
<li>Serve this HTML file (e.g. <code>python3 -m http.server</code>) and go to it through your browser</li>
|
||||||
|
<li>
|
||||||
|
in the JS console, do:
|
||||||
|
<pre>
|
||||||
|
aliceMatrixClient = await newMatrixClient("alice-"+randomHex());
|
||||||
|
await aliceMatrixClient.exportDevice();
|
||||||
|
await aliceMatrixClient.getAccessToken();
|
||||||
|
</pre>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
copy the result of <code>exportDevice</code> and <code>getAccessToken</code> somewhere
|
||||||
|
(<strong>not</strong> in a JS variable as it will be destroyed when you refresh the page)
|
||||||
|
</li>
|
||||||
|
<li><strong>refresh the page (F5)</strong> to make sure the client is destroyed</li>
|
||||||
|
<li>
|
||||||
|
Do the following, replacing <code>ALICE_ID</code>
|
||||||
|
with the user ID of Alice (you can find it in the exported data)
|
||||||
|
<pre>
|
||||||
|
bobMatrixClient = await newMatrixClient("bob-"+randomHex());
|
||||||
|
roomId = await bobMatrixClient.createEncryptedRoom([ALICE_ID]);
|
||||||
|
await bobMatrixClient.sendTextMessage('Hi Alice!', roomId);
|
||||||
|
</pre>
|
||||||
|
</li>
|
||||||
|
<li>Again, <strong>refresh the page (F5)</strong>. You may want to clear your console as well.</li>
|
||||||
|
<li>
|
||||||
|
Now do the following, using the exported data and the access token you saved previously:
|
||||||
|
<pre>
|
||||||
|
aliceMatrixClient = await importMatrixClient(EXPORTED_DATA, ACCESS_TOKEN);
|
||||||
|
</pre>
|
||||||
|
</li>
|
||||||
|
<li>You should see the message sent by Bob printed in the console.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<script src="olm-device-export-import.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -1,63 +1,3 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
||||||
<title>Test Crypto in Browser</title>
|
|
||||||
<script src="lib/olm.js"></script>
|
|
||||||
<script src="lib/matrix.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Testing export/import of Olm devices in the browser</h1>
|
|
||||||
<p>
|
|
||||||
Inspired by <code>examples/browser</code>
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
Make sure you built the current version of the Matrix JS SDK
|
|
||||||
(<code>yarn build</code>)
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
make sure there is
|
|
||||||
<code>matrix.js</code>, <code>olm.js</code> and <code>olm.wasm</code>
|
|
||||||
in directory <code>lib/</code>
|
|
||||||
</li>
|
|
||||||
<li>start a local Matrix homeserver (on port 8008, or change the port in the code)</li>
|
|
||||||
<li>Serve this HTML file (e.g. <code>python3 -m http.server</code>) and go to it through your browser</li>
|
|
||||||
<li>
|
|
||||||
in the JS console, do:
|
|
||||||
<pre>
|
|
||||||
aliceMatrixClient = await newMatrixClient("alice-"+randomHex());
|
|
||||||
await aliceMatrixClient.exportDevice();
|
|
||||||
await aliceMatrixClient.getAccessToken();
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
copy the result of <code>exportDevice</code> and <code>getAccessToken</code> somewhere
|
|
||||||
(<strong>not</strong> in a JS variable as it will be destroyed when you refresh the page)
|
|
||||||
</li>
|
|
||||||
<li><strong>refresh the page (F5)</strong> to make sure the client is destroyed</li>
|
|
||||||
<li>
|
|
||||||
Do the following, replacing <code>ALICE_ID</code>
|
|
||||||
with the user ID of Alice (you can find it in the exported data)
|
|
||||||
<pre>
|
|
||||||
bobMatrixClient = await newMatrixClient("bob-"+randomHex());
|
|
||||||
roomId = await bobMatrixClient.createEncryptedRoom([ALICE_ID]);
|
|
||||||
await bobMatrixClient.sendTextMessage('Hi Alice!', roomId);
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
<li>Again, <strong>refresh the page (F5)</strong>. You may want to clear your console as well.</li>
|
|
||||||
<li>
|
|
||||||
Now do the following, using the exported data and the access token you saved previously:
|
|
||||||
<pre>
|
|
||||||
aliceMatrixClient = await importMatrixClient(EXPORTED_DATA, ACCESS_TOKEN);
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
<li>You should see the message sent by Bob printed in the console.</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
if (!Olm) {
|
if (!Olm) {
|
||||||
console.error(
|
console.error(
|
||||||
"global.Olm does not seem to be present."
|
"global.Olm does not seem to be present."
|
||||||
@@ -179,7 +119,4 @@ function extendMatrixClient(matrixClient) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Reference in New Issue
Block a user