Skip to content

Repository files navigation

Phoenix Channel Client for Java and Android

JavaPhoenixChannels is a Java and Android client library for the Channels API in the Phoenix Framework. Its primary purpose is to ease development of real time messaging apps for Android using an Elixir/Phoenix backend. For more about the Elixir language and the massively scalable and reliable systems you can build with Phoenix, see http://elixir-lang.org and http://www.phoenixframework.org.

Including the Library

  • Add http://dl.bintray.com/eoinsha/java-phoenix-channels as a Maven repository
  • Add JavaPhoenixChannels as an app dependency:
dependencies {
...
compile('com.github.eoinsha:JavaPhoenixChannels:0.2') {
exclude module: 'groovy-all'
}

Examples

Example Android App

For a full sample Android chat app, check out the repository at https://github.com/eoinsha/PhoenixChatAndroid

The quick examples below are used with the Phoenix Chat Example

Example using Groovy

importorg.phoenixframework.channels.*def socket =newSocket('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"})

Example using Java

importorg.phoenixframework.channels.*;
Socketsocket;
Channelchannel;
socket = newSocket("ws://localhost:4000/socket/websocket");
socket.connect();
channel = socket.chan("rooms:lobby", null);
channel.join()
.receive("ignore", newIMessageCallback() {
@OverridepublicvoidonMessage(Envelopeenvelope) {
System.out.println("IGNORE");
}
})
.receive("ok", newIMessageCallback() {
@OverridepublicvoidonMessage(Envelopeenvelope) {
System.out.println("JOINED with " + envelope.toString());
}
});
channel.on("new:msg", newIMessageCallback() {
@OverridepublicvoidonMessage(Envelopeenvelope) {
System.out.println("NEW MESSAGE: " + envelope.toString());
}
});
channel.on(ChannelEvent.CLOSE.getPhxEvent(), newIMessageCallback() {
@OverridepublicvoidonMessage(Envelopeenvelope) {
System.out.println("CLOSED: " + envelope.toString());
}
});
channel.on(ChannelEvent.ERROR.getPhxEvent(), newIMessageCallback() {
@OverridepublicvoidonMessage(Envelopeenvelope) {
System.out.println("ERROR: " + envelope.toString());
}
});
//Sending a message. This library uses Jackson for JSON serializationObjectNodenode = newObjectNode(JsonNodeFactory.instance)
.put("user", "my_username")
.put("body", message);
channel.push("new:msg", node);

Contributing

To contribute, see the contribution guidelines and instructions.

About

Java and Android channel client for the Phoenix Framework

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages