xmpp_stone 0.1.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

XmppStone #

Lightweight XMPP client library written completely in Dart. My intention is to write simple to use library for future XMPP client based on Flutter.

This is actively developing library. Currently supported:

  • RFC6120 - Extensible Messaging and Presence Protocol (XMPP): Core
  • RFC6121 - Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence

Partly supported:

  • XEP-0030: Service Discovery

Actively working on:

  • XEP-0085: Chat State Notifications

Latest news #

  • 2019-04-02: added support for: XEP-0054: vcard-temp

  • 2019-04-01: added support for SHA-1 and SHA-256 authentication algorithm

Usage #

import 'package:xmpp_stone/xmpp_stone.dart' as xmpp;

main() {
  xmpp.Connection connection = new xmpp.Connection("user@domain", "password", 5222);
  connection.open();
}

Features and bugs #

Work in progress

0.1.4 #

  • Fixing some bugs

0.1.3 #

  • Initial published version

example/example.dart

import 'dart:convert';
import 'package:xmpp_stone/xmpp_stone.dart' as xmpp;
import 'dart:io';
import "package:console/console.dart";
import 'package:image/image.dart' as image;

main(List<String> arguments) {
  print("Type user@domain:");
//  var userAtDomain = stdin.readLineSync(encoding: utf8);
  var userAtDomain = 'a1@is-a-furry.org';
  print("Type password");
  var password = '8027';
//  print("Type port");
//  int port;
//  try {
//    port = int.parse(stdin.readLineSync(encoding: utf8));
//  } catch (e) {
//    port = 5222;
//  }
  xmpp.Jid jid = xmpp.Jid.fromFullJid(userAtDomain);
  xmpp.XmppAccount account = xmpp.XmppAccount(userAtDomain, jid.local, jid.domain, password, 5222);
  xmpp.Connection connection = xmpp.Connection(account);
  connection.open();
  xmpp.MessagesListener messagesListener = ExampleMessagesListener();
  ExampleConnectionStateChangedListener(connection, messagesListener);
  xmpp.PresenceManager presenceManager = xmpp.PresenceManager.getInstance(connection);
  presenceManager.subscriptionStream.listen((streamEvent) {
    if (streamEvent.type == xmpp.SubscriptionEventType.REQUEST) {
      print("Accepting presence request");
      presenceManager.acceptSubscription(streamEvent.jid);
    }
  });
}

class ExampleConnectionStateChangedListener implements xmpp.ConnectionStateChangedListener {
  xmpp.Connection _connection;
  xmpp.MessagesListener _messagesListener;

  ExampleConnectionStateChangedListener(
      xmpp.Connection connection, xmpp.MessagesListener messagesListener) {
    _connection = connection;
    _messagesListener = messagesListener;
    _connection.connectionStateStream.listen(onConnectionStateChanged);
  }

  @override
  void onConnectionStateChanged(xmpp.XmppConnectionState state) {
    if (state == xmpp.XmppConnectionState.DoneServiceDiscovery) {
      print("Connected");
      xmpp.VCardManager vCardManager = xmpp.VCardManager(_connection);
      vCardManager.getSelfVCard().then((vCard) {
        if (vCard != null) {
          print("Your info" + vCard.buildXmlString());
        }
      });
      xmpp.MessageHandler messageHandler =
          xmpp.MessageHandler.getInstance(_connection);
      xmpp.RosterManager rosterManager = xmpp.RosterManager.getInstance(_connection);
      messageHandler.messagesStream.listen(_messagesListener.onNewMessage);
      sleep(const Duration(seconds: 1));
      //print("Enter receiver jid: ");
      //var receiver = stdin.readLineSync(encoding: utf8);
      var receiver = "a2@is-a-furry.org";
      xmpp.Jid receiverJid = xmpp.Jid.fromFullJid(receiver);
      rosterManager.addRosterItem(xmpp.Buddy(receiverJid)).then((result) {
        if (result.description != null) {
          print("add roster" + result.description);
        }
      });
      sleep(const Duration(seconds: 1));
      vCardManager.getVCardFor(receiverJid).then((vCard) {
        if (vCard != null) {
          print("Receiver info" + vCard.buildXmlString());
          if (vCard != null && vCard.image != null) {
            var file = File('test456789.jpg')
                ..writeAsBytesSync(image.encodeJpg(vCard.image));
            print("IMAGE SAVED TO: ${file.path}");
          }
        }
      });
      print("write message text:");
      Console.adapter.byteStream().asBroadcastStream().map((bytes) {
        var str = ascii.decode(bytes);
        str = str.substring(0, str.length - 1);
        return str;
      }).listen((String str) {
        messageHandler.sendMessage(receiverJid, str);
      });
    }
  }
}

