Git Product home page Git Product logo

objcphoenixclient's Introduction

PhoenixClient

Build Status Version License Platform

Usage

PhoenixClient is ready for use with Phoenix Framework v1.0.0. The PhoenixClient enables communication with a phoenix framework web project through the use of channels over websocket.

Learn more about the Phoenix Framework at http://www.phoenixframework.org/

Socket Connection

PhxSocket *socket = [[PhxSocket alloc] initWithURL:url heartbeatInterval:20];
[socket connectWithParams:@{@"user_id":1234}]

Socket Hooks

[socket onClose:^(void) {
  NSLog(@"the connection dropped");
}];

[socket onError:^(id error) {
  NSLog(@"there was an error with the connection!");
}];

Channels

PhxChannel *chan = [[PhxChannel alloc] initWithSocket:socket topic:@"rooms:123" params:@{@"token":roomToken}];
[chan onEvent:@"new_msg" callback:^(id message) {
  NSLog(@"Got message %@", message);
}];

Channel Hooks

[chan onClose:^(void) {
  NSLog(@"the channel has gone away gracefully");
}];

[chan onError:^(id error) {
  NSLog(@"there was an error!");
}];

Joining Channels

id join = [chan join];
[join onReceive:@"ok" callback:^(id messages) {
  NSLog(@"catching up %@", messages);
}];
[join onReceive:@"error" callback:^(id reason) {
  NSLog(@"failed join %@", reason);
}];
[join after:10000 callback:^(void) {
  NSLog(@"Networking issue. Still waiting...");
}];

Pushing Messages

PhxPush* push = [chan pushEvent:@"new_msg" payload:@{@"Some Message"}];
[push onReceive:@"ok" callback:^(id message) {
  NSLog(@"created message %@", message);
}];
[push onReceive:@"error" callback:^(id reason) {
  NSLog(@"create failed %@", reason);
}];
[push after:10000 callback:^(void) {
  NSLog(@"Networking issue. Still waiting...");
}];

Requirements

Installation

PhoenixClient is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "PhoenixClient"

Or without cocoapods

You can down the source and include all the files located in /Pod/Classes in your project

Example

Included in the source is the ChannelDemo iOS app. to use this app you will need to run the phoenix_chat_example. You can check this app out from

https://github.com/chrismccord/phoenix_chat_example

Follow the directions on the repo to launch the Phoenix app then launch the ChannelDemo in the Examples folder of this repository.

License

PhoenixClient is available under the MIT license. See the LICENSE file for more info.

objcphoenixclient's People

Contributors

alpacino avatar mobileoverlord avatar piets avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.