Giter Club home page Giter Club logo

dart-sdk's Introduction

Tinode Dart SDK tests

This SDK implements Tinode client-side protocol for multi platform applications based on dart. This is not a standalone project. It can only be used in conjunction with the Tinode server. You can find released packages and versions on pub page.

Installation

Depend on it

Run this command for dart applications:

dart pub add tinode

Run this command for flutter applications:

flutter pub add tinode

Import it

Now in your Dart code, you can use:

import 'package:tinode/tinode.dart';

Getting support

  • Read server-side API documentation to know about packets.
  • A complete documentation will be created soon.
  • You can see a simple example in ./example directory.
  • For bugs and feature requests open an issue

Platform support

  • Servers
  • Command-line scripts
  • Flutter mobile apps
  • Flutter desktop apps

dart-sdk's People

Contributors

or-else avatar rxmoein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dart-sdk's Issues

onPres can not will be triggered when a `pres` message is received

lib/src/models/server-messages.dart

static PresMessage fromMessage(Map<String, dynamic> msg) {
    return PresMessage(
      topic: msg['msg'],
      src: msg['src'],
      what: msg['what'],
      seq: msg['seq'],
      clear: msg['clear'],
      delseq:
          msg['delseq'] != null && msg['delseq'].length != null ? msg['delseq'].map((seq) => DeleteTransactionRange.fromMessage(seq)).toList() : [],
      ua: msg['ua'],
      act: msg['act'],
      tgt: msg['tgt'],
      acs: msg['acs'] != null ? AccessMode(msg['acs']) : null,
      dacs: msg['dacs'] != null ? AccessMode(msg['dacs']) : null,
    );
  }
}

需要改为

static PresMessage fromMessage(Map<String, dynamic> msg) {
    return PresMessage(
      topic: msg['topic'],
      src: msg['src'],
      what: msg['what'],
      seq: msg['seq'],
      clear: msg['clear'],
      delseq:
          msg['delseq'] != null && msg['delseq'].length != null ? msg['delseq'].map((seq) => DeleteTransactionRange.fromMessage(seq)).toList() : [],
      ua: msg['ua'],
      act: msg['act'],
      tgt: msg['tgt'],
      acs: msg['acs'] != null ? AccessMode(msg['acs']) : null,
      dacs: msg['dacs'] != null ? AccessMode(msg['dacs']) : null,
    );
  }
}

否则

grp!.onPres.listen

无法获取到最新的数据

How to know who send message to me?

In the flutter project, I copy example code to test

tinode = Tinode('Moein', ConnectionOptions(apiKey: key, host: host, secure: false), false);
await tinode.connect();
await tinode.loginBasic('alice', 'alice123', null);
var me = tinode.getMeTopic();
  me.onSubsUpdated.listen((value) {
    for (var item in value) {
      print('Subscription update: ' + item.public.toString() +  ' - Unread Messages:' + item.unread.toString());
    }
  });
  me.onContactUpdate.listen((value) {
    print('Contact Update: ' + value.toString());
  });
  me.onPres.listen((value) {
    print("Me Receive Pres message:" + value.toString());
  });
  // me.onAllMessagesReceived.listen((value) {
  //   print("All message receive:" + value.toString());
  // });
  // me.onInfo.listen((value) {
  //   print("Info event:" + value.toString());
  // });
  // me.onMetaSub.listen((value) {
  //   print("meta sub event:" + value.toString());
  // });
  await me.subscribe(MetaGetBuilder(me).withLaterSub(null).build(), null);
  
  var grp = tinode.getTopic('grpT9wlZYxma0Q');
  grp.onData.listen((value) {
    if (value != null) {
      print('DataMessage: ' + value.content);
    }
  });
  await grp.subscribe(MetaGetBuilder(grp).withLaterSub(null).withLaterData(null).build(), null);
  var msg = grp.createMessage('This is cool', true);
  await grp.publishMessage(msg);

When I login in by another account, and send a message to the group. I can see log: DataMessage: xxxx
But can't see any log If sending a message to the user "alice" directly.

  1. what event should be bind to get who sends a message and what's the message content?
  2. Are there any plan to explain dart sdk?

How to use the library?

After login, I cannot figure out how to do these things:

  • Get list of topic
  • Find other user
  • Get list message of topic
  • Listen to the incoming message of topic.
  • Listen to the typing message.

Can you add more examples for these?

Explain method _updateDeletedRanges()

