{"id":18961959,"url":"https://github.com/lamualfa/fastify-se","last_synced_at":"2026-04-01T19:30:16.488Z","repository":{"id":57233414,"uuid":"202694687","full_name":"lamualfa/fastify-se","owner":"lamualfa","description":"Plugin for fastify server events. https://www.fastify.io/","archived":false,"fork":false,"pushed_at":"2023-07-11T01:08:18.000Z","size":35,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T16:51:56.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lamualfa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-16T08:59:31.000Z","updated_at":"2020-10-23T23:39:28.000Z","dependencies_parsed_at":"2024-10-23T13:05:13.583Z","dependency_job_id":null,"html_url":"https://github.com/lamualfa/fastify-se","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"dd8c3a0230f5b69e66bd1b7ef6c954851b2dfa19"},"previous_names":["laodemalfatih/fastify-se"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamualfa%2Ffastify-se","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamualfa%2Ffastify-se/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamualfa%2Ffastify-se/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamualfa%2Ffastify-se/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamualfa","download_url":"https://codeload.github.com/lamualfa/fastify-se/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239458934,"owners_count":19642101,"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":[],"created_at":"2024-11-08T14:14:49.241Z","updated_at":"2026-04-01T19:30:14.374Z","avatar_url":"https://github.com/lamualfa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-se\n\nFastify plugin for handle Server-sent Events. https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events\n\n## INSTALATION\n\n`npm i fastify-se`\n\n### USAGE\n\n```javascript\nconst fastify_se = require(\"fastify-se\");\n\nconst SE = new fastify_se.SE(opts);\n\nfastify.register(SE.plugin);\n```\n\n### OPTIONS\n\n```javascript\nthis[\"seidGenerator\"] = opts.seidGenerator || defaultSeidGenerator;\nthis[\"stream\"] = opts.stream || stream.PassThrough;\nthis[\"streamOptions\"] = opts.streamOptions || { allowHalfOpen: false };\nthis[\"autoGenerateId\"] = opts.autoGenerateId || true;\nthis[\"serverTimeout\"] = opts.serverTimeout || 120000;\nthis[\"clients\"] = {};\n```\n\n- `seidGenerator` : Return a `seid` (**S**erver **e**vent **ID**) for object key to store `reply` in `clients` object, `clients[seid]= reply;`.\n- `stream` : Stream class will be passing to `reply.send(stream)`.\n- `streamOptions` : Options for create new stream, `new stream(streamOptions)`.\n- `autoGenerateId` : If `true`. The library will automatically create `id` in every `sendEvent`.\n- `serverTimeout` : Set timeout for incoming messages, default `120000ms` or equal to `2s`, in `ms`.\n- `clients` : All active `reply` will be store in this object with `seid` as a key. The `reply` will deleted after connection closed.\n\n### METHODS\n\n- **`reply.sendEvent(data, ?event, ?id, ?retry)` :**\n\n  - `data` : Data will send to client, `string` or `object`.\n  - `event` _(Optional)_ : Event name will emit in client.\n  - `id` _(Optional)_ : ID for every event action.\n  - `retry` _(Optional)_ : Interval time to reconnecting to server if connection lost (In **ms**).\n\n- **`reply.sendEventBySeid(seid, data, ?event, ?id, ?retry)` :**\n  - `seid` : **S**erver **e**vent **ID**, you can get it on `req.seid` in every `http.get` request.\n- **`reply.endEvent()` :** To close the connection and delete `reply` value in `clients` object with key same as `req.seid` value.\n\nYou can see more information about `data`, `event`, `id` and`retry` in : [Server-sent Events - Fields](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Fields).\n\n### EXAMPLE\n\n```javascript\nfastify.get(\"/events\", function(request, reply) {\n  reply.sendEvent(\"hello world\", \"greeting\");\n\n  // OR data with type object\n\n  reply.sendEvent({\n    data: {\n      from: \"@other_people\",\n      message: \"hey guy\",\n      date: \"x-x-x-x\"\n    },\n    event: \"new_private_message\"\n  });\n\n  // If you want to trigger event for other client\n\n  reply.sendEventBySeid(\n    \"@my_friend\", // Your custom seid\n    {\n      data: {\n        from: \"@my_friend\",\n        message: \"my name is x\"\n      },\n      event: \"send_new_message\"\n    }\n  );\n\n  // Important\n  reply.endEvent();\n\n  // reply.sendEvent will throw error if you call it in here\n  reply.sendEvent(\"hello world\", \"greeting\");\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamualfa%2Ffastify-se","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamualfa%2Ffastify-se","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamualfa%2Ffastify-se/lists"}