About this plugin
NS Chat Plugin enables real-time communication between WordPress users using WebSocket technology, powered by the Workerman library.
Key Features:
* Real-time private chat between users
* Visual unread message indicators
* Persistent chat history stored in the database
* Lightweight modular JS + PHP architecture
* Automatic migration and sync of WP users to chat system
* Linux daemon service with SSL support for secure connections
* Future-ready integration with NFS or AWS S3 for file upload/download
Planned Features:
* Message editing and deletion
* Read receipt indicators (message seen)
* File attachments with optional NFS or AWS S3 integration
Ideal for community websites, intranets, or any platform requiring internal messaging without third-party services.
com
WebSocket Server Setup (Linux with SSL)
-
Create a systemd service file:
bash
service
-
Paste the following content:
bash
[Unit]
Description=WebSocket Server for NS Chat (SSL)
target
[Service]
php start
Restart=always
RestartSec=25
User=www-data
Group=www-data
log
log
[Install]
target
-
php:
php
$context = [
'ssl' => [
crt',
key',
'verify_peer' => false,
]
];
-
Set permissions for plugin folder:
bash
sudo chown -R www-data:www-data /path/to/ns-chat/
sudo chmod -R 775 /path/to/ns-chat/
-
Reload and start the daemon:
bash
sudo systemctl daemon-reload
sudo systemctl enable websocket_server --now
sudo systemctl restart websocket_server
sudo systemctl status websocket_server
-
Check logs if needed:
bash
log
log
Custom Port Configuration
By default, the WebSocket server listens on port 2346.
To use a different port:
- Change the port in server.php:
php
0:2346', $context);
-
php:
php
$ws_port = 2346;
-
js:
js
wsPort || 2346;
-
If the port is closed, then open a new port on your server’s firewall:
bash
sudo ufw allow <your-port>/tcp
sudo firewall-cmd --permanent --add-port=<your-port>/tcp
sudo firewall-cmd --reload
sudo iptables -A INPUT -p tcp --dport <your-port> -j ACCEPT
v4
Database Tables
The plugin creates and uses the following tables:
- wp_ns_chat_dialogues
- wp_ns_chat_messages
- wp_ns_chat_users
Tables are created and populated automatically on plugin activation.
User Synchronization
- Initial migration of all users from wp_users to wp_ns_chat_users on plugin activation.
- New registrations are handled by:
php
add_action('user_register', 'ns_chat_add_user_on_registration');
- Profile updates are synced via:
php
add_action('profile_update', 'ns_chat_update_user_data');
You may bind these functions to custom hooks based on your app’s logic.
License
GPLv2 or later