Initial commit

This commit is contained in:
Tha_14
2024-02-22 21:43:11 +02:00
commit 1b96a031d2
1108 changed files with 157706 additions and 0 deletions

View File

@ -0,0 +1,567 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import <Foundation/Foundation.h>
#import "OCTToxDelegate.h"
#import "OCTToxConstants.h"
@class OCTToxOptions;
@interface OCTTox : NSObject
@property (weak, nonatomic) id<OCTToxDelegate> delegate;
/**
* Indicates if we are connected to the DHT.
*/
@property (assign, nonatomic, readonly) OCTToxConnectionStatus connectionStatus;
/**
* Our address.
*
* Address for Tox as a hex string. Address is kOCTToxAddressLength length and has following format:
* [publicKey (32 bytes, 64 characters)][nospam number (4 bytes, 8 characters)][checksum (2 bytes, 4 characters)]
*/
@property (strong, nonatomic, readonly) NSString *userAddress;
/**
* Our Tox Public Key (long term public key) of kOCTToxPublicKeyLength.
*/
@property (strong, nonatomic, readonly) NSString *publicKey;
/**
* Our secret key of kOCTToxSecretKeyLength.
*/
@property (strong, nonatomic, readonly) NSString *secretKey;
/**
* Client's nospam part of the address. Any 32 bit unsigned integer.
*/
@property (assign, nonatomic) OCTToxNoSpam nospam;
/**
* Client's capabilities. A 64 bit unsigned integer.
*/
@property (nonatomic, readonly) OCTToxCapabilities capabilities;
/**
* Client's user status.
*/
@property (assign, nonatomic) OCTToxUserStatus userStatus;
#pragma mark - Class methods
/**
* Return toxcore version in format X.Y.Z, where
* X - The major version number. Incremented when the API or ABI changes in an incompatible way.
* Y - The minor version number. Incremented when functionality is added without breaking the API or ABI.
* Set to 0 when the major version number is incremented.
* Z - The patch or revision number. Incremented when bugfixes are applied without changing any functionality or API or ABI.
*/
+ (NSString *)version;
/**
* The major version number of toxcore. Incremented when the API or ABI changes in an incompatible way.
*/
+ (NSUInteger)versionMajor;
/**
* The minor version number of toxcore. Incremented when functionality is added without breaking the API or ABI.
* Set to 0 when the major version number is incremented.
*/
+ (NSUInteger)versionMinor;
/**
* The patch or revision number of toxcore. Incremented when bugfixes are applied without changing any functionality or API or ABI.
*/
+ (NSUInteger)versionPatch;
#pragma mark - Lifecycle
/**
* Creates new Tox object with configuration options and loads saved data.
*
* @param options Configuration options.
* @param data Data load Tox from previously stored by `-save` method. Pass nil if there is no saved data.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorInitCode for all error codes.
*
* @return New instance of Tox or nil if fatal error occured during loading.
*
* @warning If loading failed or succeeded only partially, the new or partially loaded instance is returned and
* an error is set.
*/
- (instancetype)initWithOptions:(OCTToxOptions *)options savedData:(NSData *)data error:(NSError **)error;
/**
* Saves Tox into NSData.
*
* @return NSData with Tox save.
*/
- (NSData *)save;
/**
* Starts the main loop of the Tox on it's own unique queue.
*
* @warning Tox won't do anything without calling this method.
*/
- (void)start;
/**
* Stops the main loop of the Tox.
*/
- (void)stop;
#pragma mark - Methods
/**
* Sends a "get nodes" request to the given bootstrap node with IP, port, and
* public key to setup connections.
*
* This function will attempt to connect to the node using UDP and TCP at the
* same time.
*
* Tox will use the node as a TCP relay in case OCTToxOptions.UDPEnabled was
* YES, and also to connect to friends that are in TCP-only mode. Tox will
* also use the TCP connection when NAT hole punching is slow, and later switch
* to UDP if hole punching succeeds.
*
* @param host The hostname or an IP address (IPv4 or IPv6) of the node.
* @param port The port on the host on which the bootstrap Tox instance is listening.
* @param publicKey Public key of the node (of kOCTToxPublicKeyLength length).
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorBootstrapCode for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)bootstrapFromHost:(NSString *)host port:(OCTToxPort)port publicKey:(NSString *)publicKey error:(NSError **)error;
/**
* Adds additional host:port pair as TCP relay.
*
* This function can be used to initiate TCP connections to different ports on
* the same bootstrap node, or to add TCP relays without using them as
* bootstrap nodes.
*
* @param host The hostname or IP address (IPv4 or IPv6) of the TCP relay.
* @param port The port on the host on which the TCP relay is listening.
* @param publicKey Public key of the node (of kOCTToxPublicKeyLength length).
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorBootstrapCode for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)addTCPRelayWithHost:(NSString *)host port:(OCTToxPort)port publicKey:(NSString *)publicKey error:(NSError **)error;
/**
* Add a friend.
*
* @param address Address of a friend to add. Must be exactry kOCTToxAddressLength length.
* @param message Message that would be send with friend request. Minimum length - 1 byte.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendAdd for all error codes.
*
* @return On success returns friend number. On failure returns kOCTToxFriendNumberFailure and fills `error` parameter.
*
* @warning You can check maximum length of message with `-checkLengthOfString:withCheckType:` method with
* OCTToxCheckLengthTypeFriendRequest type.
*/
- (OCTToxFriendNumber)addFriendWithAddress:(NSString *)address message:(NSString *)message error:(NSError **)error;
/**
* Add a friend without sending friend request.
*
* This function is used to add a friend in response to a friend request. If the
* client receives a friend request, it can be reasonably sure that the other
* client added this client as a friend, eliminating the need for a friend
* request.
*
* This function is also useful in a situation where both instances are
* controlled by the same entity, so that this entity can perform the mutual
* friend adding. In this case, there is no need for a friend request, either.
*
* @param publicKey Public key of a friend to add. Public key is hex string, must be exactry kOCTToxPublicKeyLength length.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendAdd for all error codes.
*
* @return On success returns friend number. On failure returns kOCTToxFriendNumberFailure.
*/
- (OCTToxFriendNumber)addFriendWithNoRequestWithPublicKey:(NSString *)publicKey error:(NSError **)error;
/**
* Remove a friend from the friend list.
*
* This does not notify the friend of their deletion. After calling this
* function, this client will appear offline to the friend and no communication
* can occur between the two.
*
* @param friendNumber Friend number to remove.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendDelete for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)deleteFriendWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Return the friend number associated with that Public Key.
*
* @param publicKey Public key of a friend. Public key is hex string, must be exactry kOCTToxPublicKeyLength length.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendByPublicKey for all error codes.
*
* @return The friend number on success, kOCTToxFriendNumberFailure on failure.
*/
- (OCTToxFriendNumber)friendNumberWithPublicKey:(NSString *)publicKey error:(NSError **)error;
/**
* Get public key from associated friend number.
*
* @param friendNumber Associated friend number
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendGetPublicKey for all error codes.
*
* @return Public key of a friend. Public key is hex string, must be exactry kOCTToxPublicKeyLength length. If there is no such friend returns nil.
*/
- (NSString *)publicKeyFromFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Checks if there exists a friend with given friendNumber.
*
* @param friendNumber Friend number to check.
*
* @return YES if friend exists, NO otherwise.
*/
- (BOOL)friendExistsWithFriendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Return a date of the last time the friend associated with a given friend number was seen online.
*
* @param friendNumber The friend number you want to query.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendGetLastOnline for all error codes.
*
* @return Date of the last time friend was seen online.
*/
- (NSDate *)friendGetLastOnlineWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Return Friend's capabilities. A 64 bit unsigned integer.
*/
- (OCTToxCapabilities)friendGetCapabilitiesWithFriendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Return the friend's user status (away/busy/...). If the friend number is
* invalid, the return value is unspecified.
*
* @param friendNumber Friend number to check status.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendQuery for all error codes.
*
* @return Returns friend status.
*/
- (OCTToxUserStatus)friendStatusWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Check whether a friend is currently connected to this client.
*
* @param friendNumber Friend number to check status.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendQuery for all error codes.
*
* @return Returns friend connection status.
*/
- (OCTToxConnectionStatus)friendConnectionStatusWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Send a custom lossless bytes to an online friend.
*
* @param friendNumber Friend number to send the bytes.
* @param pktid the Tox Packet ID.
* @param data String that will be converted into bytes using UTF-8 encoding.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
*
* @return YES on success, NO on failure.
*/
- (BOOL)sendLosslessPacketWithFriendNumber:(OCTToxFriendNumber)friendNumber
pktid:(uint8_t)pktid
data:(NSString *)data
error:(NSError **)error;
/**
* Send a text chat message to an online friend.
*
* @param friendNumber Friend number to send a message.
* @param type Type of the message.
* @param message Message that would be send.
* @param msgv3HashHex the messagev3 Hash Hexstring or nil.
* @param msgv3tssec the messagev3 sendtimestamp in unixtimestamp or "0" if not used.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendSendMessage for all error codes.
*
* @return The message id. Message IDs are unique per friend. The first message ID is 0. Message IDs are
* incremented by 1 each time a message is sent. If UINT32_MAX messages were sent, the next message ID is 0.
*
* @warning You can check maximum length of message with `-checkLengthOfString:withCheckType:` method with
* OCTToxCheckLengthTypeSendMessage type.
*/
- (OCTToxMessageId)sendMessageWithFriendNumber:(OCTToxFriendNumber)friendNumber
type:(OCTToxMessageType)type
message:(NSString *)message
msgv3HashHex:(NSString *)msgv3HashHex
msgv3tssec:(UInt32)msgv3tssec
error:(NSError **)error;
/**
* Set the nickname for the Tox client.
*
* @param name Name to be set. Minimum length of name is 1 byte.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorSetInfoCode for all error codes.
*
* @return YES on success, NO on failure.
*
* @warning You can check maximum length of message with `-checkLengthOfString:withCheckType:` method with
* OCTToxCheckLengthTypeName type.
*/
- (BOOL)setNickname:(NSString *)name error:(NSError **)error;
/**
* Get your nickname.
*
* @return Your nickname or nil in case of error.
*/
- (NSString *)userName;
/**
* Get name of friendNumber.
*
* @param friendNumber Friend number to get name.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendQuery for all error codes.
*
* @return Name of friend or nil in case of error.
*/
- (NSString *)friendNameWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Set our status message.
*
* @param statusMessage Status message to be set.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorSetInfoCode for all error codes.
*
* @return YES on success, NO on failure.
*
* @warning You can check maximum length of message with `-checkLengthOfString:withCheckType:` method with
* OCTToxCheckLengthTypeStatusMessage type.
*/
- (BOOL)setUserStatusMessage:(NSString *)statusMessage error:(NSError **)error;
/**
* Get our status message.
*
* @return Our status message.
*/
- (NSString *)userStatusMessage;
/**
* Get status message of a friend.
*
* @param friendNumber Friend number to get status message.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendQuery for all error codes.
*
* @return Status message of a friend.
*/
- (NSString *)friendStatusMessageWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Set our typing status for a friend. You are responsible for turning it on or off.
*
* @param isTyping Status showing whether user is typing or not.
* @param friendNumber Friend number to set typing status.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorSetTyping for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)setUserIsTyping:(BOOL)isTyping forFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Get the typing status of a friend.
*
* @param friendNumber Friend number to get typing status.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFriendQuery for all error codes.
*
* @return YES if friend is typing, otherwise NO.
*/
- (BOOL)isFriendTypingWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Return the number of friends.
*
* @return Return the number of friends.
*/
- (NSUInteger)friendsCount;
/**
* Return an array of valid friend IDs.
*
* @return Return an array of valid friend IDs. Array contain NSNumbers with IDs.
*/
- (NSArray *)friendsArray;
/**
* Generates a cryptographic hash of the given data.
* This function may be used by clients for any purpose, but is provided primarily for
* validating cached avatars. This use is highly recommended to avoid unnecessary avatar
* updates.
*
* @param data Data to be hashed
*
* @return Hash generated from data.
*/
- (NSData *)hashData:(NSData *)data;
/**
* Sends a file control command to a friend for a given file transfer.
*
* @param fileNumber The friend-specific identifier for the file transfer.
* @param friendNumber The friend number of the friend the file is being transferred to or received from.
* @param control The control command to send.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFileControl for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)fileSendControlForFileNumber:(OCTToxFileNumber)fileNumber
friendNumber:(OCTToxFriendNumber)friendNumber
control:(OCTToxFileControl)control
error:(NSError **)error;
/**
* Sends a file seek control command to a friend for a given file transfer.
*
* This function can only be called to resume a file transfer right before
* OCTToxFileControlResume is sent.
*
* @param fileNumber The friend-specific identifier for the file transfer.
* @param friendNumber The friend number of the friend the file is being received from.
* @param position The position that the file should be seeked to.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFileSeek for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)fileSeekForFileNumber:(OCTToxFileNumber)fileNumber
friendNumber:(OCTToxFriendNumber)friendNumber
position:(OCTToxFileSize)position
error:(NSError **)error;
/**
* Get the file id associated to the file transfer.
*
* @param fileNumber The friend-specific identifier for the file transfer.
* @param friendNumber The friend number of the friend the file is being transferred to or received from.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFileGet for all error codes.
*
* @return File id on success, nil on failure.
*/
- (NSData *)fileGetFileIdForFileNumber:(OCTToxFileNumber)fileNumber
friendNumber:(OCTToxFriendNumber)friendNumber
error:(NSError **)error;
/**
* Send a file transmission request.
*
* Maximum filename length is kOCTToxMaxFileNameLength bytes. The filename should generally just be
* a file name, not a path with directory names.
*
* If a non-zero file size is provided, this can be used by both sides to
* determine the sending progress. File size can be set to zero for streaming
* data of unknown size.
*
* File transmission occurs in chunks, which are requested through the
* `fileChunkRequest` callback.
*
* When a friend goes offline, all file transfers associated with the friend are
* purged from core.
*
* If the file contents change during a transfer, the behaviour is unspecified
* in general. What will actually happen depends on the mode in which the file
* was modified and how the client determines the file size.
*
* - If the file size was increased
* - and sending mode was streaming (fileSize = kOCTToxFileSizeUnknown), the behaviour will be as
* expected.
* - and sending mode was file (fileSize != kOCTToxFileSizeUnknown), the fileChunkRequest
* callback will receive length = 0 when Core thinks the file transfer has
* finished. If the client remembers the file size as it was when sending
* the request, it will terminate the transfer normally. If the client
* re-reads the size, it will think the friend cancelled the transfer.
* - If the file size was decreased
* - and sending mode was streaming, the behaviour is as expected.
* - and sending mode was file, the callback will return 0 at the new
* (earlier) end-of-file, signalling to the friend that the transfer was
* cancelled.
* - If the file contents were modified
* - at a position before the current read, the two files (local and remote)
* will differ after the transfer terminates.
* - at a position after the current read, the file transfer will succeed as
* expected.
* - In either case, both sides will regard the transfer as complete and
* successful.
*
* @param friendNumber The friend number of the friend the file send request should be sent to.
* @param kind The meaning of the file to be sent.
* @param fileSize Size in bytes of the file the client wants to send, kOCTToxFileSizeUnknown if unknown or streaming.
* @param fileId A file identifier of length kOCTToxFileIdLength that can be used to
* uniquely identify file transfers across core restarts. If nil, a random one will
* be generated by core. It can then be obtained by using `fileGetFileId`.
* @param fileName Name of the file. Does not need to be the actual name. This
* name will be sent along with the file send request.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFileSend for all error codes.
*
* @return A file number used as an identifier in subsequent callbacks. This
* number is per friend. File numbers are reused after a transfer terminates.
* on failure, this function returns kOCTToxFileNumberFailure.
*/
- (OCTToxFileNumber)fileSendWithFriendNumber:(OCTToxFriendNumber)friendNumber
kind:(OCTToxFileKind)kind
fileSize:(OCTToxFileSize)fileSize
fileId:(NSData *)fileId
fileName:(NSString *)fileName
error:(NSError **)error;
/**
* Send a chunk of file data to a friend.
*
* This method is called in response to the `fileChunkRequest` callback. The
* length of data should be equal to the one received though the callback.
* If it is zero, the transfer is assumed complete. For files with known size,
* Core will know that the transfer is complete after the last byte has been
* received, so it is not necessary (though not harmful) to send a zero-length
* chunk to terminate. For streams, core will know that the transfer is finished
* if a chunk with length less than the length requested in the callback is sent.
*
* @param friendNumber The friend number of the receiving friend for this file.
* @param fileNumber The file transfer identifier returned by fileSend.
* @param position The file or stream position from which to continue reading.
* @param data Data of chunk to send. May be nil, then transfer is assumed complete.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxErrorFileSendChunk for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)fileSendChunkForFileNumber:(OCTToxFileNumber)fileNumber
friendNumber:(OCTToxFriendNumber)friendNumber
position:(OCTToxFileSize)position
data:(NSData *)data
error:(NSError **)error;
@end

View File

@ -0,0 +1,148 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import <Foundation/Foundation.h>
#import "OCTToxAVConstants.h"
#import "OCTToxConstants.h"
#import "OCTToxAVDelegate.h"
@class OCTTox;
@interface OCTToxAV : NSObject
@property (weak, nonatomic) id<OCTToxAVDelegate> delegate;
#pragma mark - Lifecycle
/**
* Creates a new Toxav object.
* @param tox Tox object to be initialized with.
* @param error If an error occurs, this pointer is set to an actual error object.
*/
- (instancetype)initWithTox:(OCTTox *)tox error:(NSError **)error;
/**
* Starts the main loop of the ToxAV on it's own unique queue.
*
* @warning ToxAV won't do anything without calling this method.
*/
- (void)start;
/**
* Stops the main loop of the ToxAV.
*/
- (void)stop;
#pragma mark - Call Methods
/**
* Call a friend. This will start ringing the friend.
* It is the client's responsibility to stop ringing after a certain timeout,
* if such behaviour is desired. If the client does not stop ringing, the
* library will not stop until the friend is disconnected.
* @param friendNumber The friend number of the friend that should be called.
* @param audioBitRate Audio bit rate in Kb/sec. Set this to kOCTToxAVAudioBitRateDisable to disable audio sending.
* @param videoBitRate Video bit rate in Kb/sec. Set this to kOCTToxAVVideoBitRateDisable to disable video sending.
* video sending.
* @param error If an error occurs, this pointer is set to an actual error object.
*/
- (BOOL)callFriendNumber:(OCTToxFriendNumber)friendNumber audioBitRate:(OCTToxAVAudioBitRate)audioBitRate videoBitRate:(OCTToxAVVideoBitRate)videoBitRate error:(NSError **)error;
/**
* Accept an incoming call.
*
* If answering fails for any reason, the call will still be pending and it is
* possible to try and answer it later.
*
* @param friendNumber The friend number of the friend that is calling.
* @param audioBitRate Audio bit rate in Kb/sec. Set this to kOCTToxAVAudioBitRateDisable to disable
* audio sending.
* @param videoBitRate Video bit rate in Kb/sec. Set this to kOCTToxAVVideoBitRateDisable to disable
* video sending.
*/
- (BOOL)answerIncomingCallFromFriend:(OCTToxFriendNumber)friendNumber audioBitRate:(OCTToxAVAudioBitRate)audioBitRate videoBitRate:(OCTToxAVVideoBitRate)videoBitrate error:(NSError **)error;
/**
* Send a call control to a friend
* @param control The control command to send.
* @param friendNumber The friend number of the friend this client is in a call with.
*/
- (BOOL)sendCallControl:(OCTToxAVCallControl)control toFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
#pragma mark - Controlling bit rates
/**
* Set the audio bit rate to be used in subsequent audio frames. If the passed
* bit rate is the same as the current bit rate this function will return true
* without calling a callback. If there is an active non forceful setup with the
* passed audio bit rate and the new set request is forceful, the bit rate is
* forcefully set and the previous non forceful request is cancelled. The active
* non forceful setup will be canceled in favour of new non forceful setup.
* @param bitRate The new audio bit rate in Kb/sec. Set to kOCTToxAVAudioBitRateDisable to disable audio sending.
* @param friendNumber The friend for which to set the audio bit rate.
* @param error If an error occurs, this pointer is set to an actual error object.
*/
- (BOOL)setAudioBitRate:(OCTToxAVAudioBitRate)bitRate force:(BOOL)force forFriend:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Set the video bit rate to be used in subsequent video frames. If the passed
* bit rate is the same as the current bit rate this function will return true
* without calling a callback. If there is an active non forceful setup with the
* passed video bit rate and the new set request is forceful, the bit rate is
* forcefully set and the previous non forceful request is cancelled. The active
* non forceful setup will be canceled in favour of new non forceful setup.
* @param bitRate The new video bit rate in Kb/sec. Set to kOCTToxAVVideoBitRateDisable to disable video sending.
* @param friendNumber The friend for which to set the video bit rate.
* @param error If an error occurs, this pointer is set to an actual error object.
*/
- (BOOL)setVideoBitRate:(OCTToxAVVideoBitRate)bitRate force:(BOOL)force forFriend:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
#pragma mark - Sending frames
/**
* Send an audio frame to a friend.
*
* The expected format of the PCM data is: [s1c1][s1c2][...][s2c1][s2c2][...]...
* Meaning: sample 1 for channel 1, sample 1 for channel 2, ...
* For mono audio, this has no meaning, every sample is subsequent. For stereo,
* this means the expected format is LRLRLR... with samples for left and right
* alternating.
* @param pcm An array of audio samples. The size of this array must be
* sample_count * channels.
* @param sampleCount Number of samples in this frame. Valid numbers here are
* ((sample rate) * (audio length) / 1000), where audio length can be
* 2.5, 5, 10, 20, 40 or 60 millseconds.
* @param channels Number of audio channels. Supported values are 1 and 2.
* @param samplingRate Audio sampling rate used in this frame. Valid sampling
* rates are 8000, 12000, 16000, 24000, or 48000.
* @param friendNumber The friend number of the friend to which to send an
* audio frame.
* @param error If an error occurs, this pointer is set to an actual error object.
*/
- (BOOL)sendAudioFrame:(OCTToxAVPCMData *)pcm sampleCount:(OCTToxAVSampleCount)sampleCount
channels:(OCTToxAVChannels)channels sampleRate:(OCTToxAVSampleRate)sampleRate
toFriend:(OCTToxFriendNumber)friendNumber error:(NSError **)error;
/**
* Send a video frame to a friend.
*
* Y - plane should be of size: height * width
* U - plane should be of size: (height/2) * (width/2)
* V - plane should be of size: (height/2) * (width/2)
*
* @param friendNumber The friend number of the friend to which to send a video
* frame.
* @param width Width of the frame in pixels.
* @param height Height of the frame in pixels.
* @param y Y (Luminance) plane data.
* @param u U (Chroma) plane data.
* @param v V (Chroma) plane data.
* @param error If an error occurs, this pointer is set to an actual error object.
*/
- (BOOL)sendVideoFrametoFriend:(OCTToxFriendNumber)friendNumber
width:(OCTToxAVVideoWidth)width height:(OCTToxAVVideoHeight)height
yPlane:(OCTToxAVPlaneData *)yPlane uPlane:(OCTToxAVPlaneData *)uPlane
vPlane:(OCTToxAVPlaneData *)vPlane
error:(NSError **)error;
@end

