Skip to content

Instantly share code, notes, and snippets.

@ara4n
Created October 20, 2021 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ara4n/7edefcdb9dfaba627c9c4654dfd920ec to your computer and use it in GitHub Desktop.
Save ara4n/7edefcdb9dfaba627c9c4654dfd920ec to your computer and use it in GitHub Desktop.
megolm test jig
import olm from "olm";
import sdk from "matrix-js-sdk";
import { MatrixEvent } from "matrix-js-sdk";
import { LocalStorage } from "node-localstorage";
global.Olm = olm;
const myUserId = "@matthewtest94:matrix.org";
const myAccessToken = "secret";
const matrixClient = sdk.createClient({
baseUrl: "http://matrix.org",
accessToken: myAccessToken,
userId: myUserId,
deviceId: "JKGRJUVTBL",
sessionStore: new sdk.WebStorageSessionStore(new LocalStorage("./scratch")),
cryptoStore: new sdk.MemoryCryptoStore(),
});
await matrixClient.initCrypto();
await matrixClient.startClient();
matrixClient.crypto.setGlobalErrorOnUnknownDevices(false);
matrixClient.once('sync', async function(state, prevState, res) {
if(state === 'PREPARED') {
console.log("prepared");
const ct1 = await matrixClient.sendEvent(
"!BBYSlfSuRqYdhBZxjF:matrix.org",
"m.room.message",
{
"body": "hello world",
}
);
} else {
console.log(state);
process.exit(1);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment