{"_id":"hyco-ws","_rev":"92-c2494c6540f75b54104c20f59c2c291e","name":"hyco-ws","dist-tags":{"latest":"1.0.5"},"versions":{"1.0.2":{"name":"hyco-ws","version":"1.0.2","keywords":["Hixie","HyBi","Push","RFC-6455","WebSocket","WebSockets","real-time"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"hyco-ws@1.0.2","maintainers":[{"name":"microsoft","email":"npmjs@microsoft.com"}],"homepage":"https://github.com/clemensv/azure-relay-hybridconnections#readme","bugs":{"url":"https://github.com/clemensv/azure-relay-hybridconnections/issues"},"dist":{"shasum":"e82295589130e0d82efba9afc6d4e303ce006b02","tarball":"https://registry.npmjs.org/hyco-ws/-/hyco-ws-1.0.2.tgz","integrity":"sha512-vGb8yqLFF/lci1UJNB4A1zYuoVjyDkkfLotEUZr2YNVn2vrGnXpy1civKK2omVIdTksS6Y+YIq4kmU61j8LIcw==","signatures":[{"sig":"MEUCICh92XQK/fR14IqDZNbpBrRWJFJp5DRzdGRaszSdH3qxAiEArT4g0PVKsj43wmg055rQ/VAfDPaEOy/SEp9B6c1rOe0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"e82295589130e0d82efba9afc6d4e303ce006b02","gypfile":true,"private":false,"scripts":{},"_npmUser":{"name":"microsoft","email":"npmjs@microsoft.com"},"repository":{"url":"git+https://github.com/clemensv/azure-relay-hybridconnections.git","type":"git"},"_npmVersion":"3.9.5","description":"xyz","directories":{},"_nodeVersion":"6.2.2","dependencies":{"ws":"1.1.x","crypto":"latest","moment":"latest"},"_npmOperationalInternal":{"tmp":"tmp/hyco-ws-1.0.2.tgz_1478014224647_0.10647556302137673","host":"packages-18-east.internal.npmjs.com"}},"1.0.3":{"name":"hyco-ws","version":"1.0.3","keywords":["Hixie","HyBi","Push","RFC-6455","WebSocket","WebSockets","real-time"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"hyco-ws@1.0.3","maintainers":[{"name":"jtaubensee","email":"jtaubensee@outlook.com"},{"name":"microsoft","email":"npmjs@microsoft.com"}],"homepage":"https://azure.com","bugs":{"url":"https://github.com/Azure/azure-relay-node/issues"},"dist":{"shasum":"ed0e4e838181a003354c6bf5d4bdfc0d294d5368","tarball":"https://registry.npmjs.org/hyco-ws/-/hyco-ws-1.0.3.tgz","integrity":"sha512-UH1UDehScREwKE68vRdZ0YvTIjB6IYGWnuyltvitnETYummYDVYvuEZqZmIc7+fSB17oAUZxp7jBJWnBVpYjXg==","signatures":[{"sig":"MEYCIQDqHV5XSG/jH169T/Q44rXjwrDUm2GJ6azTV6d5wzThiQIhAJUsFCvbHomLugQkjhWYYGxqgm6EhNnhEdpOCFsrbNY4","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"ed0e4e838181a003354c6bf5d4bdfc0d294d5368","gypfile":true,"scripts":{},"_npmUser":{"name":"microsoft","email":"npmjs@microsoft.com"},"repository":{"url":"git+https://github.com/Azure/azure-relay-node.git","type":"git"},"_npmVersion":"3.9.5","description":"This Node package for Azure Relay Hybrid Connections is built on and extends the \r ['ws'](https://www.npmjs.com/package/ws) NPM package. This package \r re-exports all exports of that base package and adds new exports that enable \r integration with the Azu","directories":{},"_nodeVersion":"6.2.2","dependencies":{"ws":"1.1.x","crypto":"latest","moment":"latest"},"_npmOperationalInternal":{"tmp":"tmp/hyco-ws-1.0.3.tgz_1478021357684_0.08731434238143265","host":"packages-18-east.internal.npmjs.com"}},"1.0.5":{"name":"hyco-ws","version":"1.0.5","keywords":["Hixie","HyBi","Push","RFC-6455","WebSocket","WebSockets","real-time"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"hyco-ws@1.0.5","maintainers":[{"name":"jtaubensee","email":"jtaubensee@outlook.com"},{"name":"microsoft","email":"npmjs@microsoft.com"}],"homepage":"https://docs.microsoft.com/en-us/azure/service-bus-relay/","bugs":{"url":"https://github.com/Azure/azure-relay-node/issues"},"dist":{"shasum":"eba3900df4e6f1ae27454a7dc520f777b382e1f2","tarball":"https://registry.npmjs.org/hyco-ws/-/hyco-ws-1.0.5.tgz","integrity":"sha512-ZpG4kvKL1q7M4StVs41IQz5VE4sn0eE1KnOQ+xt9IZ0TdVilAhXfg9+YXSvnHVbNuT1Ff2dZjlmGJrefm+uNbg==","signatures":[{"sig":"MEQCIDzfZWkHspIEJuCe3LlXx6fpzOxQjxblSr/ad3bEwvoeAiBmq3ccBDbecxHPAvSuZRch53n9I7qIMxXXDESCIaO0Dw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"eba3900df4e6f1ae27454a7dc520f777b382e1f2","gypfile":true,"scripts":{},"_npmUser":{"name":"jtaubensee","email":"jtaubensee@outlook.com"},"repository":{"url":"git+https://github.com/Azure/azure-relay-node.git","type":"git"},"_npmVersion":"3.10.8","description":"This Node package for Azure Relay Hybrid Connections is built on and extends the \r ['ws'](https://www.npmjs.com/package/ws) NPM package. This package \r re-exports all exports of that base package and adds new exports that enable \r integration with the Azu","directories":{},"_nodeVersion":"7.0.0","dependencies":{"ws":"1.1.x","http":"latest","util":"latest","crypto":"latest","events":"latest","moment":"latest"},"_npmOperationalInternal":{"tmp":"tmp/hyco-ws-1.0.5.tgz_1490387068557_0.4000116055831313","host":"packages-18-east.internal.npmjs.com"}}},"time":{"created":"2016-11-01T15:30:25.297Z","modified":"2026-07-16T15:49:10.544Z","1.0.2":"2016-11-01T15:30:25.297Z","1.0.3":"2016-11-01T17:29:19.365Z","1.0.5":"2017-03-24T20:24:29.185Z"},"bugs":{"url":"https://github.com/Azure/azure-relay-node/issues"},"author":{"name":"Microsoft Corporation"},"license":"MIT","homepage":"https://docs.microsoft.com/en-us/azure/service-bus-relay/","keywords":["Hixie","HyBi","Push","RFC-6455","WebSocket","WebSockets","real-time"],"repository":{"url":"git+https://github.com/Azure/azure-relay-node.git","type":"git"},"description":"This Node package for Azure Relay Hybrid Connections is built on and extends the \r ['ws'](https://www.npmjs.com/package/ws) NPM package. This package \r re-exports all exports of that base package and adds new exports that enable \r integration with the Azu","maintainers":[{"email":"npmjs@microsoft.com","name":"microsoft1es"},{"email":"microsoft-oss-publishing@microsoft.com","name":"microsoft-oss-releases"},{"email":"jtaubensee@outlook.com","name":"jtaubensee"}],"readme":"# The 'hyco-ws' Package for Azure Relay Hybrid Connections \r\n\r\n## Overview\r\n\r\nThis Node package for Azure Relay Hybrid Connections is built on and extends the \r\n['ws'](https://www.npmjs.com/package/ws) NPM package. This package \r\nre-exports all exports of that base package and adds new exports that enable \r\nintegration with the Azure Relay service's Hybrid Connections feature. \r\n\r\nExisting applications that `require('ws')` can use this package instead \r\nwith `require('hyco-ws')` , which also enables hybrid scenarios where an \r\napplication can listen for WebSocket connections locally from \"inside the firewall\"\r\nand via Relay Hybrid Connections all at the same time.\r\n  \r\n## Documentation\r\n\r\nThe API is [generally documented in the main 'ws' package](https://github.com/websockets/ws/blob/master/doc/ws.md)\r\nand this document describes how this package differs from that baseline. \r\n\r\nThe key differences between the base package and this 'hyco-ws' is that it adds \r\na new server class, that is exported via `require('hyco-ws').RelayedServer`,\r\nand a few helper methods.\r\n\r\n### Package Helper methods\r\n\r\nThere are several utility methods available on the package export that can be \r\nreferenced like this:\r\n\r\n``` JavaScript\r\nconst WebSocket = require('hyco-ws');\r\n\r\nvar listenUri = WebSocket.createRelayListenUri('namespace.servicebus.windows.net', 'path');\r\nlistenUri = WebSocket.appendRelayToken(listenUri, 'ruleName', '...key...')\r\n...\r\n\r\n```\r\n\r\nThe helper methods are for use with this package, but might be also be used by a Node server \r\nfor enabling web or device clients to create listeners or senders by handing them URIs that\r\nalready embed short-lived tokens and that can be used with common WebSocket stacks that do \r\nnot support setting HTTP headers for the WebSocket handshake. Embedding authorization tokens\r\ninto the URI is primarily supported for those library-external usage scenarios. \r\n\r\n#### createRelayListenUri\r\n``` JavaScript\r\nvar uri = createRelayListenUri([namespaceName], [path], [[token]], [[id]])\r\n```\r\n\r\nCreates a valid Azure Relay Hybrid Connection listener URI for the given namespace and path. This \r\nURI can then be used with the relayed version of the WebSocketServer class.\r\n\r\n- **namespaceName** (required) - the domain-qualified name of the Azure Relay namespace to use\r\n- **path** (required) - the name of an existing Azure Relay Hybrid Connection in that namespace\r\n- **token** (optional) - a previously issued Relay access token that shall be embedded in\r\n                         the listener URI (see below)\r\n- **id** (optional) - a tracking identifier that allows end-to-end diagnostics tracking of requests\r\n\r\nThe **token** value is optional and should only be used when it is not possible to send HTTP \r\nheaders along with the WebSocket handshake as it is the case with the W3C WebSocket stack.                  \r\n\r\n\r\n#### createRelaySendUri \r\n``` JavaScript\r\nvar uri = createRelaySendUri([namespaceName], [path], [[token]], [[id]])\r\n```\r\n\r\nCreates a valid Azure Relay Hybrid Connection send URI for the given namespace and path. This \r\nURI can be used with any WebSocket client.\r\n\r\n- **namespaceName** (required) - the domain-qualified name of the Azure Relay namespace to use\r\n- **path** (required) - the name of an existing Azure Relay Hybrid Connection in that namespace\r\n- **token** (optional) - a previously issued Relay access token that shall be embedded in\r\n                         the send URI (see below)\r\n- **id** (optional) - a tracking identifier that allows end-to-end diagnostics tracking of requests\r\n\r\nThe **token** value is optional and should only be used when it is not possible to send HTTP \r\nheaders along with the WebSocket handshake as it is the case with the W3C WebSocket stack.                   \r\n\r\n\r\n#### createRelayToken \r\n``` JavaScript\r\nvar token = createRelayToken([uri], [ruleName], [key], [[expirationSeconds]])\r\n```\r\n\r\nCreates an Azure Relay Shared Access Signature (SAS) token for the given target URI, SAS rule, \r\nand SAS rule key that is valid for the given number of seconds or for an hour from the current \r\ninstant if the expiry argunent is omitted.\r\n\r\n- **uri** (required) - the URI for which the token is to be issued. The URI will be normalized to \r\n                       using the http scheme and query string information will be stripped.\r\n- **ruleName** (required) - SAS rule name either for the entity represented by the given URI or \r\n                            for the namespace represented by teh URI host-portion.\r\n- **key** (required) - valid key for the SAS rule. \r\n- **expirationSeconds** (optional) - the number of seconds until the generated token should expire. \r\n                            The default is 1 hour (3600) if not specified.\r\n\r\nThe issued token will confer the rights associated with the chosen SAS rule for the chosen duration.\r\n\r\n#### appendRelayToken\r\n``` JavaScript\r\nvar uri = appendRelayToken([uri], [ruleName], [key], [[expirationSeconds]])\r\n```\r\n\r\nThis method is functionally equivalent to the **createRelayToken** method above, but\r\nreturns the token correctly appended to the input URI.\r\n\r\n### Class ws.RelayedServer\r\n\r\nThe `hycows.RelayedServer` class is an alternative to the `ws.Server`\r\nclass that does not listen on the local network, but delegates listening to the Azure Relay.\r\n\r\nThe two classes are largely contract compatible, meaning that an existing application using \r\nthe `ws.Server` class can be changed to use the relayed version quite easily. The \r\nmain differences in the constructor and the available options.\r\n\r\n#### Constructor  \r\n\r\n``` JavaScript \r\nvar ws = require('hyco-ws');\r\nvar server = ws.RelayedServer;\r\n\r\nvar wss = new server(\r\n    {\r\n        server : ws.createRelayListenUri(ns, path),\r\n        token: function() { return ws.createRelayToken('http://' + ns, keyrule, key); }\r\n    });\r\n```\r\n\r\nThe `RelayedServer` constructor supports a different set of arguments than the \r\n`Server` since it is neither a standalone listener nor embeddable into an existing HTTP\r\nlistener framework. There are also fewer options available since the WebSocket management is \r\nlargely delegated to the Relay service.\r\n\r\nConstructor arguments:\r\n\r\n- **server** (required) - the fully qualified URI for a Hybrid Connection name on which to listen, usually\r\n                          constructed with the WebSocket.createRelayListenUri() helper.\r\n- **token** (required) - this argument *either* holds a previously issued token string *or* a callback\r\n                         function that can be called to obtain such a token string. The callback option\r\n                         is preferred as it allows token renewal.\r\n\r\n#### Events\r\n\r\n`RelayedServer` instances emit three Events that allow you to handle incoming requests, establish \r\nconnections, and detect error conditions. You must subscribe to the 'connect' event to handle \r\nmessages. \r\n\r\n##### headers\r\n``` JavaScript \r\nfunction(headers)\r\n```\r\n\r\nThe 'headers' event is raised just before an incoming connection is accepted, allowing\r\nfor modification of the headers to send to the client. \r\n\r\n##### connection\r\n``` JavaScript\r\nfunction(socket)\r\n```\r\n\r\nEmitted whenever a new WebSocket connection is accepted. The object is of type ws.WebSocket \r\njust as with the base package.\r\n\r\n\r\n##### error\r\n``` JavaScript\r\nfunction(error)\r\n```\r\n\r\nIf the underlying server emits an error, it will be forwarded here.  \r\n\r\n#### Helpers\r\n\r\nTo simplify starting a relayed server and immediately subscribing to incoming connections,\r\nthe package exposes a simple helper function, which is also used in the samples:\r\n\r\n##### createRelayedListener\r\n\r\n``` JavaScript\r\n    var WebSocket = require('hyco-ws');\r\n\r\n    var wss = WebSocket.createRelayedServer(\r\n        {\r\n            server : WebSocket.createRelayListenUri(ns, path),\r\n            token: function() { return WebSocket.createRelayToken('http://' + ns, keyrule, key); }\r\n        }, \r\n        function (ws) {\r\n            console.log('connection accepted');\r\n            ws.onmessage = function (event) {\r\n                console.log(JSON.parse(event.data));\r\n            };\r\n            ws.on('close', function () {\r\n                console.log('connection closed');\r\n            });       \r\n    });\r\n``` \r\n\r\nvar server = createRelayedServer([options], [connectCallback] )\r\n\r\nThis method is simple syntactic sugar that calls the constructor to create a new \r\ninstance of the RelayedServer and then subscribes the provided callback \r\nto the 'connection' event.\r\n \r\n##### relayedConnect\r\n\r\nSimply mirroring the `createRelayedServer` helper in function, `relayedConnect`\r\ncreates a client connection and subscribes to the 'open' event on the \r\nresulting socket.\r\n\r\n``` JavaScript\r\n    var uri = WebSocket.createRelaySendUri(ns, path);\r\n    WebSocket.relayedConnect(\r\n        uri,\r\n        WebSocket.createRelayToken(uri, keyrule, key),\r\n        function (socket) {\r\n            ...\r\n        }\r\n    );\r\n```","readmeFilename":"README.md","users":{"mscss":true}}