Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@master.technology/websockets
Advanced tools
Readme
This is a cross-platform WebSocket library for IOS and Android. It supports:
Please note, According to some stats (https://www.david-smith.org/iosversionstats/ as of mid-2021) iOS < 13 support is still about 7% of the iOS market.
My code is (c)2015-2022, 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.
I 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.
If you want professional and support plugins; checkout the all new https://proplugins.org
First run tns --version
Run tns plugin add nativescript-websockets
in your ROOT directory of your project.
Run ns plugin add @master.technology/websockets
in your ROOT directory of your project.
Pay 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.
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('@master.technology/websockets');
var mySocket = new WebSocket("ws://echo.websocket.org", [ /* "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('@master.technology/websockets');
var mySocket = new WS("ws://echo.websocket.org",{protocols: [/* 'chat', 'video' */], timeout: 6000, allowCellular: true, headers: { 'Authorization': 'Basic ...' }});
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);});
// When all done with the socket, if you want to clear its memory do
mySocket.unref();
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.
Do to the way GC works, we have to keep a hard reference so that your websocket doesn't disappear mid-use. We automatically call this function on close of browser based websockets. On advanced sockets because you can reopen them again, you are responsible to call this when you are totally done with the socket.
FAQs
A WebSocket NativeScript module for Android and iOS
The npm package @master.technology/websockets receives a total of 134 weekly downloads. As such, @master.technology/websockets popularity was classified as not popular.
We found that @master.technology/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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.