flutter mqtt chat client
1.0.0
채팅 목적으로 MQTT를 통해 구축 된 프로토콜 인 MQCHAT의 Flutter Client.
브로커는 HiveMQ 채팅 확장을 먼저 설치해야합니다.
MQTT를 채팅 프로토콜로 사용하여 필요한 모든 기능을 지원하는 최신 채팅 응용 프로그램을 만듭니다. 이것은 mqchat의 플러터 클라이언트입니다.
패키지 설치 flutter-mqchat :
flutter pub add flutter-mqchat
완전하고 풍부한 예제는 /example 폴더에서 찾을 수 있습니다.
기존 계정을 사용하여 사용자 로그인 :
bool connected = await ChatApp . instance () ! .clientHandler. connect (
host : "broker.url.com" ,
username : "[email protected]" ,
password : "user_pass" );성공적인 로그인 후 MQTT 클라이언트는 업데이트를 받게됩니다. 받을 첫 번째 업데이트는 프로필 세부 사항, 사용자가 회원하는 객실, 지속적인 초대장 및 메시지 (중개인이 메시지 보관이 지원되는 경우)입니다.
ChatApp . instance () ! .archiveHandler. getUser (). listen ((user) {
//insert/update user to database
});로그인 한 사용자가 객실에 추가 될 때마다 (또는 객실 세부 사항이 변경됨) 객실 세부 사항이 대화 스트림에 추가됩니다.
ChatApp . instance () ! .archiveHandler. getAllConversations (). listen ((rooms) {
//insert/update rooms on the Database
}); ChatApp . instance () ! .messageReader. getChatMessages (). listen ((message) {
var dbMessage = message. toDbMessage ();
// insert the message to the database
// send chatmarker if the message is not mine
}); ChatApp . instance () !
.messageReader
. getChatMarkerMessages ()
. listen ((markerMessage) {
String messageId = markerMessage.referenceId;
if (markerMessage.status == ChatMarker .displayed) {
//update the database record
} else if (markerMessage.status == ChatMarker .delivered) {
//update the database record
}
}); ChatApp . instance () !
.invitationHandler
. newInvitationsStream ()
. listen ((invitation) {
if (invitation.type == MessageType . EventInvitationRequest ) {
//new invitation request
//insert invitation record to the database, notify the user
}
if (invitation.type == MessageType . EventInvitationResponseAccept || invitation.type == MessageType . EventInvitationResponseReject ) {
//responded to invitation, update the local record and wait the server to sync the new contact (if accepted).
//Do not insert a room, the user will receive a new room details triggered by getAllConversations()
}
});우리는 이것을 사용하여 사용자가 보낸 초대장을들을 수 있습니다. 그것은 될 수 있습니다 :
ChatApp . instance () !
.invitationHandler
. invitationUpdatesStream ()
. listen ((invitation) {
if (invitation.invitationMessageType == InvitationMessageType . INFO ) {
//update the invitation record to be confirmed
}
else if (invitation.invitationMessageType == InvitationMessageType . ERROR ) {
//notify the user, and delete the record in inserted
}
}); ChatMessage newMessage = ChatMessage (
id : "generated_random_id" ,
type : MessageType . ChatText ,
text : "Hello there" ,
roomId : "[room_id]" ,
fromId : "[my_id]" , //optional
sendTime : DateTime . now ().millisecondsSinceEpoch,
fromName : "[my_name]" ); ChatApp . instance () !
.messageSender
. sendChatMessage (newMessage, "[room_id]" ); ChatMessage replyToMessage = ...; //the message to reply to
ChatApp . instance () !
.messageSender
. replyToMessage (replyToMessage, newMessage, widget.contactChat.roomId); ChatApp . instance () ! .messageSender. sendFileChatMessage (
type : MessageType . ChatImage , //for example
fileLocalPath : path,
room : "[room_id]" ); ChatApp . instance () !
.eventsSender
. sendIsTyping ( true , "[room_id]" ); ChatApp . instance () ! .messageReader. getTypingMessages (). listen ((event) {
//using event.roomId and event.isTyping and event.fromId, update the ui state
}); ChatApp . instance () !
.eventsSender
. sendInvitation ( "[invitee_username]" , "[invitation_random_id]" );TODO : 사용자에게 패키지에 대해 더 자세히 알려주십시오 : 더 많은 정보를 찾을 수있는 위치, 패키지에 기여하는 방법, 문제를 제출하는 방법, 패키지 작성자가 기대할 수있는 응답 등.