famedlysdk/README.md

71 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
2020-01-04 10:21:54 +00:00
The API is documented here: [famedly.gitlab.io/famedlysdk/famedlysdk/famedlysdk-library.html](https://famedly.gitlab.io/famedlysdk/famedlysdk/famedlysdk-library.html)
2019-06-10 10:25:19 +00:00
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
2019-10-02 11:33:01 +00:00
```
2019-06-09 10:20:59 +00:00
```dart
import 'package:flutter/material.dart';
import 'package:famedlysdk/famedlysdk.dart';
2019-10-02 11:33:01 +00:00
```
2. Create a new client:
2019-06-09 10:20:59 +00:00
2019-10-02 11:33:01 +00:00
```dart
Client matrix = Client("HappyChat");
2019-06-09 10:20:59 +00:00
```
2019-10-16 07:47:41 +00:00
Take a look here for an example store:
2020-01-04 10:21:54 +00:00
[https://gitlab.com/ChristianPauly/fluffychat-flutter/snippets](https://gitlab.com/ChristianPauly/fluffychat-flutter/snippets)
2019-06-09 10:20:59 +00:00
```dart
2020-01-04 10:21:54 +00:00
Client matrix = Client("HappyChat");
2019-06-09 10:20:59 +00:00
```
3. Connect to a Matrix Homeserver and listen to the streams:
```dart
2020-01-02 14:09:49 +00:00
matrix.onLoginStateChanged.stream.listen((bool loginState){
2019-06-09 10:20:59 +00:00
print("LoginState: ${loginState.toString()}");
});
2020-01-02 14:09:49 +00:00
matrix.onEvent.stream.listen((EventUpdate eventUpdate){
2019-06-09 10:20:59 +00:00
print("New event update!");
});
2020-01-02 14:09:49 +00:00
matrix.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
2020-01-02 14:09:49 +00:00
final resp = await matrix.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"
}
);
```