Work in Progress
Using Gradle 2.2.1 or later:
gradle build
Examples below are used with the Phoenix Chat Example
import org.phoenixframework.channels.*
def socket = new Socket('ws://localhost:4000/socket/websocket')
socket.connect()
def chan = socket.chan()
chan.join("rooms:lobby", null)
.receive("ignore", { -> println "IGNORE"})
.receive("ok", { envelope -> println "JOINED with $envelope" })
chan.on('new:msg', { -> println "NEW MESSAGE: $envelope"})
import org.phoenixframework.channels.*;
Socket socket;
Channel channel;
socket = new Socket("ws://localhost:4000/socket/websocket");
socket.connect();
channel = socket.chan("rooms:lobby", null);
channel.join()
.receive("ignore", new IMessageCallback() {
@Override
public void onMessage(Envelope envelope) {
System.out.println("IGNORE");
}
})
.receive("ok", new IMessageCallback() {
@Override
public void onMessage(Envelope envelope) {
System.out.println("JOINED with " + envelope.toString());
}
});
channel.on("new:msg", new IMessageCallback() {
@Override
public void onMessage(Envelope envelope) {
System.out.println("NEW MESSAGE: " + envelope.toString());
}
});
channel.onClose(new IMessageCallback() {
@Override
public void onMessage(Envelope envelope) {
System.out.println("CLOSED: " + envelope.toString());
}
});
channel.onError(new IErrorCallback() {
@Override
public void onError(String reason) {
System.out.println("ERROR: " + reason);
}
});
//Sending a message. This library uses Jackson for JSON serialization
ObjectNode node = new ObjectNode(JsonNodeFactory.instance)
.put("user", "my_username")
.put("body", message);
channel.push("new:msg", node);