Announcing NativeScript-WebSockets!

WooHoo, I have finally released it; http://github.com/NathanaelA/NativeScript-Websockets. I only have been discussing it for almost a month.   I had it working on Android almost a month ago; and then on iOS shortly afterwords.    However, doing documentation; making a easy to use consistent interface, building install routines.   And then fixing BUGS.  Ouch, tracing bugs in NativeScript, iOS and Android and in the two third party libraries I used, was not exactly fun.    But I am very happy with the state of the library now.  The library not only support Text messages; but fully supports binary messages also!

You should be able to do a tns plugin add nativescript-websockets to install it on both iOS and Android.   iOS as usual has a few items you have to do afterwords to the xcode project.  And hopefully by the time you read this post; Telerik will have released v1.2.2 of the iOS runtimes.  They have already tagged the v1.2.2 a couple days ago; so I assume they are running tests.   But until you have the v1.2.2 iOS runtimes you will need to use the workaround I put in as the first issue on the nativescript-websockets repo.

The NativeScript-WebSockets supports TWO interfaces; I'm particularly proud of this feature -- you can do var ws = new WebSocket(url, protocol); just like you would do on a browser and all the functions and events are present so this as far as I can tell fully emulates the web socket on your browser.     The second interface is much more advanced and allows re-connecting on a dead socket and timeout support.    See the documentation for more details on both interfaces.

I would like to thank Nathan Rajlich for his Java_WebSocket library which is what I used as the base of the Android version: https://github.com/TooTallNate/Java-WebSocket

And thank Robert Payne (of Zwopple) for his PocketSocket library which is what I used as the base on the iOS version: https://github.com/zwopple/PocketSocket

 

5 thoughts on “Announcing NativeScript-WebSockets!

  1. Valio Stoychev

    Hey Nathanael,

    this is a great addition to NativeScript. I for one will use it to run the fireBase JavaScript SDK in NativeScript!

    One suggestion will be if you can create a pod for iOS and with 1.3 we should be able to install it directly as part of the NativeScript plugin.

    Greetings!

    Reply
  2. piyush

    Excellent so now i can use node-ddp npm package in nativescript or is there any official package or plugin for DDP client. Actually i am from meteorjs community and very excited in nativescript so wanna connect the meteor app from nativescript through DDP. I saw asteroid-nativescript but haven't tried yet

    Reply
    1. Nathanael Anderson Post author

      I have no idea on this as I haven't actually used DDP or meteor JS. But if the JS code you have uses a standard websocket interface; then my project should work for the websocket part. 😉

      Nathanael A.

      Reply
  3. ffager83

    Hey Nathanael!

    Looking real good, but I'm getting all kinda weird crashing with latest Nativescript 1.3 and nativescript-websockets plugin.. App builds successfully for the ios emulator, but just when its about to start in the emulator it just quits back to console showing: "Session ended without errors."
    App crashing if I include require('./websockets.js');

    Is the plugin compatible with Nativescript 1.3 and/or Xcode 7/iOS9?

    I added the required files that needed to be added to the xcode project.
    Except I couldn't find a file named LibSystem.dylib to be added?
    Is it removed/replaced in Xcode 7/iOS9?

    - Tried the workaround you posted for 1.2.2, but couldn't get any further.

    On some tests I received this:
    - file:///app/websockets.js:65:36: JS ERROR ReferenceError: Can't find variable: PSWebSocketDelegate

    I'm on Mac OS X El Capitan, Xcode 7, IOS9, Nativescript 1.3.. you need to know more? 🙂

    Thank you, and keep up with the great stuff!

    FF

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.