
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
nativescript-websockets
Advanced tools
This is a cross platform WebSocket library for IOS and Android.
My code is (c)2015, Master Technology. All my code is LICENSED under the MIT Licesnse. Any other libraries used may have different licenses; which you may view them by reading the "LICENSE" file.
I do contract work; so if you have a module you want built for NativeScript (or pretty much any other language) feel free to contact me (nathan@master-technology.com).
First run tns --version
Run tns plugin add nativescript-websockets
in your ROOT directory of your project.
Please upgrade to v1.1.3 or later - You can use NPM to upgrade to the latest version by doing a npm install nativescript -g
.
This should only be needed this first time, and currently unfortunately anytime you install new runtimes as the project file gets replaced. Hopefully NativeScript in the future will have the plugins support added which will make this automatic.
There 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.
require('nativescript-websockets');
var mySocket = new WebSockets("ws://192.168.0.1:3000", ["protocol","another protocol"]);
MySocket.addEventListener('open', function (evt) { console.log("We are Open"); evt.target.send("Hello"); });
MySocket.addEventListener('message', function(evt) { console.log("We got a message: ", evt.data); evt.target.close(); });
MySocket.addEventListener('close', function(evt) { console.log("The Socket was Closed:", evt.code, evt.reason);
MySocket.addEventListener('error', function(evt) { console.log(("The socket had an error", evt.error); });
var WS = require('nativescript-websockets');
var mySocket = new WS("ws://192.168.0.1:3000",{protocols: ['chat', 'video'], timeout: 6000, allowCellular: true});
mySocket.on('open', function(socket) { console.log("Hey I'm open); socket.send("Hello"); });
mySocket.on('message', function(socket, message) { console.log("Got a message", message); });
mySocket.on('close', function(socket, code, reason) { console.log("Socket was closed because: ", reason, " code: ", code); });
MySocket.on('error', function(socket, error) { console.log("Socket had an error", error);});
The 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.
The 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.
FAQs
A WebSocket NativeScript module for Android and iOS
The npm package nativescript-websockets receives a total of 734 weekly downloads. As such, nativescript-websockets popularity was classified as not popular.
We found that nativescript-websockets demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.