View File

@ -0,0 +1,339 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import <Foundation/Foundation.h>
typedef const int16_t OCTToxAVPCMData;
typedef size_t OCTToxAVSampleCount;
typedef uint8_t OCTToxAVChannels;
typedef uint32_t OCTToxAVSampleRate;
typedef int OCTToxAVVideoBitRate;
typedef uint16_t OCTToxAVVideoWidth;
typedef uint16_t OCTToxAVVideoHeight;
typedef const uint8_t OCTToxAVPlaneData;
typedef const int32_t OCTToxAVStrideData;
extern const OCTToxAVVideoBitRate kOCTToxAVVideoBitRateDisable;
extern NSString *const kOCTToxAVErrorDomain;
/*******************************************************************************
*
* Call state graph
*
******************************************************************************/
typedef NS_OPTIONS(NSInteger, OCTToxAVCallState) {
/**
* The call is paused by the friend.
*/
OCTToxAVFriendCallStatePaused = 0,
/**
* Set by the AV core if an error occurred on the remote end or if friend
* timed out. This is the final state after which no more state
* transitions can occur for the call. This call state will never be triggered
* in combination with other call states.
*/
OCTToxAVFriendCallStateError = 1 << 0,
/**
* The call has finished. This is the final state after which no more state
* transitions can occur for the call. This call state will never be
* triggered in combination with other call states.
*/
OCTToxAVFriendCallStateFinished = 1 << 1,
/**
* The flag that marks that friend is sending audio.
*/
OCTToxAVFriendCallStateSendingAudio = 1 << 2,
/**
* The flag that marks that friend is sending video.
*/
OCTToxAVFriendCallStateSendingVideo = 1 << 3,
/**
* The flag that marks that friend is accepting audio.
*/
OCTToxAVFriendCallStateAcceptingAudio = 1 << 4,
/**
* The flag that marks that friend is accepting video.
*/
OCTToxAVFriendCallStateAcceptingVideo = 1 << 5,
};
/*******************************************************************************
*
* Error Codes
*
******************************************************************************/
/**
* Error codes for init method.
*/
typedef NS_ENUM(NSInteger, OCTToxAVErrorInitCode) {
OCTToxAVErrorInitCodeUnknown,
/**
* One of the arguments to the function was NULL when it was not expected.
*/
OCTToxAVErrorInitNULL,
/**
* Memory allocation failure while trying to allocate structures required for
* the A/V session.
*/
OCTToxAVErrorInitCodeMemoryError,
/**
* Attempted to create a second session for the same Tox instance.
*/
OCTToxAVErrorInitMultiple,
};
/**
* Error codes for call setup.
*/
typedef NS_ENUM(NSInteger, OCTToxAVErrorCall) {
OCTToxAVErrorCallUnknown,
/**
* A resource allocation error occurred while trying to create the structures
* required for the call.
*/
OCTToxAVErrorCallMalloc,
/**
* Synchronization error occurred.
*/
OCTToxAVErrorCallSync,
/**
* The friend number did not designate a valid friend.
*/
OCTToxAVErrorCallFriendNotFound,
/**
* The friend was valid, but not currently connected.
*/
OCTToxAVErrorCallFriendNotConnected,
/**
* Attempted to call a friend while already in an audio or video call with
* them.
*/
OCTToxAVErrorCallAlreadyInCall,
/**
* Audio or video bit rate is invalid.
*/
OCTToxAVErrorCallInvalidBitRate,
};
/**
* Error codes for answer calls.
*/
typedef NS_ENUM(NSInteger, OCTToxAVErrorAnswer) {
OCTToxAVErrorAnswerUnknown,
/**
* Synchronization error occurred.
*/
OCTToxAVErrorAnswerSync,
/**
* Failed to initialize codecs for call session. Note that codec initiation
* will fail if there is no receive callback registered for either audio or
* video.
*/
OCTToxAVErrorAnswerCodecInitialization,
/**
* The friend number did not designate a valid friend.
*/
OCTToxAVErrorAnswerFriendNotFound,
/**
* The friend was valid, but they are not currently trying to initiate a call.
* This is also returned if this client is already in a call with the friend.
*/
OCTToxAVErrorAnswerFriendNotCalling,
/**
* Audio or video bit rate is invalid.
*/
OCTToxAVErrorAnswerInvalidBitRate,
};
/**
* Error codes for when sending controls.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorCallControl) {
OCTToxAVErrorControlUnknown,
/**
* Synchronization error occurred.
*/
OCTToxAVErrorControlSync,
/**
* The friend number passed did not designate a valid friend.
*/
OCTToxAVErrorControlFriendNotFound,
/**
* This client is currently not in a call with the friend. Before the call is
* answered, only CANCEL is a valid control.
*/
OCTToxAVErrorControlFriendNotInCall,
/**
* Happens if user tried to pause an already paused call or if trying to
* resume a call that is not paused.
*/
OCTToxAVErrorControlInvaldTransition,
};
/**
* Error codes for setting the bit rate.
*/
typedef NS_ENUM(NSInteger, OCTToxAVErrorSetBitRate) {
OCTToxAVErrorSetBitRateUnknown,
/**
* Synchronization error occured.
*/
OCTToxAVErrorSetBitRateSync,
/**
* The bit rate passed was not one of the supported values.<Paste>
*/
OCTToxAVErrorSetBitRateInvalidBitRate,
/**
* The friend number passed did not designate a valid friend.
*/
OCTToxAVErrorSetBitRateFriendNotFound,
/**
* This client is currently not in a call with the friend.
*/
OCTToxAVErrorSetBitRateFriendNotInCall,
};
/**
* Error codes for sending audio/video frames
*/
typedef NS_ENUM(NSInteger, OCTToxAVErrorSendFrame) {
OCTToxAVErrorSendFrameUnknown,
/**
* In case of video, one of Y, U, or V was NULL. In case of audio, the samples
* data pointer was NULL.
*/
OCTToxAVErrorSendFrameNull,
/**
* The friend number passed did not designate a valid friend.
*/
OCTToxAVErrorSendFrameFriendNotFound,
/**
* This client is currently not in a call with the friend.
*/
OCTToxAVErrorSendFrameFriendNotInCall,
/**
* Synchronization error occurred.
*/
OCTToxAVErrorSendFrameSync,
/**
* One of the frame parameters was invalid. E.g. the resolution may be too
* small or too large, or the audio sampling rate may be unsupported.
*/
OCTToxAVErrorSendFrameInvalid,
/**
* Bit rate for this payload type was not set up.
*/
OCTToxAVErrorSendFramePayloadTypeDisabled,
/**
* Failed to push frame through rtp interface.
*/
OCTToxAVErrorSendFrameRTPFailed,
};
/*******************************************************************************
*
* Call control
*
******************************************************************************/
typedef NS_ENUM(NSInteger, OCTToxAVCallControl) {
/**
* Resume a previously paused call. Only valid if the pause was caused by this
* client, if not, this control is ignored. Not valid before the call is accepted.
*/
OCTToxAVCallControlResume,
/**
* Put a call on hold. Not valid before the call is accepted.
*/
OCTToxAVCallControlPause,
/**
* Reject a call if it was not answered, yet. Cancel a call after it was
* answered.
*/
OCTToxAVCallControlCancel,
/**
* Request that the friend stops sending audio. Regardless of the friend's
* compliance, this will cause the audio_receive_frame event to stop being
* triggered on receiving an audio frame from the friend.
*/
OCTToxAVCallControlMuteAudio,
/**
* Calling this control will notify client to start sending audio again.
*/
OCTToxAVCallControlUnmuteAudio,
/**
* Request that the friend stops sending video. Regardless of the friend's
* compliance, this will cause the video_receive_frame event to stop being
* triggered on receiving an video frame from the friend.
*/
OCTToxAVCallControlHideVideo,
/**
* Calling this control will notify client to start sending video again.
*/
OCTToxAVCallControlShowVideo,
};
/*******************************************************************************
*
* Audio Bitrates. All bitrates are in kb/s.
*
******************************************************************************/
typedef NS_ENUM(NSInteger, OCTToxAVAudioBitRate) {
OCTToxAVAudioBitRateDisabled = 0,
OCTToxAVAudioBitRate8 = 8,
OCTToxAVAudioBitRate16 = 16,
OCTToxAVAudioBitRate24 = 24,
OCTToxAVAudioBitRate32 = 32,
OCTToxAVAudioBitRate48 = 48,
};

