Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.vladimirgoodwall:JavaPhoenixChannels:v0.1.2'
}
dependencies {
implementation("com.github.vladimirgoodwall:JavaPhoenixChannels:v0.1.2")
}
<dependency>
<groupId>com.github.vladimirgoodwall</groupId>
<artifactId>JavaPhoenixChannels</artifactId>
<version>v0.1.2</version>
</dependency>
libraryDependencies += "com.github.vladimirgoodwall" % "JavaPhoenixChannels" % "v0.1.2"
:dependencies [[com.github.vladimirgoodwall/JavaPhoenixChannels "v0.1.2"]]
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);