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,57 @@
// 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
@protocol OCTSubmanagerBootstrap <NSObject>
/**
* Add node to bootstrap with.
*
* This will NOT start bootstrapping. To start actual bootstrapping set all desired nodes
* and call `bootstrap` method.
*
* @param ipv4Host IPv4 hostname or an IP address of the node.
* @param ipv6Host IPv4 hostname or an IP address of the node.
* @param udpPort The port on the host on which the bootstrap Tox instance is listening.
* @param tcpPorts NSNumbers with OCTToxPorts on which the TCP relay is listening.
* @param publicKey Public key of the node (of kOCTToxPublicKeyLength length).
*/
- (void)addNodeWithIpv4Host:(nullable NSString *)ipv4Host
ipv6Host:(nullable NSString *)ipv6Host
udpPort:(OCTToxPort)udpPort
tcpPorts:(NSArray<NSNumber *> *)tcpPorts
publicKey:(NSString *)publicKey;
/**
* Add nodes from https://nodes.tox.chat/. objcTox is trying to keep this list up to date.
* You can check all nodes and update date in nodes.json file.
*
* This will NOT start bootstrapping. To start actual bootstrapping set all desired nodes
* and call `bootstrap` method.
*/
- (void)addPredefinedNodes;
/**
* You HAVE TO call this method on startup to connect to Tox network.
*
* Before calling this method add nodes to bootstrap with.
*
* After calling this method
* - if manager wasn't connected before it will start bootstrapping immediately.
* - if it was connected before, it will wait 10 to connect to existing nodes
* before starting actually bootstrapping.
*
* When bootstrapping, submanager will bootstrap 4 random nodes from a list every 5 seconds
* until is will be connected.
*/
- (void)bootstrap;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,145 @@
// 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 "OCTView.h"
#import "OCTChat.h"
#import "OCTToxAVConstants.h"
#import "OCTSubmanagerCallsDelegate.h"
@class OCTToxAV;
@class OCTCall;
@protocol OCTSubmanagerCalls <NSObject>
@property (nullable, weak, nonatomic) id<OCTSubmanagerCallDelegate> delegate;
/**
* Set the property to YES to enable the microphone, otherwise NO.
* Default value is YES at the start of every call;
**/
@property (nonatomic, assign) BOOL enableMicrophone;
/**
* This must be called once after initialization.
* @param error Pointer to an error when setting up.
* @return YES on success, otherwise NO.
*/
- (BOOL)setupAndReturnError:(NSError *__nullable *__nullable)error;
/**
* This class is responsible for telling the end-user what calls we have available.
* We can also initialize a call session from here.
* @param chat The chat for which we would like to initiate a call.
* @param enableAudio YES for Audio, otherwise NO.
* @param enableVideo YES for Video, otherwise NO.
* @param error Pointer to an error when attempting to answer a call
* @return OCTCall session
*/
- (nullable OCTCall *)callToChat:(nonnull OCTChat *)chat
enableAudio:(BOOL)enableAudio
enableVideo:(BOOL)enableVideo
error:(NSError *__nullable *__nullable)error;
/**
* Enable video calling for an active call.
* Use this when you started a call without video in the first place.
* @param enable YES to enable video, NO to stop video sending.
* @param call Call to enable video for.
* @param error Pointer to an error object.
* @return YES on success, otherwise NO.
*/
- (BOOL)enableVideoSending:(BOOL)enable
forCall:(nonnull OCTCall *)call
error:(NSError *__nullable *__nullable)error;
/**
* Answer a call
* @param call The call session we would like to answer
* @param enableAudio YES for Audio, otherwise NO.
* @param enableVideo YES for Video, otherwise NO.
* @param error Pointer to an error when attempting to answer a call
* @return YES if we were able to succesfully answer the call, otherwise NO.
*/
- (BOOL)answerCall:(nonnull OCTCall *)call
enableAudio:(BOOL)enableAudio
enableVideo:(BOOL)enableVideo
error:(NSError *__nullable *__nullable)error;
/**
* Send call control to call.
* @param control The control to send to call.
* @param call The appopriate call to send to.
* @param error Pointer to error object if there's an issue muting the call.
* @return YES if succesful, NO otherwise.
*/
- (BOOL)sendCallControl:(OCTToxAVCallControl)control
toCall:(nonnull OCTCall *)call
error:(NSError *__nullable *__nullable)error;
/**
* The OCTView that will have the video feed.
*/
- (nullable OCTView *)videoFeed;
/**
* The preview video of the user.
* You must be in a video call for this to show. Otherwise the layer will
* just be black.
* @param completionBlock Block responsible for using the layer. This
* must not be nil.
*/
- (void)getVideoCallPreview:(void (^__nonnull)( CALayer *__nullable layer))completionBlock;
/**
* Set the Audio bit rate.
* @param bitrate The bitrate to change to.
* @param call The Call to set the bitrate for.
* @param error Pointer to error object if there's an issue setting the bitrate.
*/
- (BOOL)setAudioBitrate:(int)bitrate forCall:(nonnull OCTCall *)call error:(NSError *__nullable *__nullable)error;
#if ! TARGET_OS_IPHONE
/**
* Set input source and output targets for A/V.
*
* On iPhone OS, you must pass one of the OCT[Input|Output]Device... constants
* as the deviceUniqueID.
* On OS X, you can get valid deviceUniqueID values from:
* - AVFoundation: video and audio (inputs only) (AVCaptureDevice uniqueID)
* - Core Audio: audio inputs and outputs (kAudioDevicePropertyDeviceUID).
* @param deviceUniqueID The device ID to use. May be nil, in which case
* a default device will be used
*/
- (BOOL)setAudioInputDevice:(nullable NSString *)deviceUniqueID
error:(NSError *__nullable *__nullable)error;
- (BOOL)setAudioOutputDevice:(nullable NSString *)deviceUniqueID
error:(NSError *__nullable *__nullable)error;
- (BOOL)setVideoInputDevice:(nullable NSString *)deviceUniqueID
error:(NSError *__nullable *__nullable)error;
#else
/**
* Send the audio to the speaker
* @param speaker YES to send audio to speaker, NO to reset to default.
* @param error Pointer to error object.
* @return YES if successful, otherwise NO.
*/
- (BOOL)routeAudioToSpeaker:(BOOL)speaker
error:(NSError *__nullable *__nullable)error;
/**
* Use a different camera for input.
* @param front YES to use the front camera, NO to use the
* rear camera. Front camera is used by default.
* @error Pointer to error object.
* @return YES on success, otherwise NO.
*/
- (BOOL)switchToCameraFront:(BOOL)front error:(NSError *__nullable *__nullable)error;
#endif
@end

