public void Init() { var options = new ToxOptions(true, true); _tox1 = new Tox(options); _tox2 = new Tox(options); _tox1.AddFriend(_tox2.Id, "hey"); _tox2.AddFriend(_tox1.Id, "hey"); while (_tox1.GetFriendConnectionStatus(0) == ToxConnectionStatus.None) { DoIterate(); } }
/// <summary> /// Initializes a new instance of Tox. If no secret key is specified, toxcore will generate a new keypair. /// </summary> /// <param name="options">The options to initialize this instance of Tox with.</param> /// <param name="secretKey">Optionally, specify the secret key to initialize this instance of Tox with. Must be ToxConstants.SecretKeySize bytes in size.</param> public Tox(ToxOptions options, ToxKey secretKey = null) { var error = ToxErrorNew.Ok; var optionsStruct = options.Struct; if (secretKey != null) optionsStruct.SetData(secretKey.GetBytes(), ToxSaveDataType.SecretKey); _tox = ToxFunctions.New(ref optionsStruct, ref error); if (_tox == null || _tox.IsInvalid || error != ToxErrorNew.Ok) throw new Exception("Could not create a new instance of tox, error: " + error.ToString()); optionsStruct.Free(); Options = options; }
public void TestToxFriendRequest() { var options = new ToxOptions(true, true); var tox1 = new Tox(options); var tox2 = new Tox(options); var error = ToxErrorFriendAdd.Ok; string message = "Hey, this is a test friend request."; bool testFinished = false; tox1.AddFriend(tox2.Id, message, out error); if (error != ToxErrorFriendAdd.Ok) Assert.Fail("Failed to add friend: {0}", error); tox2.OnFriendRequestReceived += (sender, args) => { if (args.Message != message) Assert.Fail("Message received in the friend request is not the same as the one that was sent"); tox2.AddFriendNoRequest(args.PublicKey, out error); if (error != ToxErrorFriendAdd.Ok) Assert.Fail("Failed to add friend (no request): {0}", error); if (!tox2.FriendExists(0)) Assert.Fail("Friend doesn't exist according to core"); testFinished = true; }; while (!testFinished && tox1.GetFriendConnectionStatus(0) == ToxConnectionStatus.None) { int time1 = tox1.Iterate(); int time2 = tox2.Iterate(); Thread.Sleep(Math.Min(time1, time2)); } tox1.Dispose(); tox2.Dispose(); }
public static extern ToxHandle New(ref ToxOptions options);
public void TestToxProxySocks5() { var options = new ToxOptions(true, ToxProxyType.Socks5, "127.0.0.1", 9050); var tox = new Tox(options); var error = ToxErrorBootstrap.Ok; foreach (var node in Globals.TcpRelays) { bool result = tox.AddTcpRelay(node, out error); if (!result || error != ToxErrorBootstrap.Ok) Assert.Fail("Failed to bootstrap, error: {0}, result: {1}", error, result); } tox.Start(); while (!tox.IsConnected) { Thread.Sleep(10); } Console.WriteLine("Tox connected!"); tox.Dispose(); }
/// <summary> /// Initializes a new instance of tox. /// </summary> /// <param name="options"></param> public Tox(ToxOptions options) { tox = ToxFunctions.New(ref options); if (tox == null || tox.IsInvalid) throw new Exception("Could not create a new instance of toxav."); Options = options; Invoker = new InvokeDelegate(dummyinvoker); callbacks(); }
/// <summary> /// Initializes a new instance of Tox. /// </summary> /// <param name="options">The options to initialize this instance of Tox with.</param> /// <param name="data">A byte array containing Tox save data.</param> /// <param name="key">The key to decrypt the given encrypted Tox profile data. If the data is not encrypted, this should be null.</param> public Tox(ToxOptions options, ToxData data, ToxEncryptionKey key = null) { if (data == null) throw new ArgumentNullException("data"); var optionsStruct = options.Struct; if (key == null || !data.IsEncrypted) { var error = ToxErrorNew.Ok; optionsStruct.SetData(data.Bytes, ToxSaveDataType.ToxSave); _tox = ToxFunctions.New(ref optionsStruct, ref error); if (_tox == null || _tox.IsInvalid || error != ToxErrorNew.Ok) throw new Exception("Could not create a new instance of tox, error: " + error.ToString()); } else { var error = ToxErrorNew.Ok; var decryptError = ToxErrorDecryption.Ok; byte[] decryptedData = ToxEncryption.DecryptData(data.Bytes, key, out decryptError); optionsStruct.SetData(decryptedData, ToxSaveDataType.ToxSave); _tox = ToxFunctions.New(ref optionsStruct, ref error); if (_tox == null || _tox.IsInvalid || error != ToxErrorNew.Ok || decryptError != ToxErrorDecryption.Ok) throw new Exception(string.Format("Could not create a new instance of tox, error: {0}, decrypt error: {1}" + error.ToString(), decryptError.ToString())); } optionsStruct.Free(); Options = options; }
public ExtendedTox(ToxOptions options) : base(options) { }
public ExtendedTox(ToxOptions options, ToxData data = null, ToxEncryptionKey key = null) : base(options, data, key) { }
private async void mv_Loaded(object sender, RoutedEventArgs e) { ToxOptions options; if (config.ProxyType != ToxProxyType.None) options = new ToxOptions(config.Ipv6Enabled, config.ProxyType, config.ProxyAddress, config.ProxyPort); else options = new ToxOptions(config.Ipv6Enabled, !config.UdpDisabled); tox = new Tox(options); var data = await loadTox(); if (data != null) tox = new Tox(options, data); tox.OnFriendNameChanged += tox_OnFriendNameChanged; tox.OnFriendMessageReceived += tox_OnFriendMessageReceived; tox.OnFriendRequestReceived += tox_OnFriendRequestReceived; tox.OnFriendStatusChanged += tox_OnFriendStatusChanged; tox.OnFriendStatusMessageChanged += tox_OnFriendStatusMessageChanged; tox.OnFriendTypingChanged += tox_OnFriendTypingChanged; tox.OnConnectionStatusChanged += tox_OnConnectionStatusChanged; tox.OnFriendConnectionStatusChanged += tox_OnFriendConnectionStatusChanged; tox.OnFileSendRequestReceived += tox_OnFileSendRequestReceived; tox.OnFileChunkReceived += tox_OnFileChunkReceived; tox.OnFileControlReceived += tox_OnFileControlReceived; tox.OnFileChunkRequested += tox_OnFileChunkRequested; tox.OnReadReceiptReceived += tox_OnReadReceiptReceived; tox.OnGroupTitleChanged += tox_OnGroupTitleChanged; tox.OnGroupInvite += tox_OnGroupInvite; tox.OnGroupMessage += tox_OnGroupMessage; tox.OnGroupAction += tox_OnGroupAction; tox.OnGroupNamelistChange += tox_OnGroupNamelistChange; toxav = new ToxAv(tox.Handle, 1); toxav.OnInvite += toxav_OnInvite; toxav.OnStart += toxav_OnStart; toxav.OnEnd += toxav_OnEnd; toxav.OnPeerTimeout += toxav_OnEnd; toxav.OnRequestTimeout += toxav_OnEnd; toxav.OnReject += toxav_OnEnd; toxav.OnCancel += toxav_OnEnd; toxav.OnReceivedAudio += toxav_OnReceivedAudio; toxav.OnReceivedVideo += toxav_OnReceivedVideo; toxav.OnPeerCodecSettingsChanged += toxav_OnPeerCodecSettingsChanged; toxav.OnReceivedGroupAudio += toxav_OnReceivedGroupAudio; DoBootstrap(); tox.Start(); toxav.Start(); if (string.IsNullOrEmpty(getSelfName())) tox.Name = "Tox User"; if (string.IsNullOrEmpty(getSelfStatusMessage())) tox.StatusMessage = "Toxing on Toxy"; ViewModel.MainToxyUser.Name = getSelfName(); ViewModel.MainToxyUser.StatusMessage = getSelfStatusMessage(); InitializeNotifyIcon(); SetStatus(null, false); InitFriends(); TextToSend.AddHandler(DragOverEvent, new DragEventHandler(Chat_DragOver), true); TextToSend.AddHandler(DropEvent, new DragEventHandler(Chat_Drop), true); ChatBox.AddHandler(DragOverEvent, new DragEventHandler(Chat_DragOver), true); ChatBox.AddHandler(DropEvent, new DragEventHandler(Chat_Drop), true); if (tox.Friends.Length > 0) ViewModel.SelectedChatObject = ViewModel.ChatCollection.OfType<IFriendObject>().FirstOrDefault(); initDatabase(); loadAvatars(); }