famedlysdk/README.md

76 lines
1.6 KiB
Markdown
Raw Normal View History

2019-06-10 10:25:19 +00:00
+++ This SDK is under development and highly experimental +++
2019-06-09 10:16:48 +00:00
# famedlysdk
2019-06-09 10:20:59 +00:00
Matrix SDK for the famedly talk app written in dart.
2019-06-09 10:16:48 +00:00
2019-06-10 10:25:19 +00:00
## API
The API is documented here: [famedly.gitlab.io/famedlysdk](https://famedly.gitlab.io/famedlysdk/)
2019-06-09 10:20:59 +00:00
## How to use this
2019-06-09 10:16:48 +00:00
2019-06-09 10:20:59 +00:00
1. Import the sdk
2019-06-09 10:16:48 +00:00
2019-06-09 10:20:59 +00:00
```yaml
2019-06-09 12:33:25 +00:00
famedlysdk:
2019-06-09 10:20:59 +00:00
git:
url: https://gitlab.com/famedly/famedlysdk.git
ref: 77be6102f6cbb2e01adc28f9caa3aa583f914235
```
```dart
import 'package:flutter/material.dart';
import 'package:famedlysdk/famedlysdk.dart';
```
2. Access the MatrixState object by calling Matrix.of with your current BuildContext:
```dart
Client matrix = Client("famedly talk");
```
3. Connect to a Matrix Homeserver and listen to the streams:
```dart
2019-06-09 12:42:19 +00:00
matrix.connection.onLoginStateChanged.stream.listen((bool loginState){
2019-06-09 10:20:59 +00:00
print("LoginState: ${loginState.toString()}");
});
2019-06-09 12:42:19 +00:00
matrix.connection.onEvent.stream.listen((EventUpdate eventUpdate){
2019-06-09 10:20:59 +00:00
print("New event update!");
});
2019-06-09 12:42:19 +00:00
matrix.connection.onRoomUpdate.stream.listen((RoomUpdate eventUpdate){
2019-06-09 10:20:59 +00:00
print("New room update!");
});
2019-06-09 12:48:28 +00:00
final bool serverValid = await matrix.checkServer("https://yourhomeserver.abc");
2019-06-09 10:20:59 +00:00
2019-06-09 12:48:28 +00:00
final bool loginValid = await matrix.login("username", "password");
2019-06-09 10:20:59 +00:00
```
4. Send a message to a Room:
```dart
2019-06-09 12:42:19 +00:00
final resp = await matrix.connection.jsonRequest(
2019-06-09 10:20:59 +00:00
type: "PUT",
action: "/r0/rooms/!fjd823j:example.com/send/m.room.message/$txnId",
data: {
"msgtype": "m.text",
"body": "hello"
}
);
```
## Development
### Regenerating JSON Classes
To regenerate the part files of JSON Classes you need to run this command:
```bash
flutter pub run build_runner build
2019-06-09 10:20:59 +00:00
```