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
|
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:
|
|
|
|
https://gitlab.com/famedly/famedlysdk/snippets/1904187
|
2019-06-09 10:20:59 +00:00
|
|
|
|
|
|
|
```dart
|
2019-10-02 11:33:01 +00:00
|
|
|
Client matrix = Client("HappyChat", store: Store(this));
|
2019-06-09 10:20:59 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
);
|
2019-06-21 07:41:09 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## 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
|
|
|
```
|