Skip to content

Commit 0a3c0ba

Browse files
authored
Merge pull request #11 from byjg/claude/audit-docs-sidebar-position-011CV2tCp1udEQGEvR4Uvrd4
Audit and organize Docusaurus documentation structure
2 parents c54c8af + 6f2be3c commit 0a3c0ba

File tree

8 files changed

+1204
-185
lines changed

8 files changed

+1204
-185
lines changed

README.md

Lines changed: 45 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -7,233 +7,93 @@
77
[![GitHub release](https://img.shields.io/github/release/byjg/jquery-sse.svg)](https://github.com/byjg/jquery-sse/releases/)
88
[![](https://data.jsdelivr.com/v1/package/npm/jquery-sse/badge)](https://www.jsdelivr.com/package/npm/jquery-sse)
99

10-
A lightweigth jQuery Plugin for Server-Sent Events (SSE) EventSource Polyfill.
11-
This plugin try to use the native EventSource object if it supported by the browser.
12-
If there is no native support the request is made by ajax requests (polling).
10+
A lightweight jQuery Plugin for Server-Sent Events (SSE) EventSource Polyfill.
11+
This plugin tries to use the native EventSource object if it's supported by the browser.
12+
If there is no native support, the request is made by Ajax requests (polling).
1313
You do not need to change the server side nor the client side.
1414

15-
*If you are looking for a SSE Polyfill library without jQuery dependency
15+
*If you are looking for an SSE Polyfill library without jQuery dependency
1616
try [yaj-sse](https://github.com/byjg/yaj-sse). The yaj-sse is a port
1717
from version 0.1.4 of jQuery SSE.*
1818

19-
## Example
19+
## Quick Start
2020

21-
Client Side
21+
### Client Side
2222

2323
```javascript
2424
var sse = $.SSE('http://example.com/sse-server.php', {
25-
onMessage: function(e){
26-
console.log("Message"); console.log(e);
25+
onMessage: function(e){
26+
console.log("Message"); console.log(e);
2727
}
2828
});
2929
sse.start();
3030
```
3131

32-
Server Side
32+
### Server Side
3333

3434
```php
3535
echo "data: My Message\n";
3636
echo "\n";
3737
```
3838

39-
## Dependencies
39+
## Documentation
4040

41-
* jQuery
41+
For comprehensive documentation, please refer to the following guides:
4242

43-
## Install
43+
1. **[Getting Started](docs/getting-started.md)** - Installation, dependencies, and quick start guide
44+
2. **[Usage](docs/usage.md)** - Constructor, methods (start, stop), and basic usage
45+
3. **[Configuration](docs/configuration.md)** - Event callbacks, options, headers, and custom events
46+
4. **[Examples](docs/examples.md)** - Code examples for common use cases and running examples locally
47+
5. **[Known Limitations and Quirks](docs/quirks.md)** - Browser compatibility, Ajax fallback limitations, and debugging tips
48+
6. **[API Reference](docs/api-reference.md)** - Complete API documentation with all methods and properties
49+
7. **[References and Resources](docs/references.md)** - External resources, specifications, and related projects
4450

45-
Just download the repository and point to the jQuery plugin:
51+
## Features
4652

47-
```html
48-
<script src="jquery.sse.js" ></script>
49-
```
53+
- Automatic detection and use of native EventSource when available
54+
- Seamless fallback to Ajax polling when EventSource is not supported
55+
- Support for custom events
56+
- Custom HTTP headers support (automatically uses Ajax mode)
57+
- Automatic reconnection with configurable retry intervals
58+
- Event IDs and Last-Event-ID tracking
59+
- Simple jQuery-style API
60+
61+
## Installation
5062

51-
or
63+
### Direct Download
5264

5365
```html
54-
<script src="jquery.sse.min.js" ></script>
66+
<script src="jquery.sse.min.js"></script>
5567
```
5668

57-
You can also install using bower:
69+
### Bower
5870

5971
```bash
6072
bower install jquery-sse
6173
```
6274

63-
## Usage:
64-
65-
### Constructor
66-
67-
```
68-
var sse = $.SSE(url, settings);
69-
```
70-
71-
* url: URL for the server will be sent the events to this page;
72-
* settings: The events and options for the SSE instance
73-
74-
### Settings List
75-
76-
All the options:
77-
78-
```
79-
var sseObject = $.SSE('sse-server.php', {
80-
onOpen: function (e) {},
81-
onEnd: function (e) {},
82-
onError: function (e) {},
83-
onMessage: function (e) {},
84-
options: {},
85-
headers: {},
86-
events: {}
87-
});
88-
```
89-
90-
**Event onOpen**
91-
92-
Fired when the connection is opened the first time;
93-
94-
```javascript
95-
onOpen: function(e){
96-
console.log("Open"); console.log(e);
97-
},
98-
```
99-
100-
**Event onEnd**
101-
102-
Fired when the connection is closed and the client will not listen for the server events;
103-
104-
```javascript
105-
onEnd: function(e){
106-
console.log("End"); console.log(e);
107-
},
108-
```
109-
110-
**Event onError**
111-
112-
Fired when the connection error occurs;
113-
114-
```javascript
115-
onError: function(e){
116-
console.log("Could not connect");
117-
},
118-
```
119-
120-
**Event onMessage**
121-
122-
Fired when the a message without event is received
123-
124-
```javascript
125-
onMessage: function(e){
126-
console.log("Message"); console.log(e);
127-
},
128-
```
129-
130-
**Custom Options**
131-
132-
Define the options for the SSE instance
133-
134-
```javascript
135-
options: {
136-
forceAjax: false
137-
},
138-
```
139-
140-
* **forceAjax**: Uses ajax even if the EventSource object is supported natively;
141-
142-
143-
**Custom Events**
144-
145-
Fired when the server set the event and match with the key
146-
147-
For example, if you have a custom event called `myEvent` you may use the follow code:
75+
### jsDelivr CDN
14876

149-
```javascript
150-
events: {
151-
myEvent: function(e) {
152-
console.log('Custom Event');
153-
console.log(e);
154-
}
155-
}
156-
```
157-
158-
Server side:
159-
160-
```php
161-
echo "event: myEvent\n"; // Must match with events in the HTML.
162-
echo "data: My Message\n";
163-
echo "\n";
164-
```
165-
166-
**Custom Headers**
167-
168-
You can send custom headers to the request.
169-
170-
```javascript
171-
headers: {
172-
'Authorization': 'Bearer 1a234fd4983d'
173-
}
174-
```
175-
176-
Note: As the EventSource does not support send custom headers to the request,
177-
the object will fallback automatically to 'forceAjax=true', even this it is not set.
178-
179-
180-
## Methods
181-
182-
**start**
183-
184-
Start the EventSource communication
185-
186-
```javascript
187-
sse.start();
188-
```
189-
190-
**stop**
191-
192-
Stop the EventSource communication
193-
194-
```javascript
195-
sse.stop();
196-
```
197-
198-
199-
## Quirks
200-
201-
The ajax does not support the streaming as the event source supports. In that case we recommend
202-
create a server without streaming and set the "retry" to determine query frequency;
203-
204-
Example Server Side:
205-
206-
```php
207-
echo "retry: 3000\n";
208-
echo "data: My Message\n";
209-
echo "\n";
210-
```
211-
212-
## Minify
213-
214-
```
215-
apt install uglifyjs
216-
217-
uglifyjs --compress 'drop_console,drop_debugger' --mangle -r '$,require,exports,_' -o jquery.sse.min.js jquery.sse.js
77+
```html
78+
<script src="https://cdn.jsdelivr.net/npm/jquery-sse@latest/jquery.sse.min.js"></script>
21879
```
21980

220-
## Running the examples
81+
## Browser Support
22182

222-
Start the webserver:
83+
- ✅ Chrome 6+
84+
- ✅ Firefox 6+
85+
- ✅ Safari 5+
86+
- ✅ Opera 11+
87+
- ✅ Edge 79+
88+
- ❌ Internet Explorer (uses Ajax fallback automatically)
22389

224-
```shell
225-
docker run -it --rm -p 8080:80 -v $PWD:/var/www/html byjg/php:7.4-fpm-nginx
226-
```
90+
## Contributing
22791

228-
Open the browser:
229-
http://localhost:8080/examples/sse-client.html
92+
Contributions are welcome! Please feel free to submit pull requests or open issues on GitHub.
23093

231-
## References
94+
## License
23295

233-
* http://www.w3.org/TR/2009/WD-eventsource-20091029/
234-
* https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events
235-
* http://html5doctor.com/server-sent-events/
236-
* http://www.html5rocks.com/en/tutorials/eventsource/basics/
96+
This project is licensed under the MIT License. See the [LICENSE](https://opensource.byjg.com/opensource/licensing.html) file for details.
23797

23898
----
23999
[Open source ByJG](http://opensource.byjg.com)

0 commit comments

Comments
 (0)