SocketCluster / socketcluster-client

JavaScript client for SocketCluster
MIT License
292 stars 91 forks source link

global atob btoa not available in JavaScriptCore and react-native #41

Closed sjmueller closed 8 years ago

sjmueller commented 8 years ago

Getting this exception when running a react-native project on device:

global.atob is not a function

Most likely due to this line: https://github.com/SocketCluster/socketcluster-client/blob/1b2cc0b7f66fa7f8d4b737bfb7d3381f757bd69b/lib/scsocket.js#L352

Perhaps the solution is to use a polyfill like https://github.com/mathiasbynens/base64 to supplement these methods when running socketcluster-client in a more restricted runtime like JavaScriptCore.

sjmueller commented 8 years ago

Verified works with base-64 (don't forget the dash!) For react-native googlers, npm i --save base-64, then add this somewhere in your codebase and make sure it runs before socketcluster-client is referenced:

if (!global.atob) {
  global.atob = require('base-64').decode;
}
jondubois commented 8 years ago

@sjmueller Ok, that should be fixed in v4.1.6.

sjmueller commented 8 years ago

Confirmed! Thanks @jondubois!

dilipkumar2k6 commented 7 years ago

Thanks @sjmueller, it worked for me 👍