Trying to understand this method but have no clue.
Could you explain the purpose of the method?

  /// Calculate ranges of missing messages
  void _updateDeletedRanges() {
    var ranges = <DataMessage>[];
    DataMessage prev;

    // Check for gap in the beginning, before the first message.
    var first = _messages.length > 0 ? _messages.getAt(0) : null;

    if (first != null && _minSeq > 1 && !_noEarlierMsgs) {
      // Some messages are missing in the beginning.
      if (first.hi != null && (first.hi ?? 0) > 0) {
        // The first message already represents a gap.
        if ((first.seq ?? 0) > 1) {
          first.seq = 1;
        }
        if ((first.hi ?? 0) < _minSeq - 1) {
          first.hi = _minSeq - 1;
        }
        prev = first;
      } else {
        // Create new gap.
        prev = DataMessage(seq: 1, hi: _minSeq - 1);
        ranges.add(prev);
      }
    } else {
      // No gap in the beginning.
      prev = DataMessage(seq: 0, hi: 0);
    }

    // Find gaps in the list of received messages. The list contains messages-proper as well
    // as placeholders for deleted ranges.
    // The messages are iterated by seq ID in ascending order.
    _messages.forEach((data, i) {
      // Do not create a gap between the last sent message and the first unsent.
      if (data.seq! >= _configService.appSettings.localSeqId) {
        return;
      }

      // New message is reducing the existing gap
      if (data.seq == ((prev.hi != null && prev.hi! > 0) ? prev.hi : prev.seq)! + 1) {
        // No new gap. Replace previous with current.
        prev = data;
        return;
      }

      // Found a new gap.
      if (prev.hi != null && prev.hi != 0) {
        // Previous is also a gap, alter it.
        prev.hi = data.hi! > 0 ? data.hi : data.seq;
        return;
      }

      // Previous is not a gap. Create a new gap.
      prev = DataMessage(
        seq: (data.hi! > 0 ? data.hi! : data.seq)! + 1,
        hi: data.hi! > 0 ? data.hi : data.seq,
      );
      ranges.add(prev);
    }, null, null);

    // Check for missing messages at the end.
    // All messages could be missing or it could be a new topic with no messages.
    var last = _messages.length > 0 ? _messages.getLast() : null;
    var maxSeq = max(seq!, _maxSeq);
    if ((maxSeq > 0 && last == null) || (last != null && (((last.hi != null && last.hi! > 0) ? last.hi : last.seq)! < maxSeq))) {
      if (last != null && (last.hi != null && last.hi! > 0)) {
        // Extend existing gap
        last.hi = maxSeq;
      } else {
        // Create new gap.
        ranges.add(DataMessage(seq: last != null ? last.seq! + 1 : 1, hi: maxSeq));
      }
    }

    // Insert new gaps into cache.
    ranges.map((gap) {
      _messages.put([gap]);
    });
  }

Tinode Connect and Disconnect Issue

Hi, I'm coming again.
I initialized the Tincode as below codes on app startup:

if (tinode == null){
        tinode = Tinode(
            'Wow',
            ConnectionOptions(WebSocketUtils.WsUrl, WebSocketUtils.ApiKey, secure: true),
            ApiConstant.isDebug);
}
 
CtrlMessage connectResult = await tinode.connect();
if (connectResult.code < 300) {
  isConnect = true;
}

When the user logout, call the disconnect method and set the tinode instance to null:

disConnect() {
    tinode.disconnect();
    tinode = null;
}

But after the user signs in again, I re-call the initialization method, it throws the error:

Invalid argument(s): Object/factory with  type ConfigService is already registered inside GetIt. 
      throwIf (package:get_it/get_it_impl.dart:7:18)
#1      _GetItImplementation._register (package:get_it/get_it_impl.dart:800:5)
#2      _GetItImplementation.registerSingleton (package:get_it/get_it_impl.dart:585:5)
#3      Tinode._registerDependencies (package:tinode/tinode.dart:123:13)
#4      new Tinode (package:tinode/tinode.dart:114:5)
#5      WebSocketUtils.connectService (package:wow/pages/home/messages/websocket_utils.dart:37:18)
#6      WebSocketUtils.login (package:wow/pages/home/messages/websocket_utils.dart:54:13)
<asynchronous suspension>

I'm not sure what's problem is, is my disconnect not correct?
Thanks

Call setMeta error

I want to update my profile as below code:

var _public = new Map();
_public.putIfAbsent("fn", () => _myProfile.nickName);
_public.putIfAbsent("photo", () => _myProfile.avatar);
_public.putIfAbsent("gender", () => _myProfile.gender);

var me = await WebSocketUtils.getInstance().tinode.getMeTopic();
me.setMeta(new SetParams(desc: new TopicDescription(public: _public))).then((value) {
LogUtil.v(value);
return value;
}, onError: (error) {
LogUtil.e(error);
return null;
});

But throw the error:
Converting object to an encodable object failed: Instance of 'TopicDescription'
cause: NoSuchMethodError: Class 'TopicDescription' has no instance method 'toJson'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.