-
Make sure you built the current version of the Matrix JS SDK
(
yarn build
)
-
copy
olm.js
and olm.wasm
from a recent release of Olm (was tested with version 3.1.4)
in directory lib/
- start a local Matrix homeserver (on port 8008, or change the port in the code)
- Serve this HTML file (e.g.
python3 -m http.server
) and go to it through your browser
-
in the JS console, do:
aliceMatrixClient = await newMatrixClient("alice-"+randomHex());
await aliceMatrixClient.exportDevice();
await aliceMatrixClient.getAccessToken();
-
copy the result of
exportDevice
and getAccessToken
somewhere
(not in a JS variable as it will be destroyed when you refresh the page)
- refresh the page (F5) to make sure the client is destroyed
-
Do the following, replacing
ALICE_ID
with the user ID of Alice (you can find it in the exported data)
bobMatrixClient = await newMatrixClient("bob-"+randomHex());
roomId = await bobMatrixClient.createEncryptedRoom([ALICE_ID]);
await bobMatrixClient.sendTextMessage('Hi Alice!', roomId);
- Again, refresh the page (F5). You may want to clear your console as well.
-
Now do the following, using the exported data and the access token you saved previously:
aliceMatrixClient = await importMatrixClient(EXPORTED_DATA, ACCESS_TOKEN);
- You should see the message sent by Bob printed in the console.