Hello, can anyone explain me with this example why my event is not called from B4A?
using the Simple Library Compiler I could compile it:
Here goes my question because I don't understand very well what name should I use in my case to get the event working.....
Should I put this one?
Or this one, supposing that I initialize it this way:
I supposed this last name because of the:
Could anyone help me?
Thank you!!!!
using the Simple Library Compiler I could compile it:
B4X:
package anywheresoftware.b4a.SocketIOClient;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.*;
import anywheresoftware.b4a.BA;
import android.telephony.*;
import java.net.MalformedURLException;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.json.simple.parser.ParseException;
import io.socket.*;
@Permissions(values={"android.permission.INTERNET"})
@ShortName("SocketIOClient")
@DependsOn(values={"json-org","json-simple-1.1.1","WebSocket","socket2"})
@ActivityObject
@Events(values={"OnConnect(json as String)"})
public class SocketIOClient {
private SocketIO socket;
private BA ba;
private String eventName;
public void connect(String host) throws MalformedURLException {
this.socket = new SocketIO(host);
socket.connect(new IOCallback() {
@Override
public void onMessage(JSONObject json, IOAcknowledge ack) {
try {
System.out.println("Server said:" + json.toString(2));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onMessage(String data, IOAcknowledge ack) {
System.out.println("Server said: " + data);
}
@Override
public void onError(SocketIOException socketIOException) {
System.out.println("an Error occured");
socketIOException.printStackTrace();
}
@Override
public void onDisconnect() {
System.out.println("Connection terminated.");
}
@Override
public void onConnect() {
System.out.println("Connection established");
ba.raiseEvent(this, eventName + "_onconnect","OK");
}
@Override
public void on(String event, IOAcknowledge ack, Object... args) {
System.out.println("Server triggered event '" + event + "'");
}
});
}
public void initialize(BA ba, String EventName) throws MalformedURLException
{
this.ba = ba;
this.eventName = EventName.toLowerCase(BA.cul);
}
}
Here goes my question because I don't understand very well what name should I use in my case to get the event working.....
B4X:
@Events(values={"OnConnect(json as String)"})
Should I put this one?
B4X:
Sub OnConnect(valor As String)
Msgbox("connected!","info")
End Sub
Or this one, supposing that I initialize it this way:
B4X:
Sub Globals
Dim socket As SocketIOClient
End Sub
Sub Activity_Create(FirstTime As Boolean)
DisableStrictMode
socket.initialize("socket")
socket.connect("http://192.168.1.3:8080/")
End Sub
Sub socket_onconnect(valor As String)
Msgbox("connected!","info")
End Sub
I supposed this last name because of the:
B4X:
ba.raiseEvent(this, eventName + "_onconnect","OK");
Could anyone help me?
Thank you!!!!