View File

@ -0,0 +1,95 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import <Foundation/Foundation.h>
#import "OCTToxAVConstants.h"
#import "OCTToxConstants.h"
@class OCTToxAV;
/**
* All delegate methods will be called on main thread.
*/
@protocol OCTToxAVDelegate <NSObject>
@optional
/**
* Receiving call from friend.
* @param audio YES audio is enabled. NO otherwise.
* @param video YES video is enabled. NO otherwise.
* @param friendNumber Friend number who is calling.
*/
- (void)toxAV:(OCTToxAV *)toxAV receiveCallAudioEnabled:(BOOL)audio videoEnabled:(BOOL)video friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Call state has changed.
* @param state The new state.
* @param friendNumber Friend number whose state has changed.
*/
- (void)toxAV:(OCTToxAV *)toxAV callStateChanged:(OCTToxAVCallState)state friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* The event is triggered when the network becomes too saturated for
* current bit rates at which point core suggests new bit rates.
* @param audioBitRate Suggested maximum audio bit rate in Kb/sec.
* @param friendNumber The friend number of the friend for which to set the bit rate.
*/
- (void)toxAV:(OCTToxAV *)toxAV audioBitRateStatus:(OCTToxAVAudioBitRate)audioBitRate forFriendNumber:(OCTToxFriendNumber)friendNumber;
/**
* The event is triggered when the network becomes too saturated for
* current bit rates at which point core suggests new bit rates.
* @param videoBitRate Suggested maximum video bit rate in Kb/sec.
* @param friendNumber The friend number of the friend for which to set the bit rate.
*/
- (void)toxAV:(OCTToxAV *)toxAV videoBitRateStatus:(OCTToxAVVideoBitRate)videoBitRate forFriendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Received audio frame from friend.
* @param pcm An array of audio samples (sample_count * channels elements).
* @param sampleCount The number of audio samples per channel in the PCM array.
* @param channels Number of audio channels.
* @param sampleRate Sampling rate used in this frame.
* @param friendNumber The friend number of the friend who sent an audio frame.
*/
- (void) toxAV:(OCTToxAV *)toxAV
receiveAudio:(OCTToxAVPCMData *)pcm
sampleCount:(OCTToxAVSampleCount)sampleCount
channels:(OCTToxAVChannels)channels
sampleRate:(OCTToxAVSampleRate)sampleRate
friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Received video frame from friend.
* @param width Width of the frame in pixels.
* @param height Height of the frame in pixels.
* @param yPlane
* @param uPlane
* @param vPlane Plane data.
* The size of plane data is derived from width and height where
* Y = MAX(width, abs(ystride)) * height,
* U = MAX(width/2, abs(ustride)) * (height/2) and
* V = MAX(width/2, abs(vstride)) * (height/2).
* @param yStride
* @param uStride
* @param vStride Strides data. Strides represent padding for each plane
* that may or may not be present. You must handle strides in
* your image processing code. Strides are negative if the
* image is bottom-up hence why you MUST abs() it when
* calculating plane buffer size.
* @param friendNumber The friend number of the friend who sent an audio frame.
*/
- (void) toxAV:(OCTToxAV *)toxAV
receiveVideoFrameWithWidth:(OCTToxAVVideoWidth)width height:(OCTToxAVVideoHeight)height
yPlane:(OCTToxAVPlaneData *)yPlane uPlane:(OCTToxAVPlaneData *)uPlane
vPlane:(OCTToxAVPlaneData *)vPlane
yStride:(OCTToxAVStrideData)yStride uStride:(OCTToxAVStrideData)uStride
vStride:(OCTToxAVStrideData)vStride
friendNumber:(OCTToxFriendNumber)friendNumber;
@end

