Comments (8)
#8
Solution is to add this to SocketIoReadableNativeMap.java:
protected SocketIoReadableNativeMap(HybridData hybridData) {
super(hybridData);
}
SocketIoReadableNativeMap.java then looks like this:
package com.gcrabtree.rctsocketio;
import android.util.Log;
import com.facebook.jni.HybridData;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.ReadableNativeMap;
import java.util.HashMap;
import io.socket.client.IO;
/**
* Created by Greg Crabtree on 5/17/16.
*/
public class SocketIoReadableNativeMap extends ReadableNativeMap {
private static final String TAG = "SIOReadableNativeMap";
protected SocketIoReadableNativeMap(HybridData hybridData) {
super(hybridData);
}
/**
* Note: This will only be necessary until RN version 0.26 goes live
* It will be deprecated from the project, as this is just included in that version of RN.
*
* This converts the SocketIoReadableNativeMap to a Java usable HashMap.
* @return converted HashMap.
*/
public static HashMap<String, Object> toHashMap(ReadableNativeMap map) {
ReadableMapKeySetIterator iterator = map.keySetIterator();
HashMap<String, Object> hashMap = new HashMap<>();
while (iterator.hasNextKey()) {
String key = iterator.nextKey();
switch (map.getType(key)) {
case Null:
hashMap.put(key, null);
break;
case Boolean:
hashMap.put(key, map.getBoolean(key));
break;
case Number:
hashMap.put(key, map.getDouble(key));
break;
case String:
hashMap.put(key, map.getString(key));
break;
case Map:
hashMap.put(key, toHashMap(map.getMap(key)));
break;
case Array:
hashMap.put(key, ((SocketIoReadableNativeArray) map.getArray(key)).toArrayList());
break;
default:
throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
}
}
return hashMap;
}
/**
* This converts a SocketIoReadableNativeMap to a SocketIO Option object.
* @param options ReadableNativeMap that is a JS bridged hash of options.
* @return IO.Options object that has been populated. Currently incomplete. Pas welcome.
*/
public static IO.Options mapToOptions(ReadableNativeMap options) {
ReadableMapKeySetIterator iterator = options.keySetIterator();
IO.Options opts = new IO.Options();
while (iterator.hasNextKey()) {
String key = iterator.nextKey().toLowerCase();
switch (key) {
case "force new connection":
case "force new"
opts.forceNew = options.getBoolean(key);
break;
case "multiplex":
opts.multiplex = options.getBoolean(key);
break;
case "reconnection":
opts.reconnection = options.getBoolean(key);
break;
case "connect_timeout":
opts.timeout = options.getInt(key);
break;
default:
Log.e(TAG, "Could not convert object with key: " + key + ".");
}
}
return opts;
}
}
Note:
You can't use localhost when creating a new SocketIO for Android Emulator.
Use whatever your local IP is when creating a socket in index.android.js
Example:
this.socket = new SocketIO('http://192.168.0.1:3000', {});
from react-native-socketio.
+1
from react-native-socketio.
Same here and with react-native 0.30.0
from react-native-socketio.
Same here
from react-native-socketio.
same here
from react-native-socketio.
same here,
@gcrabtree any solution that you could suggest?
thanks
from react-native-socketio.
Sorry for the author but i could'nt wait more... so if this can help you guys: https://gist.github.com/littlepsylo/341ed91aed9870924de082d9d1eee580
This simple implementation of WebSocket works for me with an existing socket.io server on both android and ios. Beyond that, you will surely find more informations in the React-Native documentation or MDN, for example, about this API.
from react-native-socketio.
Made a PR that makes this library compatible with RN 0.29+
Check it out here: #46
from react-native-socketio.
Related Issues (20)
- Not compatible with react-native init? HOT 2
- Something wrong in java file SocketIoReadableNativeMap.java HOT 1
- SocketIoReadableNativeMap.java constructor not defined HOT 2
- react-native 0.39.2 HOT 1
- Android socket event is global,and open new socket the old event is still there
- can't parse String type,when node call emit('eventName', JSON.stringify({name:'hj',age:23})); HOT 1
- How to fix: opening import file for module 'Swift': Permission denied
- [Support Request] Multiple client problem HOT 2
- Can't find variable: SocketIO HOT 6
- On server use socket v0.9.16 react-native-socketio connect not work
- undefined is not an object (evaluating this.sockets.initialize) HOT 8
- node_modules bundles/default/AndroidManifest.xml FileNotFoundException
- error: method do es not override or implement a method from a supertype HOT 2
- App crashed when calling connect(). (RN0.48.3) HOT 1
- android is ok,but ios error HOT 1
- Event created in Android device shown as Birthday on Calendar and after sometime it disappears HOT 1
- Will this library supports rn > 50, xcode 9+
- another dead project.. awesome... HOT 1
- Getting error in installation HOT 4
- how to send data private?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-socketio.