class ExampleMessagesListener implements xmpp.MessagesListener {
  @override
  onNewMessage(xmpp.MessageStanza message) {
    if (message.body != null) {
      print(format(
          "New Message from {color.blue}${message.fromJid.userAtDomain}{color.end} message: {color.red}${message.body}{color.end}"));
    }
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  xmpp_stone: ^0.1.4

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:xmpp_stone/xmpp_stone.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
62
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-0.81 points)

317 out of 319 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/src/Connection.dart.

Run dartfmt to format lib/src/Connection.dart.

Format lib/src/ConnectionManager.dart.

Run dartfmt to format lib/src/ConnectionManager.dart.

Format lib/src/ConnectionStateChangedListener.dart.

Run dartfmt to format lib/src/ConnectionStateChangedListener.dart.

Fix additional 35 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/StanzaListener.dart (Run dartfmt to format lib/src/StanzaListener.dart.)
  • lib/src/account/XmppAccount.dart (Run dartfmt to format lib/src/account/XmppAccount.dart.)
  • lib/src/chat/Chat.dart (Run dartfmt to format lib/src/chat/Chat.dart.)
  • lib/src/chat/ChatManager.dart (Run dartfmt to format lib/src/chat/ChatManager.dart.)
  • lib/src/chat/Message.dart (Run dartfmt to format lib/src/chat/Message.dart.)
  • lib/src/data/Jid.dart (Run dartfmt to format lib/src/data/Jid.dart.)
  • lib/src/elements/XmppElement.dart (Run dartfmt to format lib/src/elements/XmppElement.dart.)
  • lib/src/elements/nonzas/Nonza.dart (Run dartfmt to format lib/src/elements/nonzas/Nonza.dart.)
  • lib/src/elements/stanzas/AbstractStanza.dart (Run dartfmt to format lib/src/elements/stanzas/AbstractStanza.dart.)
  • lib/src/elements/stanzas/IqStanza.dart (Run dartfmt to format lib/src/elements/stanzas/IqStanza.dart.)
  • lib/src/elements/stanzas/MessageStanza.dart (Run dartfmt to format lib/src/elements/stanzas/MessageStanza.dart.)
  • lib/src/elements/stanzas/PresenceStanza.dart (Run dartfmt to format lib/src/elements/stanzas/PresenceStanza.dart.)
  • lib/src/extensions/vcard_temp/VCard.dart (Run dartfmt to format lib/src/extensions/vcard_temp/VCard.dart.)
  • lib/src/extensions/vcard_temp/VCardManager.dart (Run dartfmt to format lib/src/extensions/vcard_temp/VCardManager.dart.)
  • lib/src/features/BindingResourceNegotiator.dart (Run dartfmt to format lib/src/features/BindingResourceNegotiator.dart.)
  • lib/src/features/ConnectionNegotatiorManager.dart (Run dartfmt to format lib/src/features/ConnectionNegotatiorManager.dart.)
  • lib/src/features/Negotiator.dart (Run dartfmt to format lib/src/features/Negotiator.dart.)
  • lib/src/features/SessionInitiationNegotiator.dart (Run dartfmt to format lib/src/features/SessionInitiationNegotiator.dart.)
  • lib/src/features/StartTlsNegotatior.dart (Run dartfmt to format lib/src/features/StartTlsNegotatior.dart.)
  • lib/src/features/sasl/AbstractSaslHandler.dart (Run dartfmt to format lib/src/features/sasl/AbstractSaslHandler.dart.)
  • lib/src/features/sasl/PlainSaslHandler.dart (Run dartfmt to format lib/src/features/sasl/PlainSaslHandler.dart.)
  • lib/src/features/sasl/ScramSaslHandler.dart (Run dartfmt to format lib/src/features/sasl/ScramSaslHandler.dart.)
  • lib/src/features/servicediscovery/Feature.dart (Run dartfmt to format lib/src/features/servicediscovery/Feature.dart.)
  • lib/src/features/servicediscovery/Identity.dart (Run dartfmt to format lib/src/features/servicediscovery/Identity.dart.)
  • lib/src/features/servicediscovery/ServiceDiscoverySupport.dart (Run dartfmt to format lib/src/features/servicediscovery/ServiceDiscoverySupport.dart.)
  • lib/src/messages/MessageApi.dart (Run dartfmt to format lib/src/messages/MessageApi.dart.)
  • lib/src/messages/MessageHandler.dart (Run dartfmt to format lib/src/messages/MessageHandler.dart.)
  • lib/src/messages/MessagesListener.dart (Run dartfmt to format lib/src/messages/MessagesListener.dart.)
  • lib/src/parser/StanzaParser.dart (Run dartfmt to format lib/src/parser/StanzaParser.dart.)
  • lib/src/presence/PresenceApi.dart (Run dartfmt to format lib/src/presence/PresenceApi.dart.)
  • lib/src/presence/PresenceManager.dart (Run dartfmt to format lib/src/presence/PresenceManager.dart.)
  • lib/src/roster/RosterListener.dart (Run dartfmt to format lib/src/roster/RosterListener.dart.)
  • lib/src/roster/RosterManager.dart (Run dartfmt to format lib/src/roster/RosterManager.dart.)
  • lib/src/sasl/Mechanism.dart (Run dartfmt to format lib/src/sasl/Mechanism.dart.)
  • lib/xmpp_stone.dart (Run dartfmt to format lib/xmpp_stone.dart.)

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field http://www.vukoye.com was unreachable.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (xml).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
console ^3.1.0 3.1.0
crypto ^2.0.6 2.1.4
cryptoutils ^0.4.0 0.4.0
image ^2.0.7 2.1.12
quiver >=2.0.0 <3.0.0 2.1.3
synchronized ^2.1.0 2.2.0
tuple ^1.0.2 1.0.3
unorm_dart ^0.1.1 0.1.2
xml ^3.4.1 3.7.0 4.1.0
Transitive dependencies
archive 2.0.13
args 1.6.0
charcode 1.1.3
collection 1.14.12
convert 2.1.1
matcher 0.12.6
meta 1.1.8
path 1.6.4
petitparser 3.0.2
stack_trace 1.9.3
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
mockito ^4.0.0
test ^1.0.0