View File

@ -0,0 +1,15 @@
// 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/.
@class OCTCall;
@protocol OCTSubmanagerCalls;
@protocol OCTSubmanagerCallDelegate <NSObject>
/**
* This gets called when we receive a call.
**/
- (void)callSubmanager:(id<OCTSubmanagerCalls>)callSubmanager receiveCall:(OCTCall *)call audioEnabled:(BOOL)audioEnabled videoEnabled:(BOOL)videoEnabled;
@end

View File

@ -0,0 +1,84 @@
// 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 OCTChat;
@class OCTFriend;
@class OCTMessageAbstract;
@protocol OCTSubmanagerChats <NSObject>
/**
* Searches for a chat with specific friend. If chat is not found creates one and returns it.
*
* @param friend Friend to get/create chat with.
*
* @return Chat with specific friend.
*/
- (OCTChat *)getOrCreateChatWithFriend:(OCTFriend *)friend;
/**
* Removes given messages.
*
* @param messages Array with messages to remove.
*
* @warning Destructive operation! There is no way to restore messages after removal.
*/
- (void)removeMessages:(NSArray<OCTMessageAbstract *> *)messages;
/**
* Removes all messages in chat and chat itself.
*
* @param chat Chat to remove in.
* @param removeChat Whether remove chat or not
*
* @warning Destructive operation! There is no way to restore chat or messages after removal.
*/
- (void)removeAllMessagesInChat:(OCTChat *)chat removeChat:(BOOL)removeChat;
/**
* Send text message to specific chat
*
* @param chat Chat send message to.
* @param text Text to send.
* @param type Type of message to send.
* @param successBlock Block called when message was successfully send.
* @param message Message that was send.
* @param failureBlock Block called when submanager failed to send message.
* @param error Error that occurred. See OCTToxErrorFriendSendMessage for all error codes.
*/
- (void)sendMessageToChat:(OCTChat *)chat
text:(NSString *)text
type:(OCTToxMessageType)type
successBlock:(void (^)(OCTMessageAbstract *message))userSuccessBlock
failureBlock:(void (^)(NSError *error))userFailureBlock;
/**
* Trigger PUSH Message to yourself
*/
- (void)sendOwnPush;
/**
* Trigger PUSH Message to Friend if the Text Message was sent in a period where the friend
* was online to us, but the friend was in fact already offline.
* so no message was sent AND not PUSH was triggered.
*/
- (void)sendMessagePushToChat:(OCTChat *)chat;
/**
* Set our typing status for a chat. You are responsible for turning it on or off.
*
* @param isTyping Status showing whether user is typing or not.
* @param chat Chat 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)setIsTyping:(BOOL)isTyping inChat:(OCTChat *)chat error:(NSError **)error;
@end

View File

@ -0,0 +1,124 @@
// 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>
@class OCTMessageAbstract;
@class OCTChat;
@protocol OCTSubmanagerFilesProgressSubscriber;
@protocol OCTSubmanagerFiles <NSObject>
/**
* Send given data to particular chat. After sending OCTMessageAbstract with messageFile will be added to this chat.
* You can monitor progress using this message.
*
* File will be saved in uploaded files directory (see OCTFileStorageProtocol).
*
* @param data Data to send.
* @param fileName Name of the file.
* @param chat Chat to send data to.
* @param failureBlock Block that will be called in case of upload failure.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTSendFileError for all error codes.
*/
- (void)sendData:(nonnull NSData *)data
withFileName:(nonnull NSString *)fileName
toChat:(nonnull OCTChat *)chat
failureBlock:(nullable void (^)(NSError *__nonnull error))failureBlock;
/**
* Send given file to particular chat. After sending OCTMessageAbstract with messageFile will be added to this chat.
* You can monitor progress using this message.
*
* @param filePath Path of file to upload.
* @param moveToUploads If YES file will be moved to uploads directory.
* @param chat Chat to send file to.
* @param failureBlock Block that will be called in case of upload failure.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTSendFileError for all error codes.
*/
- (void)sendFileAtPath:(nonnull NSString *)filePath
moveToUploads:(BOOL)moveToUploads
toChat:(nonnull OCTChat *)chat
failureBlock:(nullable void (^)(NSError *__nonnull error))failureBlock;
/**
* Accept file transfer.
*
* @param message Message with file transfer. Message should be incoming and have OCTMessageFile with
* fileType OCTMessageFileTypeWaitingConfirmation. Otherwise nothing will happen.
* @param failureBlock Block that will be called in case of download failure.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTAcceptFileError for all error codes.
*/
- (void)acceptFileTransfer:(nonnull OCTMessageAbstract *)message
failureBlock:(nullable void (^)(NSError *__nonnull error))failureBlock;
/**
* Cancel file transfer. File transfer can be waiting confirmation or active.
*
* @param message Message with file transfer. Message should have OCTMessageFile. Otherwise nothing will happen.
*/
- (BOOL)cancelFileTransfer:(nonnull OCTMessageAbstract *)message error:(NSError *__nullable *__nullable)error;
/**
* Retry to send file using same OCTMessageAbstract. This message should have Canceled type, otherwise retry will failure.
*
* @param message File transfer message to send.
* @param failureBlock Block that will be called in case of upload failure.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTSendFileError for all error codes.
*/
- (void)retrySendingFile:(nonnull OCTMessageAbstract *)message
failureBlock:(nullable void (^)(NSError *__nonnull error))failureBlock;
/**
* Pause or resume file transfer.
* - For pausing transfer should be in Loading state or paused by friend, otherwise nothing will happen.
* - For resuming transfer should be in Paused state and paused by user, otherwise nothing will happen.
*
* @param pause Flag notifying of pausing/resuming file transfer.
* @param message Message with file transfer. Message should have OCTMessageFile.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTFileTransferError for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)pauseFileTransfer:(BOOL)pause
message:(nonnull OCTMessageAbstract *)message
error:(NSError *__nullable *__nullable)error;
/**
* Add progress subscriber for given file transfer. Subscriber will receive progress immediately after subscribing.
* File transfer should be in Loading or Paused state, otherwise subscriber won't be added.
*
* @param subscriber Object listening to progress protocol.
* @param message Message with file transfer. Message should have OCTMessageFile. Otherwise nothing will happen.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTFileTransferError for all error codes.
*
* @return YES on success, NO on failure.
*
* @warning Subscriber will be stored as weak reference, so it is safe to dealloc it without unsubscribing.
*/
- (BOOL)addProgressSubscriber:(nonnull id<OCTSubmanagerFilesProgressSubscriber>)subscriber
forFileTransfer:(nonnull OCTMessageAbstract *)message
error:(NSError *__nullable *__nullable)error;
/**
* Remove progress subscriber for given file transfer.
*
* @param subscriber Object listening to progress protocol.
* @param message Message with file transfer. Message should have OCTMessageFile. Otherwise nothing will happen.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTFileTransferError for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)removeProgressSubscriber:(nonnull id<OCTSubmanagerFilesProgressSubscriber>)subscriber
forFileTransfer:(nonnull OCTMessageAbstract *)message
error:(NSError *__nullable *__nullable)error;
@end

View File

@ -0,0 +1,30 @@
// 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>
@class OCTMessageAbstract;
@protocol OCTSubmanagerFilesProgressSubscriber <NSObject>
/**
* Method called on download/upload progress.
*
* @param progress Progress of download/upload. From 0.0 to 1.0.
* @param message File message with progress update.
*/
- (void)submanagerFilesOnProgressUpdate:(float)progress message:(nonnull OCTMessageAbstract *)message;
/**
* Method called on download/upload eta update.
*
* @param eta Estimated time of finish of download/upload.
* @param bytesPerSecond Speed of download/upload.
* @param message File message with progress update.
*/
- (void)submanagerFilesOnEtaUpdate:(CFTimeInterval)eta
bytesPerSecond:(OCTToxFileSize)bytesPerSecond
message:(nonnull OCTMessageAbstract *)message;
@end

