Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
sse.io-client
Advanced tools
JavaScript Client For SSE-IO. You can use it with Node.js or as a browser polyfill for browsers that don't have native EventSource support.
You can serve the file sse.io-client.js
found in the dist
folder or include it via CDN
<script src="/dist/sse.io-client.js"></script>
<script>
var client = sseio.client('http://localhost', ['event']);
client.start();
client.onMessage(function(data) {
console.log(data);
})
client.onError(function(err) {
console.error(err);
})
</script>
Import using ES6
import * as sseio from 'sse.io-client';
const client = sseio.client('http://localhost', ['event']);
you should always create a client first
url
(String, Required) url path for SSE connection.events
(Array[String], Required) the EventSource
created by client will addEventListener to the events. Also, it will be add to query params to the SSE http request.options
(Object, Optional)
reconnect
(Boolean) (default to true
) client will auto reconnect when can't connect to server, connections closed by server or receiving 5xx http status.backoffOptions
(Object) implements from backo. Client will delay reconnect when receiving 5xx http status or can't connect to server.Client
options
(Object, Optional)
headers
(Object) implements from eventsoureproxy
(String) implements from eventsourehttps
(Object) implements from eventsourewithCredentials
(Boolean) when you send CORS request, you can set it to true
to enable sending cookie.forceXhr
(Boolean) use XMLHttpRequest
when Fetch
is not support by some browers.queryParams
(Object) your custom query parametersCreates a new EventSource, establishing the SSE connection, and register listeners for the events
.
Close the EventSource, as well as closing the SSE connection.
Equals to client.stop() && client.start()
, using the latest options.
params
(Object) your custom query parametersAdd query parameters for SSE request. It will be passed to the server when the SSE connection is established next time.
Whether or not The SSE connection is connected to the server.
event
(String, Required)params
(Object, Optional)Add an event to events
. You can add query params too. Then the client will restart to make it take effect.
event
(String, Required)Remove an event from events
. Then the client will restart to make it take effect.
Register a handler for the event
Event: 'message'
callback
(Function) an Object data
will be passed to the callback function
data.event
(String)data.message
(String)Handle received message from server for the registered events.
client.on('message', (data) => {
// ...
})
Event: 'error'
callback
(Function) an Error
will be passed to the callback function
error.message
(String)error.status
(Number) (default to -1) the http status received from servererror.reason
(String) possible values: 'can't connect to server', 'http error'Handle error message. Including the http error as well as the EventSource
error or close message.
client.on('error', (err) => {
// ...
})
Event: 'connected'
Fired upon a connection.
Event: 'disconnect'
Fired upon a disconnection.
FAQs
JavaScript Client For SSE-IO
The npm package sse.io-client receives a total of 6 weekly downloads. As such, sse.io-client popularity was classified as not popular.
We found that sse.io-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.