Skip to content

Tornjk/SharpTox

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SharpTox

Unofficial

This project aims to provide a simple library that wraps all of the functions found in the ProjectTox GitHub repo. (Tox.h, ToxAv.h, ToxEncryption.h)

Tox is a free (as in freedom) Skype replacement.

Feel free to contribute!

Remarks

I do not really maintain this version of SharpTox! I aim to have a base to play with and be able to use the basic features of Tox in C#!

Feel free to contribute but do not expect a working version!

The current version I program against is 0.2.8 of toxcore.

Things you'll need

  • The libtox library, you should compile that yourself from the ProjectTox GitHub repo. Guidelines on how to do this can be found here. If you don't feel like compiling this yourself, you can find automatic builds for windows here: x86 or x64

Depending on how you compiled the core libraries, the names of those may differ from the defaults in SharpTox. Be sure to change the value of the const string DLL in Extern.cs accordingly if needed. I for example needed to change this for using SharpTox on a debian machine.

Compiling and Testing

If you've set up your project like mentioned above you can go ahead and compile SharpTox.

.NET Core (Windows/Linux/Mac)

This Repository has been set up to work with .NET Core.

Please follow the How To Setup .NET Core Guide from Microsoft to setup your Environment for building and testing SharpTox. When you've setup everything accordingly to your system go to the project top directory of SharpTox and execute following in your commandline:

dotnet restore
dotnet build

Run the Tests

In order to run the Tests for SharpTox you do not need libtox.{dll,so,dylib} in your executing directory anymore. Run from your commandline:

dotnet test

Run the Sample

For the sample you require the libtox.{dll,so,dylib} in your executing directory! Run from your commandline in the root SharpTox folder:

dotnet run --project SharpTox.Sample

A ToxID will be displayed and every friend request will be accepted automatically. Every message sent will be displayed on the commandline. Use any current Tox Messenger to try it.

If no second message (Udp or Tcp) is displayed after some seconds you may want to check if the Nodes are up 2 date.

Attention:

This repository is currently mainly for my own programming uses. If anything comes up or this changes I will write it down somewhere. Also I'm developing on Windows. So I cannot truly troubleshoot P/Invoke questions on Linux/Mac.

Looking for precompiled binaries? I do not provide them currently. Sorry!

Basic Usage (Program.cs in SharpTox.Sample)

using System;
using SharpTox.Core;
using SharpTox.Core.Interfaces;

namespace SharpTox.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            using (IToxOptions options = ToxOptions.Default())
            using (ITox tox = options.Create())
            {
                tox.OnFriendRequestReceived += OnFriendRequestReceived;
                tox.OnFriendMessageReceived += OnFriendMessageReceived;
                tox.OnConnectionStatusChanged += Tox_OnConnectionStatusChanged;

                foreach (ToxNode node in Nodes)
                {
                    tox.Bootstrap(node, out _);
                }

                tox.Name = "SharpTox";
                tox.StatusMessage = "Testing SharpTox";

                using (ToxLoop.Start(tox))
                {
                    Console.WriteLine($"ID: {tox.Id}");
                    Console.ReadKey();
                }

                void OnFriendMessageReceived(object sender, ToxEventArgs.FriendMessageEventArgs e)
                {
                    //get the name associated with the friendnumber
                    string name = tox.GetFriendName(e.FriendNumber, out _);

                    //print the message to the console
                    Console.WriteLine("<{0}> {1}", name, e.Message);
                }

                void OnFriendRequestReceived(object sender, ToxEventArgs.FriendRequestEventArgs e)
                {
                    //automatically accept every friend request we receive
                    tox.AddFriendNoRequest(e.PublicKey, out _);
                }
            }
        }

        private static void Tox_OnConnectionStatusChanged(object sender, ToxEventArgs.ConnectionStatusEventArgs e)
        {
            Console.WriteLine(e.Status);
        }

        //check https://wiki.tox.im/Nodes for an up-to-date list of nodes
        private static readonly ToxNode[] Nodes = new ToxNode[]
        {
            new ToxNode("node.tox.biribiri.org", 33445, new ToxKey(ToxKeyType.Public, "8E7D0B859922EF569298B4D261A8CCB5FEA14FB91ED412A7603A585A25698832")),
            new ToxNode("tox.verdict.gg", 33445, new ToxKey(ToxKeyType.Public, "1C5293AEF2114717547B39DA8EA6F1E331E5E358B35F9B6B5F19317911C5F976")),
        };
    }
}

About

C# Wrapper for toktok/c-toxcore

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%