CaoIM 是我做的一套即时通讯,给想自己部署聊天的人用。服务端是 Java,客户端是 Flutter。Android、iOS、Windows、macOS 和 Web 共用一份客户端代码。
客户端长什么样
桌面端打开是三栏。左边会话,中间聊天,看群的时候右边是资料。手机端是底部三个页签:消息、通讯录、我的。浏览器里也是这套界面,不是单独再写一个网页版。
能发的内容包括文字、表情、图片、拍照、语音、文件和短视频。消息可以引用、转发、撤回和收藏。会话支持置顶、免打扰和未读数,停在某个聊天里时,这个会话不再继续加未读。
通讯录里可以处理好友申请、改备注、拉黑,也可以搜索用户,或者扫码加好友、扫码进群。群资料里有名称、公告、管理员、禁言、入群验证和群昵称。成员头像会拼在一起。
私聊右上角可以发起语音或视频,目前只做一对一。有呼叫铃声,视频可以本地预览、切换摄像头。群通话没有做。示例里只配了公共 STUN,局域网通常没问题,公网很多时候要自己加 TURN。
也支持深色模式。应用在后台时,可以弹出新消息通知。
服务端各管一段
仓库是拆开的,方便单独看:
- im-server:好友、群、历史消息、已读、离线同步、WebSocket,还有一对一通话信令。端口 8080
- app-server:注册、登录、资料、文件上传。端口 8081
- im-admin:运营后台,Vue 3。可以启停用户、解散群、检索消息、管敏感词和权限
- push-server:可选。对方不在线时发系统通知
- im-sdk-flutter:长连接、本地库、会话和信令,不画界面
- flutter-demo:上面说的那个客户端
文本走长连接。图片和文件先上传到 app-server,消息里只留地址。存储可以是本地目录,也可以是 S3 兼容的对象存储。
登录成功会拿到两把令牌。token 用来访问 app-server,imToken 用来连接 im-server。后台通过内部令牌调用消息服务的管理接口,不直接改业务表。
对方在线就立刻推送,不在线就等上线拉取。已读会回给发送方,群里看到的是已读人数。
怎么运行
JDK 17、Maven 3.6、MySQL 5.7(utf8mb4)。Flutter 3,Dart 3.11 及以上。后台页面需要 Node.js 18。
mysql -u root -p < im-server/sql/schema.sql
mysql -u root -p < app-server/sql/schema.sql
cd im-server && mvn clean install -DskipTests
cd im-server/im-boot && mvn spring-boot:run
cd app-server && mvn spring-boot:run
cd flutter-demo && flutter pub get && flutter run
Windows PowerShell 里不要用 &&,进目录分开执行。
默认管理端账号是 admin / admin123,页面在 http://localhost:5173。上线后要改掉这个密码,也要换 JWT 密钥。手机调试时,服务器地址写成电脑的局域网 IP,localhost 在手机上指的是手机自己。
语音转文字、群通话、支付和小程序都不在当前代码里。一对一通话的媒体不经过服务器,服务器只转发信令。
代码在 GitHub、Gitee 的 cao-im 组织:
其余仓库从 README 的表格可以点过去。学习和个人使用免费,不用另外联系。商用也不收费,但需要先取得授权。
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
CaoIM is an instant newsletter I make for people who want to deploy themselves to chat. The service is Java, the client is Flutter. Android, iOS, Windows, MacOS and Web share a client code.
What does the client look like?
Desktopend opens in three columns. Left-hand session, middle chat, right-hand view. The end of the cell phone is three page signs at the bottom: message, address book, mine. The interface is also in the browser, not a separate web version.
The text, expression, pictures, photographs, voice, documents and short video are available. Messages can be quoted, forwarded, withdrawn and collected. The session supports topsetting, free of disturbance and unreading, and stops in a chat while the session does not continue unreading.
The address book can handle friends' applications, re-notes, blackouts, search users, or scan friends and scan groups. The data set includes names, bulletins, administrators, taboos, entry verifications and group nicknames. Members' heads will be spelled together.
The top right corner of private conversations can initiate voice or video, and only one on one. There are call bells, videos can be previewed locally, cameras switched. Group calls didn't do. The example is limited to public STUN, and the local area network is usually fine, and the public network often adds its own TURN.
It also supports dark patterns. When applied backstage, you can eject new messages.
Service lines
The warehouse is unopened and can be seen alone:
- im-server: Friends, Group, History, Read, offline Sync, WebSocket and one-on-one call. Port 8080
- App-server: registration, log-in, information, document upload. Port 8081
- im-admin: Operating backstage, Vue 3. You can disable the user, break up the group, retrieve the message, phrase and permission.
- push-server: optional. They're not on-line.
- im-sdk-flutter: long connection, local library, session and message, unpainted Noodles.
-Flutter-demo: The client.
text. Pictures and files are uploaded to app-server and only addresses are left in the message. Storage can be either a local directory or a S3 compatible object storage.
Login successfully will get two tokens. Token used to access app-server, imToken used to connect im-server. The back office calls the management interface of the message service through an internal token and does not change the business sheet directly.
It's on-line and off-line. Reads are returned to the sender and the group sees the number of readers.
How?
JDK 17, Maven 3.6, MySQL 5.7 (utf8mb4). Flutter 3, Dart 3.11 and above. Backstage page requires Node.js18.
mysql -u root -p < im-server/sql/schema.sql
mysql -u root -p < app-server/sql/schema.sql
cd im-server && mvn clean install -DskipTests
cd im-server/im-boot && mvn spring-boot:run
cd app-server && mvn spring-boot:run
cd flutter-demo && flutter pub get && flutter run
Windows PowerShell does not operate separately from & & in the directory.
The default management account number is admin / admin123, page at http://localhost:5173. Change the password when you go online and change the JWT key. When the cell phone is debugged, the server address is the computer's LAN IP, localhost on the phone means the cell phone itself.
Voiceover text, group calls, payments and applets are not in the current code. One-on-one media does not pass through the server, which forwards only messages.
Code in the cao-im organization of GitHub, Gitee:
The rest of the warehouse can go past the README form. Learning and personal use is free of charge, without separate contact. There is no commercial charge, but authorization is required.
Auto-fetched and translated by AI Atlas. All rights belong to the original author.