View File

@ -0,0 +1,557 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import <Foundation/Foundation.h>
typedef uint32_t OCTToxNoSpam;
typedef uint16_t OCTToxPort;
typedef int OCTToxFriendNumber;
typedef int OCTToxMessageId;
typedef uint32_t OCTToxFileNumber;
typedef long long OCTToxFileSize;
typedef uint64_t OCTToxCapabilities;
extern const OCTToxFriendNumber kOCTToxFriendNumberFailure;
extern const OCTToxFileNumber kOCTToxFileNumberFailure;
extern const OCTToxFileSize kOCTToxFileSizeUnknown;
extern NSString *const kOCTToxErrorDomain;
/**
* Length of address. Address is hex string, has following format:
* [publicKey (32 bytes, 64 characters)][nospam number (4 bytes, 8 characters)][checksum (2 bytes, 4 characters)]
*/
extern const NSUInteger kOCTToxAddressLength;
/**
* Length of public key. It is hex string, 32 bytes, 64 characters.
*/
extern const NSUInteger kOCTToxPublicKeyLength;
/**
* Length of secret key. It is hex string, 32 bytes, 64 characters.
*/
extern const NSUInteger kOCTToxSecretKeyLength;
extern const NSUInteger kOCTToxMaxNameLength;
extern const NSUInteger kOCTToxMaxStatusMessageLength;
extern const NSUInteger kOCTToxMaxFriendRequestLength;
extern const NSUInteger kOCTToxMaxMessageLength;
extern const NSUInteger kOCTToxMaxCustomPacketSize;
extern const NSUInteger kOCTToxMaxFileNameLength;
extern const NSUInteger kOCTToxHashLength;
extern const NSUInteger kOCTToxFileIdLength;
typedef NS_ENUM(NSInteger, OCTToxProxyType) {
OCTToxProxyTypeNone,
OCTToxProxyTypeSocks5,
OCTToxProxyTypeHTTP,
};
typedef NS_ENUM(NSInteger, OCTToxConnectionStatus) {
/**
* There is no connection. This instance, or the friend the state change is about, is now offline.
*/
OCTToxConnectionStatusNone,
/**
* A TCP connection has been established. For the own instance, this means it
* is connected through a TCP relay, only. For a friend, this means that the
* connection to that particular friend goes through a TCP relay.
*/
OCTToxConnectionStatusTCP,
/**
* A UDP connection has been established. For the own instance, this means it
* is able to send UDP packets to DHT nodes, but may still be connected to
* a TCP relay. For a friend, this means that the connection to that
* particular friend was built using direct UDP packets.
*/
OCTToxConnectionStatusUDP,
};
typedef NS_ENUM(NSInteger, OCTToxUserStatus) {
/**
* User is online and available.
*/
OCTToxUserStatusNone,
/**
* User is away. Clients can set this e.g. after a user defined
* inactivity time.
*/
OCTToxUserStatusAway,
/**
* User is busy. Signals to other clients that this client does not
* currently wish to communicate.
*/
OCTToxUserStatusBusy,
};
typedef NS_ENUM(NSInteger, OCTToxMessageType) {
/**
* Normal text message. Similar to PRIVMSG on IRC.
*/
OCTToxMessageTypeNormal,
/**
* A message describing an user action. This is similar to /me (CTCP ACTION)
* on IRC.
*/
OCTToxMessageTypeAction,
/**
* msgV3 HIGH LEVEL ACK message.
*/
OCTToxMessageTypeHighlevelack,
};
typedef NS_ENUM(NSInteger, OCTToxFileKind) {
/**
* Arbitrary file data. Clients can choose to handle it based on the file name
* or magic or any other way they choose.
*/
OCTToxFileKindData,
/**
* Avatar filename. This consists of toxHash(image).
* Avatar data. This consists of the image data.
*
* Avatars can be sent at any time the client wishes. Generally, a client will
* send the avatar to a friend when that friend comes online, and to all
* friends when the avatar changed. A client can save some traffic by
* remembering which friend received the updated avatar already and only send
* it if the friend has an out of date avatar.
*
* Clients who receive avatar send requests can reject it (by sending
* OCTToxFileControl before any other controls), or accept it (by
* sending OCTToxFileControlResume). The fileId of length kOCTToxHashLength bytes
* (same length as kOCTToxFileIdLength) will contain the hash. A client can compare
* this hash with a saved hash and send OCTToxFileControlCancel to terminate the avatar
* transfer if it matches.
*
* When fileSize is set to 0 in the transfer request it means that the client has no
* avatar.
*/
OCTToxFileKindAvatar,
};
typedef NS_ENUM(NSInteger, OCTToxFileControl) {
/**
* Sent by the receiving side to accept a file send request. Also sent after a
* OCTToxFileControlPause command to continue sending or receiving.
*/
OCTToxFileControlResume,
/**
* Sent by clients to pause the file transfer. The initial state of a file
* transfer is always paused on the receiving side and running on the sending
* side. If both the sending and receiving side pause the transfer, then both
* need to send OCTToxFileControlResume for the transfer to resume.
*/
OCTToxFileControlPause,
/**
* Sent by the receiving side to reject a file send request before any other
* commands are sent. Also sent by either side to terminate a file transfer.
*/
OCTToxFileControlCancel,
};
/*******************************************************************************
*
* Error Codes
*
******************************************************************************/
/**
* Error codes for init method.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorInitCode) {
OCTToxErrorInitCodeUnknown,
/**
* Was unable to allocate enough memory to store the internal structures for the Tox object.
*/
OCTToxErrorInitCodeMemoryError,
/**
* Was unable to bind to a port. This may mean that all ports have already been bound,
* e.g. by other Tox instances, or it may mean a permission error.
*/
OCTToxErrorInitCodePortAlloc,
/**
* proxyType was invalid.
*/
OCTToxErrorInitCodeProxyBadType,
/**
* proxyAddress had an invalid format or was nil (while proxyType was set).
*/
OCTToxErrorInitCodeProxyBadHost,
/**
* proxyPort was invalid.
*/
OCTToxErrorInitCodeProxyBadPort,
/**
* The proxy host passed could not be resolved.
*/
OCTToxErrorInitCodeProxyNotFound,
/**
* The saved data to be loaded contained an encrypted save.
*/
OCTToxErrorInitCodeEncrypted,
/**
* The data format was invalid. This can happen when loading data that was
* saved by an older version of Tox, or when the data has been corrupted.
* When loading from badly formatted data, some data may have been loaded,
* and the rest is discarded. Passing an invalid length parameter also
* causes this error.
*/
OCTToxErrorInitCodeLoadBadFormat,
};
/**
* Error codes for bootstrap and addTCPRelay methods.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorBootstrapCode) {
OCTToxErrorBootstrapCodeUnknown,
/**
* The host could not be resolved to an IP address, or the IP address passed was invalid.
*/
OCTToxErrorBootstrapCodeBadHost,
/**
* The port passed was invalid. The valid port range is (1, 65535).
*/
OCTToxErrorBootstrapCodeBadPort,
};
/**
* Common error codes for all methods that set a piece of user-visible client information.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorSetInfoCode) {
OCTToxErrorSetInfoCodeUnknow,
/**
* Information length exceeded maximum permissible size.
*/
OCTToxErrorSetInfoCodeTooLong,
};
/**
* Error codes for addFriend method.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFriendAdd) {
OCTToxErrorFriendAddUnknown,
/**
* The length of the friend request message exceeded kOCTToxMaxFriendRequestLength.
*/
OCTToxErrorFriendAddTooLong,
/**
* The friend request message was empty.
*/
OCTToxErrorFriendAddNoMessage,
/**
* The friend address belongs to the sending client.
*/
OCTToxErrorFriendAddOwnKey,
/**
* A friend request has already been sent, or the address belongs to a friend
* that is already on the friend list.
*/
OCTToxErrorFriendAddAlreadySent,
/**
* The friend address checksum failed.
*/
OCTToxErrorFriendAddBadChecksum,
/**
* The friend was already there, but the nospam value was different.
*/
OCTToxErrorFriendAddSetNewNospam,
/**
* A memory allocation failed when trying to increase the friend list size.
*/
OCTToxErrorFriendAddMalloc,
};
/**
* Error codes for deleteFriend method.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFriendDelete) {
/**
* There was no friend with the given friend number. No friends were deleted.
*/
OCTToxErrorFriendDeleteNotFound,
};
/**
* Error codes for friendNumberWithPublicKey
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFriendByPublicKey) {
OCTToxErrorFriendByPublicKeyUnknown,
/**
* No friend with the given Public Key exists on the friend list.
*/
OCTToxErrorFriendByPublicKeyNotFound,
};
/**
* Error codes for publicKeyFromFriendNumber.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFriendGetPublicKey) {
/**
* No friend with the given number exists on the friend list.
*/
OCTToxErrorFriendGetPublicKeyFriendNotFound,
};
/**
* Error codes for last online methods.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFriendGetLastOnline) {
/**
* No friend with the given number exists on the friend list.
*/
OCTToxErrorFriendGetLastOnlineFriendNotFound,
};
/**
* Error codes for friend state query methods.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFriendQuery) {
OCTToxErrorFriendQueryUnknown,
/**
* The friendNumber did not designate a valid friend.
*/
OCTToxErrorFriendQueryFriendNotFound,
};
/**
* Error codes for changing isTyping.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorSetTyping) {
/**
* The friend number did not designate a valid friend.
*/
OCTToxErrorSetTypingFriendNotFound,
};
/**
* Error codes for sending message.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFriendSendMessage) {
OCTToxErrorFriendSendMessageUnknown,
/**
* The friend number did not designate a valid friend.
*/
OCTToxErrorFriendSendMessageFriendNotFound,
/**
* This client is currently not connected to the friend.
*/
OCTToxErrorFriendSendMessageFriendNotConnected,
/**
* An allocation error occurred while increasing the send queue size.
*/
OCTToxErrorFriendSendMessageAlloc,
/**
* Message length exceeded kOCTToxMaxMessageLength.
*/
OCTToxErrorFriendSendMessageTooLong,
/**
* Attempted to send a zero-length message.
*/
OCTToxErrorFriendSendMessageEmpty,
};
/**
* Error codes for sending file control.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFileControl) {
/**
* The friendNumber passed did not designate a valid friend.
*/
OCTToxErrorFileControlFriendNotFound,
/**
* This client is currently not connected to the friend.
*/
OCTToxErrorFileControlFriendNotConnected,
/**
* No file transfer with the given file number was found for the given friend.
*/
OCTToxErrorFileControlNotFound,
/**
* A OCTToxFileControlResume control was sent, but the file transfer is running normally.
*/
OCTToxErrorFileControlNotPaused,
/**
* A OCTToxFileControlResume control was sent, but the file transfer was paused by the other
* party. Only the party that paused the transfer can resume it.
*/
OCTToxErrorFileControlDenied,
/**
* A OCTToxFileControlPause control was sent, but the file transfer was already paused.
*/
OCTToxErrorFileControlAlreadyPaused,
/**
* Packet queue is full.
*/
OCTToxErrorFileControlSendq,
};
/**
* Error codes for file seek method.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFileSeek) {
/**
* The friendNumber passed did not designate a valid friend.
*/
OCTToxErrorFileSeekFriendNotFound,
/**
* This client is currently not connected to the friend.
*/
OCTToxErrorFileSeekFriendNotConnected,
/**
* No file transfer with the given file number was found for the given friend.
*/
OCTToxErrorFileSeekNotFound,
/**
* File was not in a state where it could be seeked.
*/
OCTToxErrorFileSeekDenied,
/**
* Seek position was invalid
*/
OCTToxErrorFileSeekInvalidPosition,
/**
* Packet queue is full.
*/
OCTToxErrorFileSeekSendq,
};
/**
* Error codes for fileGetFileId method.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFileGet) {
/**
* Internal error.
**/
OCTToxErrorFileGetInternal,
/**
* The friendNumber passed did not designate a valid friend.
*/
OCTToxErrorFileGetFriendNotFound,
/**
* No file transfer with the given file number was found for the given friend.
*/
OCTToxErrorFileGetNotFound,
/**
* One of the arguments to the function was NULL when it was not expected.
*/
OCTToxErrorFileGetNULL,
};
/**
* Error codes for fileSend method.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFileSend) {
OCTToxErrorFileSendUnknown,
/**
* The friendNumber passed did not designate a valid friend.
*/
OCTToxErrorFileSendFriendNotFound,
/**
* This client is currently not connected to the friend.
*/
OCTToxErrorFileSendFriendNotConnected,
/**
* Filename length exceeded kOCTToxMaxFileNameLength bytes.
*/
OCTToxErrorFileSendNameTooLong,
/**
* Too many ongoing transfers. The maximum number of concurrent file transfers
* is 256 per friend per direction (sending and receiving).
*/
OCTToxErrorFileSendTooMany,
};
/**
* Error codes for fileSendChunk method.
*/
typedef NS_ENUM(NSInteger, OCTToxErrorFileSendChunk) {
OCTToxErrorFileSendChunkUnknown,
/**
* The friendNumber passed did not designate a valid friend.
*/
OCTToxErrorFileSendChunkFriendNotFound,
/**
* This client is currently not connected to the friend.
*/
OCTToxErrorFileSendChunkFriendNotConnected,
/**
* No file transfer with the given file number was found for the given friend.
*/
OCTToxErrorFileSendChunkNotFound,
/**
* File transfer was found but isn't in a transferring state: (paused, done,
* broken, etc...) (happens only when not called from the request chunk callback).
*/
OCTToxErrorFileSendChunkNotTransferring,
/**
* Attempted to send more or less data than requested. The requested data size is
* adjusted according to maximum transmission unit and the expected end of
* the file. Trying to send less or more than requested will return this error.
*/
OCTToxErrorFileSendChunkInvalidLength,
/**
* Packet queue is full.
*/
OCTToxErrorFileSendChunkSendq,
/**
* Position parameter was wrong.
*/
OCTToxErrorFileSendChunkWrongPosition,
};

