• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

eoinsha/JavaPhoenixChannels: Java and Android channel client for the Phoenix Fra ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

eoinsha/JavaPhoenixChannels

开源软件地址:

https://github.com/eoinsha/JavaPhoenixChannels

开源编程语言:

Java 89.7%

开源软件介绍:

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:1.0') {
      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

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"})

Example using Java

import org.phoenixframework.channels.*;

Socket socket;
Channel channel;

// To connect with authentication
String authToken = "abc123"
Uri.Builder url = Uri.parse( "ws://localhost:4000/socket/websocket" ).buildUpon();
url.appendQueryParameter( "auth_token", authToken );
socket = new Socket(url.build().toString());
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.on(ChannelEvent.CLOSE.getPhxEvent(), new IMessageCallback() {
    @Override
    public void onMessage(Envelope envelope) {
        System.out.println("CLOSED: " + envelope.toString());
    }
});

channel.on(ChannelEvent.ERROR.getPhxEvent(), new IMessageCallback() {
    @Override
    public void onMessage(Envelope envelope) {
        System.out.println("ERROR: " + envelope.toString());
    }
});

//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);

Contributing

To contribute, see the contribution guidelines and instructions.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
SignalR/java-client: OBSOLETE - see readme发布时间:2022-06-23
下一篇:
shyiko/jabba: (cross-platform) Java Version Manager发布时间:2022-06-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap