Scaledrone Blog
Mar 30th, 2018

JavaScript Library Updates

Over the past few weeks, we have been making updates to the JavaScript library. These improvements will make your life easier when integrating with Scaledrone. All of the changes are backwards compatible, offering a simpler alternative to the existing features.

Optional listeners

To simplify subscribing to messages we removed the requirement for the open and authenticate listeners. You can now subscribe to rooms right after creating a new Scaledrone instance.

Previously:

const drone = new Scaledrone(id);
drone.on('open', error => {
  const room = drone.subscribe('myroom');
  //...
});

New, simplified syntax:

const drone = new Scaledrone(id);
const room = drone.subscribe('myroom');
//...

Better error handling

Listener callbacks such as error, open and authenticate are used throughout the library to catch errors. However, if you failed to hook up all of the correct listeners you ran into the possibility of missing some errors.

In the new version of the JavaScript library, any error that does not have a specific listener set up for automatically gets sent to the default error handler.

const drone = new Scaledrone(id);
drone.on('error', error => {
  // now catches all unhandled errors
});
//...

A minimal WebSockets-only version of the library

Due to popular demand, we have released a WebSockets-only version of the JavaScript library. It's a drop-in replacement for the full library that only runs on modern browsers. The lite version of the library is three times smaller than the full one.

WebSockets-only JavaScript library:

<script type='text/javascript' src='https://cdn.scaledrone.com/scaledrone-lite.min.js'></script>

Conclusion

Hopefully, these changes will make your life easier!

If you have any questions or feedback feel free to contact us.

Scaledrone is a realtime messaging service and platform.
Send live updates, create chatrooms and collaborative tools.
Try Scaledrone for free