famedlysdk/README.md

1.7 KiB

famedlysdk

Matrix SDK for the famedly talk app written in dart.

How to use this

  1. Import the sdk
  fluffyfluttermatrix:
    git:
      url: https://gitlab.com/famedly/famedlysdk.git
      ref: 77be6102f6cbb2e01adc28f9caa3aa583f914235
import 'package:flutter/material.dart';
import 'package:famedlysdk/famedlysdk.dart';

  1. Access the MatrixState object by calling Matrix.of with your current BuildContext:
Client matrix = Client("famedly talk");
  1. Connect to a Matrix Homeserver and listen to the streams:
matrix.homeserver = "https://yourhomeserveraddress";

matrix.onLoginStateChanged.stream.listen((bool loginState){ 
  print("LoginState: ${loginState.toString()}");
});

matrix.onEvent.stream.listen((EventUpdate eventUpdate){ 
  print("New event update!");
});

matrix.onRoomUpdate.stream.listen((RoomUpdate eventUpdate){ 
  print("New room update!");
});

final loginResp = await matrix.jsonRequest(
  type: "POST",
  action: "/client/r0/login",
  data: {
    "type": "m.login.password",
    "user": _usernameController.text,
    "password": _passwordController.text,
    "initial_device_display_name": "Fluffy Matrix Client"
  }
);

matrix.connect(
  newToken: loginResp["token"],
  newUserID: loginResp["user_id"],
  newHomeserver: matrix.homeserver,
  newDeviceName: "Fluffy Matrix Client",
  newDeviceID: loginResp["device_id"],
  newMatrixVersions: ["r0.4.0"],
  newLazyLoadMembers: false
);
  1. Send a message to a Room:
final resp = await jsonRequest(
    type: "PUT",
    action: "/r0/rooms/!fjd823j:example.com/send/m.room.message/$txnId",
    data: {
        "msgtype": "m.text",
        "body": "hello"
    }
);