dalk_sdk 0.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

A SDK to add a real time chat easily.

Features #

  • Realtime events for conversations and messages
  • Conversations in one to one
  • Message status, sent, received, seen
  • Group conversations
  • Custom subject and avatar for group conversations

Usage #

Installation #

Add this to your package's pubspec.yaml file:

dalk_sdk: ^1.0.0

And run:

pub get

or for Flutter

flutter pub get

Setup #

import 'package:dalk_sdk/sdk.dart';

main() async {
  final currentUser = User(id: 'userId', name: 'userName'); 
  final sdk = DalkSdk('myProjectId', currentUser, (userId) {
    // get user information from webservice, database... and return the corresponding User
  });
  
  await sdk.connect();
}

Manage conversations #

import 'package:dalk_sdk/sdk.dart';

main() async {
  // after setup, you can retrieve the list of conversations of the user
  final conversations = await sdk.getConversations();
  
  // get real time events when new conversations are created
  sdk.newConversation.listen((Conversation conversation) {
    // this get called each time a new conversation is created to let you know new ones
  });

}

Manage a single conversation #

import 'package:dalk_sdk/sdk.dart';

main() async {
  // after setup, you can retrieve a specific conversation of the user by his id
  final conversation = await sdk.getConversation('conversationId');
  
  // get real time events when new message arrived or the status of a message change
  conversation.onMessagesEvent.listen((Message message) {
    // this get called each time a new message arrived or a message status has changed
  });
  
  // you can set custom subject and avatar (group chat only)
  await conversation.setOptions(
    subject: 'subject',
    avatar: 'urlOfTheAvatar',
  );
  
}

Manage message #

import 'package:dalk_sdk/sdk.dart';

main() async {
  // after setup, you can retrieve a specific conversation of the user by his id
  final conversation = await sdk.getConversation('conversationId');
  
  // you can load or refresh messages like this:
  await conversation.loadMessages();
  // messages available in conversation.messages
  
  // send new message to the conversation
  await conversation.sendMessage('my message');

  // set message as read
  await conversation.setMessageAsSeen('myMessageId');

}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.0.6 #

  • fix pubspec info

0.0.5 #

  • add metadata support for message
  • add message update capabilities

0.0.4 #

  • fix connection without avatar

0.0.3 #

  • fix connection without signature

0.0.2 #

  • fix pub warnings

0.0.1 #

  • Initial version

example/main.dart

import 'dart:convert';
import 'dart:io';

import 'package:dalk_sdk/sdk.dart';

void main(List<String> arguments) async {
  final myId = arguments.first;
  final otherId = arguments[1];
  final projectId = arguments.last;

  final me = User(id: myId, name: 'Jimmy');
  final other = User(id: otherId, name: 'Kev');
  Conversation conversation;

  final sdk = DalkSdk(projectId, me);

  sdk.newConversation.listen((newConversation) async {
    print('conversation created: $newConversation');
    conversation = await sdk.getConversation(newConversation.id);
    conversation.onMessagesEvent
        .listen((message) => print('new message event'));
  });

  await sdk.connect();
  print('registration: ok');

  stdin.transform(utf8.decoder).transform(LineSplitter()).listen((line) async {
    if (line == 'create conversation') {
      print('$line with $myId and $otherId');
      conversation = await sdk.createOneToOneConversation(other);
      conversation.onMessagesEvent
          .listen((message) => print('new message: $message'));
      print('conversationId: $conversation');
    } else if (line.startsWith('create conversation')) {
      print('$line with $myId and $otherId');
      conversation = await sdk.createOneToOneConversation(
          User(id: otherId, name: 'Kev'),
          conversationId: line.replaceAll('create conversation', '').trim());
      conversation.onMessagesEvent
          .listen((message) => print('new message: $message'));
      print('conversationId: $conversation');
    } else if (line == 'get conversations') {
      print('$line');
      final conversations = await sdk.getConversations();
      print('conversation: $conversations');
    } else if (line.startsWith('get details')) {
      print('$line');
      conversation =
          await sdk.getConversation(line.replaceAll('get details', '').trim());
      conversation.onMessagesEvent
          .listen((message) => print('new message $message'));
      print('conversation: $conversation');
    } else {
      print('send $line to ${conversation.id}');
      await conversation.sendMessage(message: line);
    }
  });
}

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate dalk_sdk

2. Use it

The package has the following executables:


$ dalk

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dalk_sdk: ^0.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dalk_sdk/sdk.dart';
import 'package:dalk_sdk/sdk_interop.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Jun 1, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Health suggestions

Fix lib/src/sdk_base.freezed.dart. (-0.50 points)

Analysis of lib/src/sdk_base.freezed.dart reported 1 hint:

line 15 col 13: The declaration '_' isn't referenced.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
args ^1.5.2 1.6.0
freezed_annotation ^0.7.1 0.7.1 0.11.0-dev
js ^0.6.1+1 0.6.1+1
json_rpc_2 ^2.1.1 2.2.0
logging ^0.11.4 0.11.4
meta ^1.1.8 1.1.8
retry ^3.0.0+1 3.0.0+1
stream_channel ^2.0.0 2.0.0
web_socket_channel ^1.1.0 1.1.0
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.5
json_annotation 3.0.1
path 1.7.0
stack_trace 1.9.3
typed_data 1.1.6
Dev dependencies
build_runner any
build_web_compilers any
cli_pkg ^1.0.0-beta.6
freezed ^0.10.7
grinder ^0.8.4
mockito ^4.1.1
pedantic ^1.8.0+1
test ^1.6.0