GithubHelp home page GithubHelp logo

centrifuge-csharp's Introduction

Centrifuge C# Client

Nuget

This SDK provides a client to connect to Centrifugo

⚠️ Working in progress

  • SDK is not completed yet.
  • This library is translated from centrifuge java sdk. It is not stable.

Installation

dotnet add package Centrifuge --version 1.0.0

Platforms

  • .NET Framework 4.8
  • Unity 2022.3+ (Api .NET Framework)

TODO

  • Code Refactor
  • History
  • Presence

Example

using System;
using System.Threading;
using Centrifuge;

namespace Example
{
    internal class Program
    {
        private static string TOKEN = "";

        public class TokenGetter : ConnectionTokenGetter
        {
            public override void GetConnectionToken(ConnectionTokenEvent e, TokenCallback cb)
            {
                cb(null, TOKEN);
            }
        }

        public class Listener : EventListener
        {
            public override void OnConnecting(Client client, ConnectingEvent e)
            {
                Console.WriteLine("onConnecting");
            }

            public override void OnConnected(Client client, ConnectedEvent e)
            {
                Console.WriteLine("onConnected");
            }

            public override void OnDisconnected(Client client, DisconnectedEvent e)
            {
                Console.WriteLine("onDisconnected");
            }

            public override void OnError(Client client, ErrorEvent e)
            {
                Console.WriteLine("onError1" + e.Error);
            }

            public override void OnMessage(Client client, MessageEvent e)
            {
                Console.WriteLine("onMessage");
            }

            public override void OnSubscribed(Client client, ServerSubscribedEvent e)
            {
                Console.WriteLine("onSubscribed");
            }

            public override void OnSubscribing(Client client, ServerSubscribingEvent e)
            {
                Console.WriteLine("onSubscribing");
            }

            public override void OnUnsubscribed(Client client, ServerUnsubscribedEvent e)
            {
                Console.WriteLine("onUnsubscribed");
            }

            public override void OnPublication(Client client, ServerPublicationEvent e)
            {
                Console.WriteLine("onPublication");
            }

            public override void OnJoin(Client client, ServerJoinEvent e)
            {
                Console.WriteLine("onJoin");
            }

            public override void OnLeave(Client client, ServerLeaveEvent e)
            {
                Console.WriteLine("onLeave");
            }
        }

        public class SubListener : SubscriptionEventListener
        {
            public override void OnPublication(Subscription sub, PublicationEvent e)
            {
                var d = System.Text.Encoding.UTF8.GetString(e.Data);
                Console.WriteLine("onPublication" + d);
            }

            public override void OnJoin(Subscription sub, JoinEvent e)
            {
                Console.WriteLine("onJoin");
            }

            public override void OnLeave(Subscription sub, LeaveEvent e)
            {
                Console.WriteLine("onLeave");
            }

            public override void OnSubscribed(Subscription sub, SubscribedEvent e)
            {
                Console.WriteLine("onSubscribed");
            }

            public override void OnUnsubscribed(Subscription sub, UnsubscribedEvent e)
            {
                Console.WriteLine("onUnsubscribed");
            }

            public override void OnSubscribing(Subscription sub, SubscribingEvent e)
            {
                Console.WriteLine("onSubscribing");
            }

            public override void OnError(Subscription sub, SubscriptionErrorEvent e)
            {
                Console.WriteLine("onError" + e.Error);
            }
        }

        public static void Main(string[] args)
        {
            Options opts = new Options()
            {
                Token = TOKEN,
                TokenGetter = new TokenGetter(),
            };

            Client client = new Client("ws://localhost:8088/connection/websocket", opts, new Listener());
            client.Connect();

            var sub = client.NewSubscription("message#0f63396b-3b29-4072-849b-a886ac08a5e2", new SubscriptionOptions(), new SubListener());
            sub.Subscribe();

            Thread.Sleep(200000);
        }
    }
}

centrifuge-csharp's People

Contributors

ozgursoy avatar srfaytkn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

centrifuge-csharp's Issues

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.