tinode / dart-sdk Goto Github PK
View Code? Open in Web Editor NEWDart SKD for using Tinode messenger in dart and flutter applications.
Home Page: https://pub.dev/packages/tinode
License: Apache License 2.0
Dart SKD for using Tinode messenger in dart and flutter applications.
Home Page: https://pub.dev/packages/tinode
License: Apache License 2.0
After login, I cannot figure out how to do these things:
Can you add more examples for these?
is the sdk ready to use?
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
无法获取到最新的数据
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
I am very interested in this project. Is there a specific update plan? Thank you!
I didn't find the corresponding function in the source code。By the way, when will the documentation be complete?
I want to send a Drafty type message, such as Image via SDK, but cannot find where to set it
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.
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'.
First create a new group, then add new members to it
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]);
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.