View File

@ -0,0 +1,53 @@
// 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>
@class OCTFriendRequest;
@class OCTFriend;
@protocol OCTSubmanagerFriends <NSObject>
/**
* Send friend request to given address. Automatically adds friend with this address to friend list.
*
* @param address Address of a friend. If required.
* @param message Message to send with friend request. Is required.
* @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 YES on success, NO on failure.
*/
- (BOOL)sendFriendRequestToAddress:(NSString *)address message:(NSString *)message error:(NSError **)error;
/**
* Approve given friend request. After approving new friend will be added and friendRequest will be removed.
*
* @param friendRequest Friend request to approve.
* @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 YES on success, NO on failure.
*/
- (BOOL)approveFriendRequest:(OCTFriendRequest *)friendRequest error:(NSError **)error;
/**
* Remove friend request from list. This cannot be undone.
*
* @param friendRequest Friend request to remove.
*/
- (void)removeFriendRequest:(OCTFriendRequest *)friendRequest;
/**
* Remove friend from list. This cannot be undone.
*
* @param friend Friend 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)removeFriend:(OCTFriend *)friend error:(NSError **)error;
@end

View File

@ -0,0 +1,72 @@
// 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 "OCTManagerConstants.h"
@class OCTObject;
@class OCTFriend;
@class OCTChat;
@class RLMResults;
@protocol OCTSubmanagerObjects <NSObject>
/**
* This property can be used to save any generic data you like.
*
* The default value is nil.
*/
@property (strong, nonatomic) NSData *genericSettingsData;
/**
* Returns fetch request for specified type.
*
* @param type Type of fetch request.
* @param predicate Predicate that represents search query.
*
* @return RLMResults with objects of specified type.
*/
- (RLMResults *)objectsForType:(OCTFetchRequestType)type predicate:(NSPredicate *)predicate;
/**
* Returns object for specified type with uniqueIdentifier.
*
* @param uniqueIdentifier Unique identifier of object.
* @param type Type of object.
*
* @return Object of specified type or nil, if object does not exist.
*/
- (OCTObject *)objectWithUniqueIdentifier:(NSString *)uniqueIdentifier forType:(OCTFetchRequestType)type;
#pragma mark - Friends
/**
* Sets nickname property for friend.
*
* @param friend Friend to change.
* @param nickname New nickname. If nickname is empty or nil, it will be set to friends name.
* If friend don't have name, it will be set to friends publicKey.
*/
- (void)changeFriend:(OCTFriend *)friend nickname:(NSString *)nickname;
#pragma mark - Chats
/**
* Sets enteredText property for chat.
*
* @param chat Chat to change.
* @param enteredText New text.
*/
- (void)changeChat:(OCTChat *)chat enteredText:(NSString *)enteredText;
/**
* Sets lastReadDateInterval property for chat.
*
* @param chat Chat to change.
* @param lastReadDateInterval New interval.
*/
- (void)changeChat:(OCTChat *)chat lastReadDateInterval:(NSTimeInterval)lastReadDateInterval;
@end