View File

@ -0,0 +1,219 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import <Foundation/Foundation.h>
#import "OCTToxConstants.h"
@class OCTTox;
/**
* All delegate methods will be called on main thread.
*/
@protocol OCTToxDelegate <NSObject>
@optional
/**
* User connection status changed.
*
* @param connectionStatus New connection status of the user.
*/
- (void)tox:(OCTTox *)tox connectionStatus:(OCTToxConnectionStatus)connectionStatus;
/**
* Received friend request from a new friend.
*
* @param message Message sent with request.
* @param publicKey New friend public key.
*/
- (void)tox:(OCTTox *)tox friendRequestWithMessage:(NSString *)message publicKey:(NSString *)publicKey;
/**
* Message received from a friend.
*
* @param message Received message.
* @param type Type of the message.
* @param friendNumber Friend number of appropriate friend.
* @param msgv3HashHex messageV3 Hash as Hexstring or nil.
* @param sendTimestamp unixtimestamp. if msgv3HashHex is nil then timestamp is ignored and current time is used.
*/
- (void)tox:(OCTTox *)tox friendMessage:(NSString *)message
type:(OCTToxMessageType)type
friendNumber:(OCTToxFriendNumber)friendNumber
msgv3HashHex:(NSString *)msgv3HashHex
sendTimestamp:(uint32_t)sendTimestamp;
/**
* Send msgV3 high level ACK message.
*
* @param message Message text.
* @param friendNumber Friend number of appropriate friend.
* @param msgv3HashHex messageV3 Hash as Hexstring.
* @param sendTimestamp unixtimestamp.
*/
- (void)tox:(OCTTox *)tox sendFriendHighlevelACK:(NSString *)message
friendNumber:(OCTToxFriendNumber)friendNumber
msgv3HashHex:(NSString *)msgv3HashHex
sendTimestamp:(uint32_t)sendTimestamp;
/**
* Friend's name was updated.
*
* @param name Updated name.
* @param friendNumber Friend number of appropriate friend.
*/
- (void)tox:(OCTTox *)tox friendNameUpdate:(NSString *)name friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Friend's Push Token was updated.
*
* @param pushToken Updated Push Token.
* @param friendNumber Friend number of appropriate friend.
*/
- (void)tox:(OCTTox *)tox friendPushTokenUpdate:(NSString *)pushToken friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Friend's status message was updated.
*
* @param statusMessage Updated status message.
* @param friendNumber Friend number of appropriate friend.
*/
- (void)tox:(OCTTox *)tox friendStatusMessageUpdate:(NSString *)statusMessage friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Friend's status was updated.
*
* @param status Updated status.
* @param friendNumber Friend number of appropriate friend.
*/
- (void)tox:(OCTTox *)tox friendStatusUpdate:(OCTToxUserStatus)status friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Friend's isTyping was updated
*
* @param isTyping Updated typing status.
* @param friendNumber Friend number of appropriate friend.
*/
- (void)tox:(OCTTox *)tox friendIsTypingUpdate:(BOOL)isTyping friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Friend's Msgv3Capability needs to be updated
*
* @param msgv3Capability Updated msgV3 status.
* @param friendNumber Friend number of appropriate friend.
*/
- (void)tox:(OCTTox *)tox friendSetMsgv3Capability:(BOOL)msgv3Capability friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Message that was previously sent by us has been delivered to a friend.
*
* @param messageId Id of message. You could get in in sendMessage method.
* @param friendNumber Friend number of appropriate friend.
*/
- (void)tox:(OCTTox *)tox messageDelivered:(OCTToxMessageId)messageId friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* Message that was previously sent by us has been delivered to a friend.
*
* @param message Received message. UNUSED for now.
* @param friendNumber Friend number of appropriate friend.
* @param msgv3HashHex messageV3 Hash as Hexstring.
* @param sendTimestamp unixtimestamp.
*/
- (void)tox:(OCTTox *)tox friendHighLevelACK:(NSString *)message
friendNumber:(OCTToxFriendNumber)friendNumber
msgv3HashHex:(NSString *)msgv3HashHex
sendTimestamp:(uint32_t)sendTimestamp;
/**
* Friend's connection status changed.
*
* @param status Updated status.
* @param friendNumber Friend number of appropriate friend.
*/
- (void)tox:(OCTTox *)tox friendConnectionStatusChanged:(OCTToxConnectionStatus)status friendNumber:(OCTToxFriendNumber)friendNumber;
/**
* This event is triggered when a file control command is received from a friend.
*
* When receiving OCTToxFileControlCancel, the client should release the
* resources associated with the file number and consider the transfer failed.
*
* @param control The control command to send.
* @param friendNumber The friend number of the friend the file is being transferred to or received from.
* @param fileNumber The friend-specific identifier for the file transfer.
*/
- (void) tox:(OCTTox *)tox fileReceiveControl:(OCTToxFileControl)control
friendNumber:(OCTToxFriendNumber)friendNumber
fileNumber:(OCTToxFileNumber)fileNumber;
/**
* If the length parameter is 0, the file transfer is finished, and the client's
* resources associated with the file number should be released. After a call
* with zero length, the file number can be reused for future file transfers.
*
* If the requested position is not equal to the client's idea of the current
* file or stream position, it will need to seek. In case of read-once streams,
* the client should keep the last read chunk so that a seek back can be
* supported. A seek-back only ever needs to read from the last requested chunk.
* This happens when a chunk was requested, but the send failed. A seek-back
* request can occur an arbitrary number of times for any given chunk.
*
* In response to receiving this callback, the client should call the method
* `fileSendChunk` with the requested chunk. If the number of bytes sent
* through that method is zero, the file transfer is assumed complete. A
* client must send the full length of data requested with this callback.
*
* @param friendNumber The friend number of the receiving friend for this file.
* @param fileNumber The file transfer identifier returned by fileSend.
* @param position The file or stream position from which to continue reading.
* @param length The number of bytes requested for the current chunk.
*/
- (void) tox:(OCTTox *)tox fileChunkRequestForFileNumber:(OCTToxFileNumber)fileNumber
friendNumber:(OCTToxFriendNumber)friendNumber
position:(OCTToxFileSize)position
length:(size_t)length;
/**
* The client should acquire resources to be associated with the file transfer.
* Incoming file transfers start in the PAUSED state. After this callback
* returns, a transfer can be rejected by sending a OCTToxFileControlCancel
* control command before any other control commands. It can be accepted by
* sending OCTToxFileControlResume.
*
* @param fileNumber The friend-specific file number the data received is associated with.
* @param friendNumber The friend number of the friend who is sending the file transfer request.
* @param kind The meaning of the file to be sent.
* @param fileSize Size in bytes of the file about to be received from the client, kOCTToxFileSizeUnknown if unknown or streaming.
* @param fileName The name of the file.
*/
- (void) tox:(OCTTox *)tox fileReceiveForFileNumber:(OCTToxFileNumber)fileNumber
friendNumber:(OCTToxFriendNumber)friendNumber
kind:(OCTToxFileKind)kind
fileSize:(OCTToxFileSize)fileSize
fileName:(NSString *)fileName;
/**
* This method is first called when a file transfer request is received, and
* subsequently when a chunk of file data for an accepted request was received.
*
* When chunk is nil, the transfer is finished and the client should release the
* resources it acquired for the transfer. After a call with chunk = nil, the
* file number can be reused for new file transfers.
*
* If position is equal to fileSize (received in the fileReceive callback)
* when the transfer finishes, the file was received completely. Otherwise, if
* fileSize was kOCTToxFileSizeUnknown, streaming ended successfully when chunk is nil.
*
* @param chunk A data containing the received chunk.
* @param fileNumber The friend-specific file number the data received is associated with.
* @param friendNumber The friend number of the friend who is sending the file.
* @param position The file position of the first byte in data.
*/
- (void) tox:(OCTTox *)tox fileReceiveChunk:(NSData *)chunk
fileNumber:(OCTToxFileNumber)fileNumber
friendNumber:(OCTToxFriendNumber)friendNumber
position:(OCTToxFileSize)position;
@end

