Anychat is a simple and pure Websocket chat plug-in that supports any identity system. The embedded party only needs to provide three apis for real-time communication. Support individual chat, group chat, online and offline, view chat records, offline message push, server absolute control push mechanism, reasonable thread design, support mongodb to store chat records, innate embedded support.

screenshots

Experience Address:

www.threecss.com/AnyChatClie…

Internal flow chart

Advantage:

1. Reasonable thread owning design, login, offline, disconnection thread 1, other services belong to random thread. 2. The server has absolute control. The message is first pushed to everyone's consumption queue, and then each thread pushes the message in rotation. 3. The third-party identity system only needs to provide three apis: identity authentication, friend list or organization member list, and group information acquisition to complete the docking and chat. 4, support for embedded, through the iframe can embed < iframe SRC = "https://ip:port/AnyChatClient/index.html? Token = 5 ffdefd0e1104ebdbc49cc6de538b669 "> < iframe > 5, support chat logs into mongo, improve performance.Copy the code

Project directory structure:

AnyChatServer (directory structure 3276 lines)

| - SRC. Main. Java code (server) | -- AnyChatServer. Properties -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- configuration file (need to modify) | -- generatorConfig. XML -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- mybatis automatically generate configuration files (to generate, Need to modify) | -- org. Anychat | -- action. IdentityAction. Java -- -- -- -- -- -- -- -- -- to get data from the third party identity system (non-default docking identity system, Need to modify) | -- init. InitServlet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- start classes | - directing a -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- chat record store to mongo's expansion pack (if it's not mongo, This package was useless) | - plugin. PaginationPlugin. Java -- -- -- -- -- -- -- mybatis configuration file is automatically generated class start | - protobuf (message packet generation tool)Copy the code

AnyChatClient (912 lines of code)

| | - js (js library) - anychat (anychat folder) (anychat CSS) | -- - | - CSS dist (anychat js packaging version) | - images (anychat image) | - SRC (anychat Js not packaged version) | - lib (js) rely on | -- jquery. Min. Js # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | - juggle - all. Js (decoupling tool library all IN ONE: https://github.com/dianbaer/juggle) or | - juggle -help. Js | - juggle - event. Js (decoupling tool library small require: https://github.com/dianbaer/juggle) | - juggle - websocket. Js | - juggle - mv. Js # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | - jquery. MCustomScrollbar. Concat. Min. Js | - third (third - embed - demo. HTML using style) | -- index. HTML (sample to start the project, Need to modify the link AnyChatServer address) | - third - embed - demo. HTML (third party embedded index. The HTML sample)Copy the code

Connect to a third-party identity system

The default code for connecting to the identity system is:

Github.com/dianbaer/st…

Gitee.com/dianbaer/st…

If you interconnect with other identity systems, you need to provide three apis

Modify AnyChatServer/SRC/main/Java/org/anychat/action/IdentityAction. Java, returns the demand parameters

1. Verify the identity and return user information. 2Copy the code

Embedding and docking flow chart

Version typing: In the root directory of the project, run

ant
Copy the code

AnyChatClient JS source code package

cd AnyChatClient/js/anychat

npm install -g grunt-cli

npm install

grunt
Copy the code

Recommended Environment:

Quick deployment github.com/dianbaer/de…

Jdk-8u121 apache-tomcat-8.5.12 mariadb-10.1.22 centos-7-1611 mongodb 3.4.3 (Optional) Support Html5 browserCopy the code

Release project:

1. Install the database

create database anychat

source ****/anychat.sql
Copy the code

Install the MongoDB database (optional by configuration).

Mongo --host 0.0.0.0 --eval 'db = db.getsiblingDB ("anychat"); db.createUser({user: "anychat",pwd: "123456",roles: [ "readWrite", "dbAdmin" ]})'Copy the code

3. Put ChatConfig in a server path, for example

/home/AnyChatConfig
Copy the code

4. Put anychatServer. properties in the tomcat root directory, for example

/ home/tomcat/AnyChatServer. The properties and modify the corresponding AnyChatConfig config_dir pathCopy the code

5. Add AnyChatClient and anyChatServer. war to Tomcat/Webapps, for example

/home/tomcat/webapps/AnyChatServer.war

/home/tomcat/webapps/AnyChatClient
Copy the code

The Java server is based on Grain

Rely on the following libraries, total (2162 lines, very low learning cost)

Grain-httpclient.jar (289 lines) grain-log.jar (111 lines) grain-mariadb. Jar (48 lines) grain-mongodb. Jar (340 lines) grain-msg. Jar (69 lines) Grain-websocket.jar (109 lines) Grain-websocket.jar (413 lines)Copy the code

Making:

Github.com/dianbaer/gr…

Code:

Gitee.com/dianbaer/gr…

The JS client is based on Juggle

Minimization relies on the following library, total (519 lines, very low learning cost)

Juggle -help.js (33 lines) juggle-event.js (256 lines) juggle-websocket.js (126 lines) juggle-mv.js (104 lines)Copy the code

Making:

Github.com/dianbaer/ju…

Code:

Gitee.com/dianbaer/ba…