View File

@ -0,0 +1,104 @@
// 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"
@protocol OCTSubmanagerUser;
@protocol OCTSubmanagerUserDelegate <NSObject>
- (void)submanagerUser:(nonnull id<OCTSubmanagerUser>)submanager connectionStatusUpdate:(OCTToxConnectionStatus)connectionStatus;
@end
@protocol OCTSubmanagerUser <NSObject>
@property (weak, nonatomic, nullable) id<OCTSubmanagerUserDelegate> delegate;
/**
* Indicates if client is connected to the DHT.
*/
@property (assign, nonatomic, readonly) OCTToxConnectionStatus connectionStatus;
/**
* Client's 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, nonnull) NSString *userAddress;
/**
* Client's Tox Public Key (long term public key) of kOCTToxPublicKeyLength.
*/
@property (strong, nonatomic, readonly, nonnull) NSString *publicKey;
/**
* 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;
/**
* Set the nickname for the 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.
*/
- (BOOL)setUserName:(nullable NSString *)name error:(NSError *__nullable *__nullable)error;
/**
* Get client's nickname.
*
* @return Client's nickname or nil in case of error.
*/
- (nullable NSString *)userName;
/**
* Set client's 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.
*/
- (BOOL)setUserStatusMessage:(nullable NSString *)statusMessage error:(NSError *__nullable *__nullable)error;
/**
* Get client's status message.
*
* @return Client's status message.
*/
- (nullable NSString *)userStatusMessage;
/**
* Set user avatar. Avatar should be <= kOCTManagerMaxAvatarSize.
*
* @param avatar NSData representation of avatar image.
* @param error If an error occurs, this pointer is set to an actual error object containing the error information.
* See OCTSetUserAvatarError for all error codes.
*
* @return YES on success, NO on failure.
*/
- (BOOL)setUserAvatar:(nullable NSData *)avatar error:(NSError *__nullable *__nullable)error;
/**
* Get data representation of user avatar.
*
* @return Data with user avatar if exists.
*/
- (nullable NSData *)userAvatar;
@end