View File

@ -0,0 +1,93 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import <Foundation/Foundation.h>
/**
* This class is used for encryption/decryption of save data.
*
* You can use class methods or create instance and use it's methods.
* Note that instance encryption/decryption methods are much faster because
* instance stores generated encryption key.
*/
@interface OCTToxEncryptSave : NSObject
/**
* Determines whether or not the given data is encrypted (by checking the magic number).
*
* @param data Data to check.
*
* @return YES if data is encrypted, NO otherwise.
*/
+ (BOOL)isDataEncrypted:(nonnull NSData *)data;
/**
* Encrypts the given data with the given passphrase.
*
* @param data Data to encrypt.
* @param passphrase Passphrase used to encrypt the data.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxEncryptSaveEncryptionError for all error codes.
*
* @return Encrypted data on success, nil on failure.
*/
+ (nullable NSData *)encryptData:(nonnull NSData *)data
withPassphrase:(nonnull NSString *)passphrase
error:(NSError *__nullable *__nullable)error;
/**
* Decrypts the given data with the given passphrase.
*
* @param data Data to decrypt.
* @param passphrase Passphrase used to decrypt the data.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxEncryptSaveDecryptionError for all error codes.
*
* @return Decrypted data on success, nil on failure.
*/
+ (nullable NSData *)decryptData:(nonnull NSData *)data
withPassphrase:(nonnull NSString *)passphrase
error:(NSError *__nullable *__nullable)error;
/**
* Creates new instance of OCTToxEncryptSave object with given passphrase. This instance can be used
* to encrypt and decrypt given data.
* Encryption key is generated and stored in this method. Due to that encrypting/decrypting data
* using instance instead of class methods is much faster, as key derivation is very expensive compared
* to the actual encryption.
*
* @param passphrase Passphrase used to encrypt/decrypt the data.
* @param toxData If you have toxData that you would like to decrypt, you have to pass it here. Salt will be extracted from data and used for key generation.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxEncryptSaveKeyDerivationError for all error codes.
*
* @return Created instance or nil in case of error.
*/
- (nullable instancetype)initWithPassphrase:(nonnull NSString *)passphrase
toxData:(nullable NSData *)toxData
error:(NSError *__nullable *__nullable)error;
/**
* Encrypts the given data.
*
* @param data Data to encrypt.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxEncryptSaveEncryptionError for all error codes.
*
* @return Encrypted data on success, nil on failure.
*/
- (nullable NSData *)encryptData:(nonnull NSData *)data error:(NSError *__nullable *__nullable)error;
/**
* Decrypts the given data.
*
* @param data Data to decrypt.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTToxEncryptSaveDecryptionError for all error codes.
*
* @return Decrypted data on success, nil on failure.
*/
- (nullable NSData *)decryptData:(nonnull NSData *)data error:(NSError *__nullable *__nullable)error;
@end

