Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Callback;

import org.json.JSONObject;

import java.net.URISyntaxException;
import java.util.HashMap;

import io.socket.client.Ack;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
Expand Down Expand Up @@ -63,12 +65,18 @@ public void initialize(String connection, ReadableMap options) {
* Emit event to server
* @param event The name of the event.
* @param items The data to pass through the SocketIo engine to the server endpoint.
* @param Ack callback
*/
@ReactMethod
public void emit(String event, ReadableMap items) {
public void emit(String event, ReadableMap items, final Callback ack) {
HashMap<String, Object> map = SocketIoReadableNativeMap.toHashMap((ReadableNativeMap) items);
if (mSocket != null) {
mSocket.emit(event, new JSONObject(map));
mSocket.emit(event, new JSONObject(map), new Ack() {
@Override
public void call(Object... args) {
ack.invoke(SocketIoJSONUtil.objectsFromJSON(args));
}
});
}
else {
Log.e(TAG, "Cannot execute emit. mSocket is null. Initialize socket first!!!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.util.Log;

import com.facebook.jni.HybridData;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.ReadableNativeMap;

Expand All @@ -15,6 +16,11 @@

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.
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
160 changes: 160 additions & 0 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Socket {
this.handlers = {};
this.onAnyHandler = null;

if(Platform.OS === "ios") this.sockets.addListener("socketEvent");
this.deviceEventSubscription = DeviceEventEmitter.addListener(
'socketEvent', this._handleEvent.bind(this)
);
Expand Down Expand Up @@ -63,8 +64,8 @@ class Socket {
this.onAnyHandler = handler;
}

emit (event, data) {
this.sockets.emit(event, data);
emit (event, data, ack = () => console.log(`ACK ${event}`)) {
this.sockets.emit(event, data, ack);
}

joinNamespace (namespace) {
Expand Down
Loading