-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add messaging demonstration to example
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:whixp/whixp.dart'; | ||
|
||
void main() { | ||
final whixp = Whixp( | ||
jabberID: 'vsevex@localhost', | ||
password: 'passwd', | ||
logger: Log(enableWarning: true, enableError: true, includeTimestamp: true), | ||
internalDatabasePath: 'whixp', | ||
reconnectionPolicy: RandomBackoffReconnectionPolicy(1, 3), | ||
); | ||
|
||
whixp | ||
..addEventHandler('streamNegotiated', (_) { | ||
whixp.sendPresence(); | ||
|
||
/// Sending sample message. | ||
whixp.sendMessage(JabberID('alyosha@localhost'), body: 'First message'); | ||
|
||
/// Sending marked message. | ||
const id = StanzaID('random-id'); | ||
whixp.sendMessage( | ||
JabberID('alyosha@localhost'), | ||
body: 'Second message requesting displayed marker', | ||
requestDisplayedInformation: true, | ||
payloads: [id], | ||
); | ||
}) | ||
..addEventHandler<Message>('message', (message) { | ||
if (message == null) return; | ||
if (message.isMarked) { | ||
final messageIDs = message.get<StanzaID>(); | ||
if (messageIDs.isNotEmpty && message.from != null) { | ||
final id = messageIDs.first.id; | ||
whixp.sendDisplayedMessage(message.from!, messageID: id); | ||
} | ||
} | ||
}); | ||
whixp.connect(); | ||
} |