View File

@ -0,0 +1,41 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
typedef NS_ENUM(NSInteger, OCTToxEncryptSaveKeyDerivationError) {
OCTToxEncryptSaveKeyDerivationErrorNone,
OCTToxEncryptSaveKeyDerivationErrorFailed,
};
typedef NS_ENUM(NSInteger, OCTToxEncryptSaveEncryptionError) {
OCTToxEncryptSaveEncryptionErrorNone,
/**
* Some input data was empty.
*/
OCTToxEncryptSaveEncryptionErrorNull,
/**
* Encryption failed.
*/
OCTToxEncryptSaveEncryptionErrorFailed,
};
typedef NS_ENUM(NSInteger, OCTToxEncryptSaveDecryptionError) {
OCTToxEncryptSaveDecryptionErrorNone,
/**
* Some input data was empty.
*/
OCTToxEncryptSaveDecryptionErrorNull,
/**
* The input data is missing the magic number (i.e. wasn't created by this module, or is corrupted).
*/
OCTToxEncryptSaveDecryptionErrorBadFormat,
/**
* The encrypted byte array could not be decrypted. Either the data was corrupt or the password/key was incorrect.
*/
OCTToxEncryptSaveDecryptionErrorFailed,
};

View File

@ -0,0 +1,103 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import <Foundation/Foundation.h>
#import "OCTToxConstants.h"
NS_ASSUME_NONNULL_BEGIN
/**
* After creation OCTToxOptions will have predefined default values.
*/
@interface OCTToxOptions : NSObject <NSCopying>
/**
* The type of socket to create.
*
* If this is set to false, an IPv4 socket is created, which subsequently
* only allows IPv4 communication.
* If it is set to true, an IPv6 socket is created, allowing both IPv4 and
* IPv6 communication.
*/
@property (nonatomic, assign) BOOL ipv6Enabled;
/**
* Enable the use of UDP communication when available.
*
* Setting this to false will force Tox to use TCP only. Communications will
* need to be relayed through a TCP relay node, potentially slowing them down.
* Disabling UDP support is necessary when using anonymous proxies or Tor.
*/
@property (nonatomic, assign) BOOL udpEnabled;
/**
* Enable local network peer discovery.
*
* Disabling this will cause Tox to not look for peers on the local network.
*/
@property (nonatomic, assign) BOOL localDiscoveryEnabled;
/**
* Pass communications through a proxy.
*/
@property (nonatomic, assign) OCTToxProxyType proxyType;
/**
* The IP address or DNS name of the proxy to be used.
*
* If used, this must be non-NULL and be a valid DNS name. The name must not
* exceed 255 characters.
*
* This member is ignored (it can be nil) if proxyType is OCTToxProxyTypeNone.
*/
@property (nonatomic, copy, nullable) NSString *proxyHost;
/**
* The port to use to connect to the proxy server.
*
* Ports must be in the range (1, 65535). The value is ignored if
* proxyType is OCTToxProxyTypeNone.
*/
@property (nonatomic, assign) uint16_t proxyPort;
/**
* The start port of the inclusive port range to attempt to use.
*
* If both start_port and end_port are 0, the default port range will be
* used: [33445, 33545].
*
* If either start_port or end_port is 0 while the other is non-zero, the
* non-zero port will be the only port in the range.
*
* Having start_port > end_port will yield the same behavior as if start_port
* and end_port were swapped.
*/
@property (nonatomic, assign) uint16_t startPort;
/**
* The end port of the inclusive port range to attempt to use.
*/
@property (nonatomic, assign) uint16_t endPort;
/**
* The port to use for the TCP server (relay). If 0, the TCP server is
* disabled.
*
* Enabling it is not required for Tox to function properly.
*
* When enabled, your Tox instance can act as a TCP relay for other Tox
* instance. This leads to increased traffic, thus when writing a client
* it is recommended to enable TCP server only if the user has an option
* to disable it.
*/
@property (nonatomic, assign) uint16_t tcpPort;
/**
* Enables or disables UDP hole-punching in toxcore. (Default: enabled).
*/
@property (nonatomic, assign) BOOL holePunchingEnabled;
@end
NS_ASSUME_NONNULL_END