{"id":19460381,"url":"https://github.com/bjarneo/instantly","last_synced_at":"2025-04-25T07:33:02.913Z","repository":{"id":57274954,"uuid":"47889157","full_name":"bjarneo/instantly","owner":"bjarneo","description":"EventSource convenience wrapper","archived":false,"fork":false,"pushed_at":"2018-02-16T09:35:56.000Z","size":98,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-03T01:03:38.210Z","etag":null,"topics":["eventsource","sse"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/instantly","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bjarneo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-12T18:15:15.000Z","updated_at":"2020-11-04T13:46:18.000Z","dependencies_parsed_at":"2022-09-18T07:01:56.220Z","dependency_job_id":null,"html_url":"https://github.com/bjarneo/instantly","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjarneo%2Finstantly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjarneo%2Finstantly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjarneo%2Finstantly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjarneo%2Finstantly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjarneo","download_url":"https://codeload.github.com/bjarneo/instantly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223903679,"owners_count":17222550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eventsource","sse"],"created_at":"2024-11-10T17:36:51.381Z","updated_at":"2024-11-10T17:36:51.964Z","avatar_url":"https://github.com/bjarneo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Instantly](http://i.imgur.com/pXixrM8.png)\n\n# instantly\n\n[![Code Climate](https://codeclimate.com/github/bjarneo/instantly/badges/gpa.svg)](https://codeclimate.com/github/bjarneo/instantly)\n[![Test Coverage](https://codeclimate.com/github/bjarneo/instantly/badges/coverage.svg)](https://codeclimate.com/github/bjarneo/instantly/coverage)\n![Travis](https://travis-ci.org/bjarneo/instantly.svg?branch=master)\n[![Known Vulnerabilities](https://snyk.io/test/npm/instantly/badge.svg)](https://snyk.io/test/npm/instantly)\n\n## What is this?\n\n[EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) wrapper. \u003cbr\u003e\n\nThe EventSource API is easy as it is. Reason I created this was to hide all logic used when I implement EventSource. \u003cbr\u003e\n\nIMPORTANT. This is NOT EventSource Polyfill!\n\n## Installation\n\nIt's available on npm.\n\n```\nnpm install --save instantly\n```\n\n## How can I use this library?\n\nIt's an UMD module. If you don't know what UMD is: [https://github.com/umdjs/umd](https://github.com/umdjs/umd)\n\nThe [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):\n\n```html\n\u003cscript src=\"//unpkg.com/instantly/dist/instantly.umd.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n```js\n// Example\nvar es = new Instantly('http://your-sse-endpoint.codes/channel', {\n    origin: 'http://your-sse-endpoint.codes', // Optional. Just an extra level of precaution to verify your event origin matches your app's origin.\n    retries: 2, // Optional. Default: 5 retries if connection to your endpoint fails.\n    timeout: 1000, // Optional. Default: 15 seconds (15000). This is how often we should retry.\n    closeConnNotFocus: true, // Optional. Default: false. This will close the SSE connection if the tab/window is not in focus. Will reconnect when in focus.\n    error: function(err) {\n        console.log(err);\n    }, // Optional. Extending the internal error handler.\n    open: function(event) {\n        console.log(event);\n    }, // Optional. Extend when you open a connection to SSE.\n    close: function() {\n        console.log('closed');\n    }, // Optional. Extend when a connection to SSE is closed. (Usually when an error occur)\n    injectEventSourceNode: require('eventsource'), // Optional. If the module is being used in Node you're able to inject [eventsource-node](https://www.npmjs.com/package/eventsource)\n});\n\n// If you want to use default options\n// var es = new Instantly('http://your-sse-endpoint.codes/channel');\n\n// Listen to messages without any event set\nes.on('message', function newMessage(msg) {\n    console.log(msg.data);\n});\n\n// Listen to messages with an event set\nes.on('eventName', function newMessage(msg) {\n    console.log(msg.data);\n});\n\n// Start to listen for events send by SSE\nes.listen();\n```\n\nIf you need to close the connection client side\n\n```js\n// Close\nes.close();\n\n// Need to open the connection again?\nes.listen();\n```\n\n## Built in features\n\n* If you send an event with event id 'CLOSE', it'll close your SSE connection with no retries.\n\n## Example\n\nNavigate to example folder\n\n```\nnpm install\nnpm start\n```\n\nOpen your browser in http://localhost:1337\n\n## High performance SSE server\n\n[SSEHub (Server-Sent Events streaming server)](https://github.com/vgno/ssehub)\n\n## Contribution\n\nContributions are appreciated.\n\n## License\n\nMIT-licensed. See LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjarneo%2Finstantly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjarneo%2Finstantly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjarneo%2Finstantly/lists"}