{"_id":"@c4dt/nativescript-websockets","_rev":"2-f2035faae062e33e4ae8c5ae6b740ff1","name":"@c4dt/nativescript-websockets","dist-tags":{"latest":"1.5.5"},"versions":{"1.5.5":{"name":"@c4dt/nativescript-websockets","version":"1.5.5","description":"A WebSocket NativeScript module for Android and iOS","main":"websockets","nativescript":{"platforms":{"android":"1.5.0","ios":"1.5.0"}},"repository":{"type":"git","url":"git+https://github.com/nathanaela/nativescript-websockets.git"},"keywords":["NativeScript","WebSockets","Development","JavaScript","Android","iOS","Sockets","Websocket"],"author":{"name":"Nathanael Anderson","email":"nathan@master-technology.com"},"contributors":[{"name":"Aleksey Gureiev","email":"spyromus@noizeramp.com","url":"https://github.com/alg"},{"name":"Choi Won","email":"help@myso.kr","url":"https://github.com/myso-kr"},{"name":"Linus Gasser","email":"linus.gasser@epfl.ch","url":"https://github.com/ineiti"}],"bugs":{"url":"https://github.com/nathanaela/nativescript-websockets/issues"},"license":{"type":"MIT & Apache 2.0","url":"https://github.com/nathanaela/nativescript-sqlite/blob/master/LICENSE"},"homepage":"https://github.com/nathanaela/nativescript-websockets","_id":"@c4dt/nativescript-websockets@1.5.5","_nodeVersion":"10.16.1","_npmVersion":"6.9.0","dist":{"integrity":"sha512-sfGHsRiaf5lBk3j0KLkN9yzAjAUgrMyiHJVR7aJFom5I0FrJg2ScK0WaUTl05m37ezqclD/WZWxYLJlwBd6JZQ==","shasum":"6ce831d2b9ad4eddf30894ced8fdce395e721441","tarball":"https://registry.npmjs.org/@c4dt/nativescript-websockets/-/nativescript-websockets-1.5.5.tgz","fileCount":8,"unpackedSize":177541,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdsfztCRA9TVsSAnZWagAAvWcP+QDMV7slFiiiZMa9Ai9u\ncqnxDgEA8u4X7f3uweeVbXeUU1vCtrESg1Piht3fyQe66BrLYpnBd/Mgvdxi\nKwkCf+e5Qm5rrKdMyj46IukLh3qefSm2ymOIz72n6Yrt5xI4tL5+5a2qClsX\nvwwgGKctC73OFQP8b2sLXjPOraffsxtfU3y0HS7qBTnMXHklW+2BNv2kv8T3\nN3mWxZysrnE0HdF+3e3IEHxgiosruDv8nTHqZgh/zPdNfEVd7+qpUtUqYtgJ\nJ+XZWNiMCLzFiFXy1LY4KAK8A1G0BjxZAKAdvSHlmIY6ZeyEoZ3nQh6Sx27w\nVcvH/LcAQmgAgf6OkM2dj6HffCSm/Qk1zBiX77T4vYIX5w5Nfm0c2XlQMX7v\nbtINXRoifXw8eqjeaAsdHy/nNGFfs01c4iW/dqM5ja4V/WXOWrJF9KnAA1Q9\nTYXqrAS78ZkCbAJ6o+Fv4uKoc1u9uUH977ppVofg0ce7MDm6wTPrkWWA0mL1\nb7XH2n06IKhrW5ZwD8X4dQLkJtJyalLebwYDePMWhKiCr509qFUxtogwWEiv\nWHNmiilWCSv4dnjvtq2dxpf71JsEN/ULnzT+hj31z7v6JgogDEn+VPapLxdK\n3Ax3eoGYXa7HBTRgHnmjdSJTfIzdrqf09t/LIbAK47G4OFOwtVinnR+V0Cc/\nWTsj\r\n=ohwx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEMz7YeNu1y+8EkE1w/Mg1wf6ipGdlH15FAa5QGlP1uBAiEA77SRVbzRoY6HC4Y10GH7US7WNIKEX9a8kiANqBQPp1Q="}]},"maintainers":[{"name":"cgrigis","email":"christian.grigis@epfl.ch"},{"name":"c4dt-bot","email":"c4dt-services@listes.epfl.ch"},{"name":"tharvik","email":"valerian.rousset@gmail.com"},{"name":"ineiti","email":"ineiti@gasser.blue"}],"_npmUser":{"name":"ineiti","email":"ineiti@gasser.blue"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nativescript-websockets_1.5.5_1571945709415_0.005891260212856242"},"_hasShrinkwrap":false}},"time":{"created":"2019-10-24T19:35:09.203Z","1.5.5":"2019-10-24T19:35:09.601Z","modified":"2024-05-01T15:08:20.511Z"},"maintainers":[{"email":"ineiti@gasser.blue","name":"ineiti"},{"email":"valerian.rousset@gmail.com","name":"tharvik"},{"email":"c4dt-services@listes.epfl.ch","name":"c4dt-bot"}],"description":"A WebSocket NativeScript module for Android and iOS","homepage":"https://github.com/nathanaela/nativescript-websockets","keywords":["NativeScript","WebSockets","Development","JavaScript","Android","iOS","Sockets","Websocket"],"repository":{"type":"git","url":"git+https://github.com/nathanaela/nativescript-websockets.git"},"contributors":[{"name":"Aleksey Gureiev","email":"spyromus@noizeramp.com","url":"https://github.com/alg"},{"name":"Choi Won","email":"help@myso.kr","url":"https://github.com/myso-kr"},{"name":"Linus Gasser","email":"linus.gasser@epfl.ch","url":"https://github.com/ineiti"}],"author":{"name":"Nathanael Anderson","email":"nathan@master-technology.com"},"bugs":{"url":"https://github.com/nathanaela/nativescript-websockets/issues"},"license":{"type":"MIT & Apache 2.0","url":"https://github.com/nathanaela/nativescript-sqlite/blob/master/LICENSE"},"readme":"[![npm](https://img.shields.io/npm/v/nativescript-websockets.svg)](https://www.npmjs.com/package/nativescript-websockets)\n[![npm](https://img.shields.io/npm/l/nativescript-websockets.svg)](https://www.npmjs.com/package/nativescript-workers)\n[![npm](https://img.shields.io/npm/dt/nativescript-websockets.svg?label=npm%20d%2fls)](https://www.npmjs.com/package/nativescript-websockets)\n\n# NativeScript WebSockets\n\nThis is a cross platform WebSocket library for IOS and Android.   \n\n\n\n## License\nMy code is (c)2015-2019, Master Technology.  All my code is LICENSED under the MIT License. The Android Library is also MIT, the iOS libraries used Apache 2.0; which you may view them by reading the \"LICENSE\" file.\n\nI also do contract work; so if you have a module you want built for NativeScript (or any other software projects) feel free to contact me [nathan@master-technology.com](mailto://nathan@master-technology.com).\n\nIf you want professional and support plugins; checkout the all new [https://proplugins.org](https://proplugins.org)\n\n\n\n## Installation\n\nFirst run `tns --version`\n\n### v1.4 or later\n\nRun `tns plugin add nativescript-websockets` in your ROOT directory of your project.\n\n## Limitations\n* The sending of Protocols support is not fully implemented on both platforms.  Do not depend on this; it only partially works..\n\n## Angular\nPay attention and don't forget to use `NgZone.run()` -- if you don't use it in some cases; your UI may not update when you get data updates.  This is NOT a limitation of this library; but just how Angular works for its change detection system.\n\n## Usage\n\nThere is two possible interfaces for you to use; the Simple WebSocket interface that emulates the browser based WebSockets and a more advanced WebSocket interface where you have more control.\n\n### Browser based Interface\n```js\nrequire('nativescript-websockets');\n\nvar mySocket = new WebSocket(\"ws://echo.websocket.org\", [ /* \"protocol\",\"another protocol\" */]);\nmySocket.addEventListener('open', function (evt) { console.log(\"We are Open\"); evt.target.send(\"Hello\"); });\nmySocket.addEventListener('message', function(evt) { console.log(\"We got a message: \", evt.data); evt.target.close(); });\nmySocket.addEventListener('close', function(evt) { console.log(\"The Socket was Closed:\", evt.code, evt.reason); });\nmySocket.addEventListener('error', function(evt) { console.log(\"The socket had an error\", evt.error); });\n\n```\n\n### Advanced Interface\n```js\nvar WS = require('nativescript-websockets');\n\nvar mySocket = new WS(\"ws://echo.websocket.org\",{protocols: [/* 'chat', 'video' */], timeout: 6000, allowCellular: true, headers: { 'Authorization': 'Basic ...' }});\nmySocket.on('open', function(socket) { console.log(\"Hey I'm open\"); socket.send(\"Hello\"); });\nmySocket.on('message', function(socket, message) { console.log(\"Got a message\", message); });\nmySocket.on('close', function(socket, code, reason) { console.log(\"Socket was closed because: \", reason, \" code: \", code); });\nmySocket.on('error', function(socket, error) { console.log(\"Socket had an error\", error);});\n\n```\n\n### Browser Based WebSockets\n\nThe browser based WebSockets are virtually identical to what you would get if you were using a Browser; they are automatically opened when you create it; all four events have \"event\" objects with different values.  You are not allowed to re-open a closed socket and you have no control over any additional features.  \n\n#### Create and OPENS a new BROWSER based WebSocket\n#### new WebSocket(url, [protocols]);\n##### Parameters\n* URL - (String) - Web Socket URL to open\n* Protocols - OPTIONAL (Array of String) - valid list protocols.  Please see limitations note.   \n\n#### Attaches an event to the WebSocket\n****#### .attachEventListener(EventName, function)\n#### .on(EventName, function)\n##### Parameters\n* EventName - (String) can be \"open\", \"close\", \"message\" and \"error\"\n* function  - (Function) the function that will be called when the event occurs\n\n\n### Advanced WebSockets\n\nThe Advanced WebSockets allow you a lot more control over setting up and creating; in addition if they are closed; you can re-open it without having to reset your events.\n\n#### Create a new Advanced WebSocket\n#### var WS = require('nativescript-websockets');   var ws = new WS(url, options);\n##### Parameters\n* URL - Url to Open\n* Options\n** protocols - (Array of string) - Valid protocols.  (See Limitation note)\n** timeout - timeout  (Defaults to 60,0000ms on IOS amd 10,000ms on Android, setting this to 0 disables timeouts)\n** allowCellular (ios only, defaults to True) - can disable the WebSocket from going over the cellular network\n** sslSocketFactory (android only, defaults to null) - you can pass in your ssl socket factory you want to use.\n\n#### Attaches an event to the WebSocket\n#### .attachEventListener(EventName, function, passedThis)\n#### .on(EventName, function, passedThis)\n##### Parameters\n* EventName - (String) can be \"open\", \"close\", \"message\" and \"error\"\n* Function  - (Function) the function that will be called when the event occurs\n* passedThis - the \"this\" you want the Function to have\n\n#### Opens the WebSocket\n#### .open()\n##### Notes: in the Advanced WebSocket you can re-open a closed WebSocket...\n\n\n\n\n### Common Functions between Advanced and Browser WebSockets\n\n#### Closes the open Socket\n#### .close(code, reason)\n##### Parameters\n* code - OPTIONAL (Number) - code\n* reason - OPTIONAL (String) - reason\n\n#### Sends a Text or Binary Message\n#### .send(message)\n##### Parameters\n* message - String or Array/ArrayBuffer - Text string or Binary Message to send\n\n#### Retrieves the current State\n#### .readyState\n##### Values:\n* 0 - Connection\n* 1 - Open\n* 2 - Closing\n* 3 - Closed\n\n#### The URL you opened\n#### .url\n\n#### Returns the protocol negotiated\n#### .protocol\n##### Please see notes on limitations.\n\n#### Returns true if on IOS\n#### .ios\n\n#### Return true if on Android\n#### .android\n\n#### Remove an Event Listener\n#### .removeEventListener (EventName, function)\n#### .off(EventName, function)\n##### Parameters\n* EventName - (String) - Name of Event (open, close, message, error)\n* function - (optional Function) - If you don't pass any function to this; this will remove ALL event listeners for that event, otherwise it will just remove that one event listener.\n\n#### Check to see if it is open\n#### .isOpen()\n##### Returns true if the connection is open\n\n#### Check to see if it is closed\n#### .isClosed()\n##### Returns true if the connection is closed\n\n#### Check to see if it is connecting\n#### .isConnecting()\n##### Returns true if the connection is connecting\n\n#### Check to see if the connection is closing\n#### .isClosing()\n##### Returns true if it is in the process of closing...\n\n\n## Tutorials\n\nNeed a little bit more help getting up and running with NativeScript Websockets?  Check out these tutorials for NativeScript on the subject.\n\n* [Communicate with Websockets in a NativeScript Angular Application](https://www.thepolyglotdeveloper.com/2017/01/communicate-with-websockets-in-a-nativescript-angular-application/)","readmeFilename":"README.md"}