Code Monkey home page Code Monkey logo

dn-phoenix's Introduction

a c# port of the phoenix framework js client (at 1.1.1, commit c09e98e) funded by @livehelpnow

the intention is to follow the js api and c#ly as possible

dependencies

  • newtonsoft.json (8.0.1)
  • websocket-sharp (1.0.3-rc10 prerelease)

an example i used to test (C# 6)

private static void Main(string[] args)
{
  //let socket = new Socket("/ws", {params: {userToken: "123"}})
  //socket.connect()
  var p = new JObject();
  p["userToken"] = "123";
  var options = new SocketOptions()
  {
    LogCallback = Logger,
    Params = p,
  };
  var socket = new Socket("ws://phoenix.local:4000/socket", options);
  socket.Connect();

  //let channel = socket.channel("rooms:123", { token: roomToken})
  //channel.on("new_msg", msg => console.log("Got message", msg) )
  var data = new JObject();
  var roomToken = "foo";
  data["token"] = roomToken;
  var channel = socket.Channel("rooms:lobby", data);
  channel.On("new_msg", (jo, x) => Console.WriteLine($"new_msg { jo.ToString() }"));

  //channel.join()
  //  .receive("ok", ({messages}) => console.log("catching up", messages) )
  //  .receive("error", ({reason}) => console.log("failed join", reason) )
  //  .receive("timeout", () => console.log("Networking issue. Still waiting...") )
  channel.Join()
    .Receive("ok", (jo) => Console.WriteLine("ok"))
    .Receive("error", (jo) => Console.WriteLine("error"))
    .Receive("timeout", (jo) => Console.WriteLine("timeout"))
    ;

  ReadLoop(channel);
}
private static void ReadLoop(Channel channel)
{
  var input = Console.ReadLine().Trim();
  if (input.Length < 1)
  {
    Console.WriteLine("trying to send");
    var data = new JObject();
    data["body"] = "from dotnet";
    channel.Push("new_msg", data).Receive("ok", (jo) => Console.WriteLine($"PUSH new_msg ok { jo.ToString() }"));
    ReadLoop(channel);
  }
}
private static void Logger(string kind, string msg, JObject data = null)
{
  Console.WriteLine($"{kind} - {msg}");
}

dn-phoenix's People

Contributors

jfis avatar

Watchers

James Cloos 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.