{"id":15707321,"url":"https://github.com/aleksei0807/blinchik","last_synced_at":"2026-04-02T01:51:11.285Z","repository":{"id":34298979,"uuid":"174600860","full_name":"aleksei0807/blinchik","owner":"aleksei0807","description":"FRP WebSocket library made using Kefir","archived":false,"fork":false,"pushed_at":"2023-01-07T03:42:06.000Z","size":1249,"stargazers_count":5,"open_issues_count":54,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-28T15:54:45.922Z","etag":null,"topics":["frp","streams","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aleksei0807.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":"2019-03-08T19:59:13.000Z","updated_at":"2024-02-11T22:48:28.000Z","dependencies_parsed_at":"2023-01-15T06:04:14.261Z","dependency_job_id":null,"html_url":"https://github.com/aleksei0807/blinchik","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksei0807%2Fblinchik","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksei0807%2Fblinchik/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksei0807%2Fblinchik/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksei0807%2Fblinchik/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aleksei0807","download_url":"https://codeload.github.com/aleksei0807/blinchik/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251342718,"owners_count":21574243,"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":["frp","streams","websocket"],"created_at":"2024-10-03T20:39:57.168Z","updated_at":"2026-04-02T01:51:11.248Z","avatar_url":"https://github.com/aleksei0807.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blinchik\n\nA tiny websocket wrapper that made using [Kefir.js](https://kefirjs.github.io/kefir/).\nIt returns a Kefir stream instance.\n\n[![NPM](https://nodei.co/npm/blinchik.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/blinchik/)\n\n### Etymology\n\nBlinchik — diminutive form of [Blin](https://en.wikipedia.org/wiki/Blini).\nBlini frequently made using [Kefir](https://en.wikipedia.org/wiki/Kefir).\n\n### Getting started\n\n0. Installation.\n\n```sh\nnpm i -S blinchik\n```\n\n1. Look into examples.\n\n- [Simple counter example](examples/simple).\n- [Sessions usage example](examples/sessions).\n- [Mock example](examples/mock).\n\nYou can also scale your code using Blinchik.\n\nThat's the client side:\n\n```javascript\nimport Blinchik from 'blinchik'\n\nconst b = new Blinchik('ws://127.0.0.1:8080')\n\nconst stream = b.onMsg({ shouldParseJSON: true })\n\nconst chatStream = stream\n  .filter(({ data }) =\u003e data.type === 'CHAT/INCOMING_MESSAGE')\n\nconst notificationStream = stream\n  .filter(({ data }) =\u003e data.type === 'NOTIFICATION/PAYMENT')\n\nchatStream\n  .log('chat stream')\n  .map(({ data }) =\u003e {\n    // your logic goes here\n  })\n\nnotificationStream\n  .log('notification stream')\n  .map(({ data }) =\u003e {\n    // your logic goes here.\n    // e.g., you can show a popup with the notification\n  })\n```\n\nAnd that's the server side:\n\n```javascript\nimport Blinchik from 'blinchik'\n\nconst b = new Blinchik({ port: 8080 })\n\nconst connectionsStream = b.onConn()\n\nconnectionsStream\n  .onValue(({ conn }) =\u003e {\n    // for demonstration purposes,\n    // on each new connection we send\n    // two messages to the client.\n    // you can implement any custom logic instead.\n    b.send({\n      type: 'CHAT/INCOMING_MESSAGE',\n      text: 'LMAO',\n    }, conn)\n\n    b.send({\n      type: 'NOTIFICATION/PAYMENT',\n      severity: 'error',\n      text: 'Could not process scheduled payment. Please, review your billing settings.',\n    }, conn)\n  })\n```\n\nUsing Blinchik, you can use all Kefir stream methods. See [Kefir docs](https://kefirjs.github.io/kefir/) for more information.\n\n2. You're ready to go ;)\n\n# API\n\n### Blinchik constructor parameters\n\n`new Blinchik(ws, settings)`\n\n`ws` must be one of:\n\n- undefined (for creating mock instance)\n- Blinchik instance (for using mock instance)\n- String (node \u0026 browser client only): `wss://ws.example.com/connections`.\n- Object (server only): [`WebSocket.Server` options](http://npmjs.com/ws) from `ws` library\n- WebSocket or WebSocket.Server from ws library\n- Standard [WebSocket object](https://developer.mozilla.org/ru/docs/Web/API/WebSocket)\n\n`settings` is an optional object with:\n\n- `disableReconnect` (node \u0026 browser client only, Boolean, default: false): disables automatic failover behaviour,\n  which will try to reconnect to a broken connection each `reconnectInterval` ms.\n- `reconnectInterval` (node \u0026 browser client only, Number, default: 2000): failover reconnection interval in milliseconds.\n- `mock` mock Blinchik instance or array mock Blinchik instances\n\n### Blinchik instance properties\n\n`ws` eighter is one of:\n\n- WebSocket or WebSocket.Server from ws library\n- Standard [WebSocket object](https://developer.mozilla.org/ru/docs/Web/API/WebSocket)\n\nBlinchik instance will use this connection.\n\n### Blinchik methods for both server and clients\n\n- `onError(callback)`: sets error handler for current instance. Callback should accept an error. Error type depends on mode.\n- `onClose(callback)`: sets connection close handler for current instance. Callback should accept an error. Error type depends on mode.\n- `onMessage(options)`: returns Kefir stream of connection messages.\n  - `options` is an optional object with `shouldParseJSON` boolean flag, that enables automatic data parsing.\n- `onMsg`: alias for `onMessage`\n- `send(msg, ws)`: sends given message using current instance connection or given `ws` connection, if passed.\n  This method handles connection state checks and automatic data stringify if given message is an object (which is not a valid WS message).\n\n### Blinchick client methods\n\n- `onOpen(callback)`: sets a handler which executed on successful connection.\n- `onPing(callback)` (only node client): sets a handler for pings.\n  For details, see [`ws` library](http://npmjs.com/ws) docs.\n\n### Blinchik server methods\n\n- `onConnection()`: returns Kefir stream of new connections.\n- `onConn`: alias for onConnection\n- `onHeaders()`: returns Kefir stream which allows set custom headers.\n  This is done by mutating `headers` property of the value.\n\n### Blinchik mock methods\n\n- `connect()`: create mock connection\n\n### helpers\n\n- `setCookie(cookie)(params)`: helper for onHeaders stream.\n\n`cookie` is object with:\n\n  - value?: string;\n  - expires?: string | Date;\n  - name?: string;\n  - isReplace?: boolean;\n  - ttl?: number;\n  - getValue?: () =\u003e string;\n  - getExpires?: () =\u003e string | Date;\n\n`params` is object with:\n\n  - req: Request Object;\n  - headers: Array\u003cstring\u003e;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleksei0807%2Fblinchik","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleksei0807%2Fblinchik","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleksei0807%2Fblinchik/lists"}