Skip to content

Commit df5d6a1

Browse files
authored
Merge pull request #7 from micilini/phase-07-private-chat-direct
phase 07: add private direct messaging
2 parents 20fde9e + 03ddf7b commit df5d6a1

10 files changed

Lines changed: 2182 additions & 8 deletions

File tree

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The project is currently in the **Composer foundation phase**.
1212

1313
This means the repository already has the initial Composer package structure, PSR-4 namespace configuration, base configuration classes, PHPUnit setup, PHPStan setup, PHP CS Fixer setup, and GitHub Actions workflow.
1414

15-
The modern WebSocket runtime is not implemented yet.
15+
The modern WebSocket runtime, global chat examples, callback-based MediumChat example, and first direct private chat example are now implemented.
1616

1717
## Installation for development
1818

@@ -102,6 +102,28 @@ MediumChat demonstrates high-level callbacks such as `user.joined`, `user.left`,
102102

103103
EasyChat and MediumChat also include typing indicators and simple message status receipts for sent, received, and read states.
104104

105+
## Running the PrivateChat example
106+
107+
Start the WebSocket server:
108+
109+
```bash
110+
php examples/private-chat/server.php
111+
```
112+
113+
Open a second terminal and start the browser UI:
114+
115+
```bash
116+
php -S 127.0.0.1:8002 -t examples/private-chat/public
117+
```
118+
119+
Then open:
120+
121+
```txt
122+
http://127.0.0.1:8002
123+
```
124+
125+
PrivateChat demonstrates global chat plus direct 1:1 private conversations. A direct message is delivered only to the sender and the selected recipient.
126+
105127
## Requirements
106128

107129
The modern version targets:

examples/private-chat/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# PrivateChat Example
2+
3+
PrivateChat is the direct messaging example for PHPSockets With WebSockets.
4+
5+
It demonstrates:
6+
7+
- Unique display names.
8+
- Online users list.
9+
- Global room.
10+
- Private direct 1:1 conversations.
11+
- Direct messages delivered only to the sender and the selected recipient.
12+
- Typing indicators for global and direct conversations.
13+
- Simple message receipts for sent, received and read states.
14+
- Safe rendering with `textContent`.
15+
- Plain HTML, CSS and JavaScript.
16+
- Bootstrap through CDN.
17+
18+
## Requirements
19+
20+
From the project root:
21+
22+
```bash
23+
composer install
24+
```
25+
26+
The PHP `sockets` extension must be enabled.
27+
28+
## Running the WebSocket server
29+
30+
```bash
31+
php examples/private-chat/server.php
32+
```
33+
34+
By default:
35+
36+
```txt
37+
ws://127.0.0.1:8080
38+
```
39+
40+
## Running the browser UI
41+
42+
Open a second terminal:
43+
44+
```bash
45+
php -S 127.0.0.1:8002 -t examples/private-chat/public
46+
```
47+
48+
Then open:
49+
50+
```txt
51+
http://127.0.0.1:8002
52+
```
53+
54+
## Manual test
55+
56+
Open three browser tabs:
57+
58+
```txt
59+
Tab 1: William
60+
Tab 2: Ana
61+
Tab 3: Bruno
62+
```
63+
64+
Expected behavior:
65+
66+
- All users enter with unique names.
67+
- All users see the online list.
68+
- Global messages appear for everyone.
69+
- William clicks Ana and sends a private message.
70+
- Ana receives the private message.
71+
- Bruno does not receive the private message.
72+
- Ana can reply to William.
73+
- Typing in the private conversation appears only for the selected recipient.
74+
- Message status moves from sent to received/read.
75+
- Duplicate names are rejected.
76+
- User messages are rendered safely without `innerHTML`.
77+
78+
## Important notes
79+
80+
This phase implements direct 1:1 private messaging.
81+
82+
Private group rooms are implemented in the next phase.

0 commit comments

Comments
 (0)