{"id":15817181,"url":"https://github.com/numminorihsf/herald-server","last_synced_at":"2026-07-02T07:31:30.066Z","repository":{"id":31146379,"uuid":"34706234","full_name":"NumminorihSF/herald-server","owner":"NumminorihSF","description":"Server for sending messages by publish-subscribe, and whispering.","archived":false,"fork":false,"pushed_at":"2015-11-03T01:36:04.000Z","size":268,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-06T05:22:34.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/NumminorihSF.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-04-28T03:33:07.000Z","updated_at":"2015-05-08T08:10:43.000Z","dependencies_parsed_at":"2022-08-27T09:11:52.697Z","dependency_job_id":null,"html_url":"https://github.com/NumminorihSF/herald-server","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fherald-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fherald-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fherald-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fherald-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NumminorihSF","download_url":"https://codeload.github.com/NumminorihSF/herald-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246586108,"owners_count":20801026,"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-10-05T05:22:44.146Z","updated_at":"2026-07-02T07:31:30.009Z","avatar_url":"https://github.com/NumminorihSF.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"herald-server\n===========================\n\n**v1 is not backward compatible with v0** \n\nUse node.js socket server (udp, tcp, unix) for transport messages (or encrypted messages) through applications.\n\nInstall with:\n\n    npm install herald-server\n\nDependencies:\n\n    crypt-maker\n\n[Documentation by jsDuck. Also in RUS](http://numminorihsf.github.io/herald). \n\n# Usage\n\nSimple example:\n\n```js\n\n    var HeraldServer = require('herald-server');\n    var hs = new HeraldServer({}, 'no');\n    hs.on('error', function(){\n        console.log('HS error:', error);\n    });\n    hs.on('listening', function(){\n        console.log('HS listening on', hs.address());\n    });\n    hs.listen(8765);\n    process.on('SIGINT', function(){\n        hs.close();\n    });\n    process.on('SIGTERM', function(){\n        hs.close();\n    });\n```\n\n# Changes\n\n - Add rpc support.\n - Ping removed (tcp ans unix socket know about connection close). Udp is not recommended.\n - Some procedures can be spawned on server easily.\n - Add JSDuck doc.\n\n# Methods\n\n## new HeraldSever(options[, algorithm[, key]])\n\n`options` is an Object. May be `{}`. Contains properties:\n* `.logger` - Logger object - to log inner events\n* `.whiteList` - Array of strings or regexps. Default `[]`\n* `.welcomeMessage` - String. Then connection opens - send this to socket. Default `'Welcome to Herald Server.'`\n* `.messageMaker` - Object. Some module, that make and parse messages. See below. Default `crypt-maker`\n\n`algorithm` - If need crypt messages - algorithm for crypt. By default doesn't encrypt.\n`key` Encryption key.\n\nIf use `crypt-maker` and if `algorithm \u0026\u0026 algorithm !== 'no'` and no key passed to constructor - throws error.\n\n\n## hs.listen() \n\nArguments passed to method are seems as net.Server.listen method of node.js standard api. Use like:\n\n* `hs.listen(port[, host][, backlog][, callback])`\n* `hs.listen(path[, callback])`\n* `hs.listen(handle[, callback])`\n* `hs.listen(options[, callback])`\n\nOptions are:\n* `options` {Object} - Required. Supports the following properties:\n  * `port` {Number} - Optional.\n  * `host` {String} - Optional.\n  * `backlog` {Number} - Optional.\n  * `path` {String} - Optional.\n  * `exclusive` {Boolean} - Optional.\n* `callback` {Function} - Optional.\n\nFor all info about this see: [https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback](https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback)\n\n## hs.close([callback])\n\nStops the server from accepting new connections and keeps existing\nconnections.\n\n## hs.unref() Experimental\n\nCalling `unref` on a server will allow the program to exit if this is the only\nactive server in the event system. If the server is already `unref`d calling\n`unref` again will have no effect.\n\n## hs.ref() Experimental\n\nOpposite of `unref`, calling `ref` on a previously `unref`d server will *not*\nlet the program exit if it's the only server left (the default behavior). If\nthe server is `ref`d calling `ref` again will have no effect.\n\n# Events\n\n## 'listening'\n\nEmitted when the server has been bound after calling `hs.listen`.\n\n## 'connection'\n\n* {Socket Object} The connection object\n\nEmitted when a new connection is made. `socket` is an instance of\n`net.Socket`. Also where if `socket.header` with header of auth message.\n\n## 'close'\n\nEmitted when the server closes. Note that if connections exist, this\nevent is not emitted until all connections are ended.\n\n## 'error'\n\n* {Error Object}\n\nEmitted when an error occurs.  The `'close'` event will be called directly\nfollowing this event.  See example in discussion of `hs.listen`.\n\n\n# Message format\n\nEvery message should has `header` and `body`.\nIf there is no `header` or `body` - message will not sent.\n\n\n## Authorize\n\n**Be careful** by default without any encrypt algorithm any can connect to your server if he know format.\n\nExample of message to authorize (without encrypt):\n\n```\n    '{\"rpc\":\"herald-server\",\"action\":\"authorize\",\"actionId\":7,\"name\":\"156512\",\n    \"uid\":\"156512_86835\",\"messId\":76688,\"retry\":5,\"timeout\":15000}\\r\\n\n     {\"args\":{\"wellKnown\":\"pHrAsE\",\"name\":\"156512\",\"uid\":\"156512_86835\",\"rand\":459}}\\r\\n\\r\\n' \n```\n\nIf there is some connection with same uid - will not authorize new connection and close it.\n\n\n\n## Message header format\n\nFields:\n* `messId` Number - id of message.\n* `name` String - connection name. Used for whispering and rpc.\n* `uid` String - connection uid. Used for whispering and rpc. Unique for every connect.\n* `retry` Number [optional] - Count of retries of sending this message. If no field - will not retry.\n*Now it is ignored by server. Will work soon.*\n* `timeout` Number [optional] - Duration in ms to wait answer from client. If no field - will not retry.\n*Now it is ignored by server. Will work soon.*\n\nEvent:\n* `whisp` String [optional] - name of connection to send event message.\n* `whispUid` String [optional] - uid of connection to send event message.\n* `event` String - event name. If no `whisp` or `whispUid` sends to all subscribers.\n\nRPC:\n* `actionId` Number - id of action.\n* `action` String - name of action.\n* `rpc` String [optional] - name of connection to send rpc message.\n* `rpcUid` String [optional] - uid of connection to send rpc message.\n* `rpcRegExp` String|RegExp [optional] - regexp to find connections by name to send rpc message.\n\n\n## Message body format\n\nBody can by plain string, json, number or something else, except functions.\n\n## Message examples\n\nExamples shown without any encryption.\n\nRPC by client name message:\n```js\n     '{\"rpc\":\"applicationToCall\",\"action\":\"actionToCall\",\"actionId\":numberActionIdFromSender,\n     \"name\":\"nameOfSender\",\"uid\":\"uidOfSender\",\"messId\":numberMessageId}\\r\\n\n         {\"args\":{argsObject}}\\r\\n\\r\\n' \n```\n\nRPC by client UID message:\n```js\n     '{\"rpcUid\":\"applicationToCall\",\"action\":\"actionToCall\",\"actionId\":numberActionIdFromSender,\n     \"name\":\"nameOfSender\",\"uid\":\"uidOfSender\",\"messId\":numberMessageId}\\r\\n\n         {\"args\":{argsObject}}\\r\\n\\r\\n' \n```\n\nWhispering message:\n```js\n    '{\"whisp\":\"nameOfAppToWhisp\",\"event\":\"someSecretEvent\",\"name\":\"nameOfSender\",\"uid\":\"uidOfSender\",\n    \"messId\":numberMessageId}\\r\\n\"eventBody\"\\r\\n\\r\\n'\n```\n\nEvent message:\n```js\n    '{\"event\":\"someEvent\",\"name\":\"nameOfSender\",\"uid\":\"uidOfSender\",\"messId\":numberMessageId}\\r\\n\"eventBody\"\\r\\n\\r\\n'\n```\n\n# LICENSE - \"MIT License\"\n\nCopyright (c) 2015 Konstantine Petryaev\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumminorihsf%2Fherald-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumminorihsf%2Fherald-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumminorihsf%2Fherald-server/lists"}