패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.1.2

flutter_mqchat

MqChat 클라이언트로, 이 패키지는 MQTT 프로토콜을 채팅 프로토콜로 사용할 수 있게 해줍니다. 브로커는 HiveMq-Chat-Extension 사양을 구현해야 합니다.

AndroidiOSmacOSWindowsLinux
30일 다운로드
32
좋아요
15
Pub 점수
125

패키지 설치

flutter pub add flutter_mqchat

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

FlutterMQChat는 HiveMQ-Chat-Extension 사양을 지원하는 브로커와 함께 사용할 수 있도록 설계된 Flutter 패키지로, MQTT 프로토콜을 사용하여 실시간 채팅 기능을 제공합니다. MQTT의 복잡성을 추상화함으로써 양방향 메시징을 단순화하여 가벼우며 지연이 적은 채팅 애플리케이션에 이상적입니다. Android, iOS, macOS, Windows, Linux 등 여러 플랫폼을 지원하며, 크로스플랫폼 일관성을 보장합니다. 최소한의 오버헤드로 즉시 메시지 전달이 필요한 앱에 특히 유용합니다.

사용 사례

  • 실시간 메시징 앱
  • 사물인터넷 기반 채팅 시스템
  • 크로스 플랫폼 채팅 클라이언트
  • 저지연 통신
  • 협업 도구

주요 기능

  • MQTT 기반 채팅 프로토콜
  • HiveMQ-Chat-Extension 호환
  • 다중 플랫폼 지원
  • 메시지 처리를 위한 간단한 API
  • 경량이고 효율적

적합한 대상

  • 실시간 채팅 기능을 구축하는 개발자
  • 인프라에서 MQTT를 사용하는 팀
  • 확장 가능한 메시징이 필요한 앱
  • 여러 운영 체제를 대상으로 하는 프로젝트
  • 사물인터넷 또는 임베디드 채팅 애플리케이션

고려 사항

  • HiveMQ-Chat-Extension이 있는 브로커가 필요합니다
  • MQTT 호환 환경에만 제한됨
  • 내장된 사용자 인증 없음
  • 외부 브로커 설정에 의존
  • 추가 조치 없이 고보안 채팅에 적합하지 않습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Flutter client of MqChat, a protocol built over MQTT for chatting purposes.

The Broker should install HiveMQ Chat-Extension first.

Features

Use MQTT as a chat protocol, to create a modern chat application that supports all needed features. This is a flutter client of MqChat.

  • [x] Login
  • [x] Send/receive messages (text, image, vide, location, document, contact messages)
  • [x] Send Files
  • [x] Typing indicators
  • [x] Presence
  • [x] Group Chat
  • [x] Private Chat invitation

Getting started

Install the package flutter-mqchat:

flutter pub add flutter-mqchat

Usage

A full and rich example can be found in /example folder.

1. Login

User login using an existing account:

bool connected = await ChatApp.instance()!.clientHandler.connect(
        host: "broker.url.com",
        username: "user@test.com",
        password: "user_pass");

After a successful login, the mqtt client will receive updates. The first updates to be received are profile details, rooms that users is member of, ongoing invitations and messages (if message archiving is supported by the broker).

2. Listen to my profile changes
ChatApp.instance()!.archiveHandler.getUser().listen((user) {
      //insert/update user to database
    });
3. Listen to rooms

Whenever the logged in user is added to a room (or room details changed), the room details will be added to the Conversations stream.

ChatApp.instance()!.archiveHandler.getAllConversations().listen((rooms) {
      //insert/update rooms on the Database
    });
4. Listen to new messages
ChatApp.instance()!.messageReader.getChatMessages().listen((message) {
      var dbMessage = message.toDbMessage();
      // insert the message to the database
      // send chatmarker if the message is not mine
    });
5. Listen to ChatMarkers
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
      }
    });
6. Listen to new chat invitations
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()
          }
    });
7. Listen to invitatioin updates

We use this to listen to the invitations that the user has sent. It could be:

  • Info: When receive an affirmation that the invitation is sent
  • Error: When there is an error (like the user is not found)
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
      }
    });
8. Send a text Message
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]");
8.1 Send the message as regular message
ChatApp.instance()!
          .messageSender
          .sendChatMessage(newMessage, "[room_id]");
8.2 Send the message as a reply to another message
ChatMessage replyToMessage = ...; //the message to reply to
ChatApp.instance()!
          .messageSender
          .replyToMessage(replyToMessage, newMessage, widget.contactChat.roomId);
9. Send File Message
 ChatApp.instance()!.messageSender.sendFileChatMessage(
          type: MessageType.ChatImage,//for example
          fileLocalPath: path,
          room: "[room_id]");
10. Send typing indicator
ChatApp.instance()!
          .eventsSender
          .sendIsTyping(true, "[room_id]");
11. Listen to typing indicator
ChatApp.instance()!.messageReader.getTypingMessages().listen((event) {
    //using event.roomId and event.isTyping and event.fromId, update the ui state
    
    });
12. Send new chat invitation
ChatApp.instance()!
        .eventsSender
        .sendInvitation("[invitee_username]", "[invitation_random_id]");

Additional information

TODO: Tell users more about the package: where to find more information, how to contribute to the package, how to file issues, what response they can expect from the package authors, and more.

카테고리

의존성

의존성 목록 6 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.