libtoxcore-racket
(require libtoxcore-racket) | package: libtoxcore-racket |
1 Examples
; simple 1-to-1 function wrapper (require libtoxcore-racket) (define-values (my-tox new-err) (tox-new TOX_ENABLE_IPV6_DEFAULT)) (define my-name "Toxizen5k") (define my-status-message "Testing Tox with the Racket wrapper!") (set-self-name! my-tox my-name) (set-self-status-message! my-status-message) (tox-kill! my-tox)
2 Constants and Enums
Tox uses several enums and many different constants. It is important to be familiar with the enums, especially.
2.1 Constants
value
TOX_PUBLIC_KEY_SIZE : 32
value
TOX_SECRET_KEY_SIZE : 32
value
:
(+ TOX_PUBLIC_KEY_SIZE (ctype-sizeof uint32_t) (ctype-sizeof uint16_t))
value
TOX_MAX_NAME_LENGTH : 128
value
value
value
TOX_MAX_MESSAGE_LENGTH : 1372
value
TOX_MAX_CUSTOM_PACKET_SIZE : 1373
value
TOX_HASH_LENGTH : 32
value
TOX_FILE_ID_LENGTH : 32
value
TOX_MAX_FILENAME_LENGTH : 255
value
2.2 Enums
Tox uses various enumerations in many of its functions and they are explained below.
value
_TOX-USER-STATUS : '(available away busy)
value
_TOX-MESSAGE-TYPE : '(normal action)
value
_TOX-PROXY-TYPE : '(none http socks5)
value
_TOX-ERR-OPTIONS-NEW : '(ok malloc)
value
_TOX-ERR-NEW :
'(ok null malloc port-alloc proxy-bad-type proxy-bad-host proxy-bad-port proxy-not-found load-encrypted load-bad-format)
'port-alloc is returned when the function 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.
'proxy-bad-type is returned when the proxy-type variable was invalid.
'proxy-bad-host is returned when the proxy-type variable was valid, but the proxy-host had an invalid format or was NULL.
'proxy-bad-port is returned when the proxy-type was valid, but the proxy-port was invalid.
'proxy-not-found is returned when the proxy host passed could not be resolved.
'load-encrypted is returned when the bytes loaded into the function contained an encrypted save.
'load-bad-format is returned when 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.
value
_TOX-ERR-BOOTSTRAP : '(ok null bad-host bad-port)
value
_TOX-CONNECTION : '(none tcp udp)
value
_TOX-ERR-SET-INFO : '(ok null too-long)
value
_TOX-ERR-FRIEND-SEND-MESSAGE :
'(ok null friend-not-found friend-not-connected sendq too-long empty)
value
_TOX-FILE-KIND : '(data avatar)
'avatar is used when sending avatar 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 TOX_FILE_CONTROL_CANCEL before any other controls), or accept it (by sending TOX_FILE_CONTROL_RESUME). The file_id of length TOX_HASH_LENGTH bytes (same length as TOX_FILE_ID_LENGTH) will contain the hash. A client can compare this hash with a saved hash and send TOX_FILE_CONTROL_CANCEL to terminate the avatar transfer if it matches. When file_size is set to 0 in the transfer request it means that the client has no avatar.
value
_TOX-FILE-CONTROL : '(resume pause cancel)
'pause is 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 TOX_FILE_CONTROL_RESUME for the transfer to resume.
'cancel is sent by the receiving client to reject a file send request before any other commands are sent. Also sent by either side to terminate a file transfer.
value
_TOX-ERR-FILE-CONTROL :
'(ok friend-not-found friend-not-connected not-found not-paused denied already-paused sendq)
'denied is returned when a 'resume control was sent, but the file transfer was paused by the other party. Only the party that paused the transfar can resume it.
'senq is returned when the packet queue is full.
value
_TOX-ERR-FILE-SEEK :
'(ok friend-not-found friend-not-connected transfer-not-found seek-denied invalid-position sendq)
'seek-denied is returned when the file was not in a state where it could be seeked.
'invalid-position is returned when the seek position was invalid.
'senq is returned when the packet queue is full.
value
_TOX-ERR-FILE-GET : '(ok friend-not-found transfer-not-found)
value
_TOX-ERR-FILE-SEND :
'(ok null friend-not-found friend-not-connected name-too-long too-many)
value
_TOX-ERR-FILE-SEND-CHUNK :
'(ok null friend-not-found friend-not-connected not-found not-transferring invalid-length senq wrong-position)
value
_TOX-ERR-FRIEND-CUSTOM-PACKET :
'(ok null friend-not-found friend-not-connected invalid empty too-long sendq)
value
_TOX-ERR-KEY-DERIVATION : '(ok null failed)
value
_TOX-ERR-ENCRYPTION :
'(ok null key-derivation-failed encryption-failed)
'key-derivation-failed is returned when the crypto lib was unable to derive a key from the given passphrase, which is usually a lack of memory issue. The functions accepting keys do not produce this error.
'encryption-failed is returned when the encryption itself failed.
value
_TOX-ERR-DECRYPTION :
'(ok null invalid-length bad-format key-derivation-failed decryption-failed)
value
_TOX-GROUPCHAT-TYPE : '(text av)
value
_TOX-CHAT-CHANGE-PEER : '(add del name)
'del is for when a peer has left the groupchat.
'name is for when a peer has changed her nickname.
procedure
(_ToxAvCallbackID sym) → (or/c false? integer?)
sym :
(or/c 'Invite 'Ringing 'Start 'Cancel 'Reject 'End 'RequestTimeout 'PeerTimeout 'PeerCSChange 'SelfCSChange)
'Ringing is when the peer is ready to accept/reject the call.
'Start is when the call (rtp transmission) has started.
'Cancel is when the side that initiated the call has canceled the invite.
'Reject is when the side that was invited rejected the call.
'End is when the call that was active has ended.
'RequestTimeout is when the request didn’t get a response in time.
'PeerTimeout peer timed out; stop the call.
'PeerCSChange is when the peer changed csettings. Prepare for changed AV.
'SelfCSChange is for csettings change confirmation. Once triggered, the peer is ready to receive changed AV.
procedure
(_ToxAvCallType sym) → (or/c false? integer?)
sym : (or/c 'Audio 'Video)
procedure
(_ToxAvCallState sym) → (or/c false? integer?)
sym :
(or/c 'CallNonExistant 'CallInviting 'CallStarting 'CallActive 'CallHold 'CallHangedUp)
'CallInviting is for when we’re sending a call invite.
'CallStarting is for when we’re getting a call invite.
procedure
(_ToxAvError sym) → (or/c false? integer?)
sym :
(or/c 'None = 0 'Unknown = -1 'NoCall = -20 'InvalidState = -21 'AlreadyInCallWithPeer = -22 'ReachedCallLimit = -23 'InitializingCodecs = -30 'SettingVideoResolution = -31 'SettingVideoBitrate = -32 'SplittingVideoPayload = -33 'EncodingVideo = -34 'EncodingAudio = -35 'SendingPayload = -40 'CreatingRtpSessions = -41 'NoRtpSession = -50 'InvalidCodecState = -51 'PacketTooLarge = -52)
'InvalidState means we are trying to perform a call action while in an invalid state.
'AlreadyInCallWithPeer means we are trying to call peer when already in a call with peer.
'ReachedCallLimit means we cannot handle more calls.
'InitializingCodecs means we failed to create a CSSession.
'SplittingVideoPayload means there was an error splitting the video payload
'EncodingVideo means vpx_codec_encode failed.
'EncodingAudio means opus_encode failed.
'SendingPayload means sending lossy packet failed.
'CreatingRtpSessions means one of the rtp sessions failed to initialize.
'NoRtpSession means we tried to perform an rtp action on an invalid session.
'InvalidCodecState means the codec state was not initialized.
'PacketTooLarge means the buffer exceeds size while encoding.
Those not listed above are self-explanatory.
procedure
(_ToxAvCapabilities sym) → (or/c false? integer?)
sym :
(or/c 'AudioEncoding 'AudioDecoding 'VideoEncoding 'VideoDecoding)
'AudioDecoding is equivalent to 1 << 1 or (expt 2 1)
'VideoEncoding is equivalent to 1 << 2 or (expt 2 2)
'VideoDecoding is equivalent to 1 << 3 or (expt 2 3)
3 Functions
(require libtoxcore-racket/functions) | |
package: libtoxcore-racket |
The functions in libtoxcore-racket/functions are the base wrappers for the functions found in libtoxcore.
3.1 Getters and Setters
procedure
(friendlist-length tox) → integer?
tox : _Tox-pointer
You should use this to determine how much memory to allocate for copy_friendlist.
procedure
(friend-exists? tox friendnumber) → boolean?
tox : _Tox-pointer friendnumber : integer?
return #t if friend exists.
return #f if friend doesn’t exist.
Return an address to give to others. (Must be transformed into hex format for ordinary usage).
return public key if success.
return #f if failure.
procedure
(get-friend-connection-status tox friendnumber) → integer? tox : _Tox-pointer friendnumber : integer?
return 1 if friend is connected to us (Online).
return 0 if friend is not connected to us (Offline).
return -1 on failure.
procedure
tox : _Tox-pointer list-size : integer?
Returns the friend list (in bytes).
If the list-size was too small, the contents of the return value will be truncated to list-size.
procedure
(get-friend-number tox public-key) → (or/c integer? boolean?)
tox : _Tox-pointer public-key : bytes?
return #f if no such friend
returns #t if friend is typing.
returns #f if friend is not typing.
procedure
(get-last-online tox friendnumber) → (or/c integer? boolean?)
tox : _Tox-pointer friendnumber : integer?
returns #f on error.
procedure
tox : _Tox-pointer friendnumber : integer?
return #f if failure.
procedure
tox : _Tox-pointer friendnumber : integer?
returns #f on failure.
procedure
(get-num-online-friends tox) → integer?
tox : _Tox-pointer
return 0 on error.
return #f on failure.
return #f on failure.
Values unknown to your application should be represented as TOX_USERSTATUS_NONE.
If friendnumber is invalid, this shall return TOX_USERSTATUS_INVALID.
procedure
(get-self-user-status tox) → integer?
tox : _Tox-pointer
procedure
(get-status-message tox friendnumber) → (or/c boolean? bytes?)
tox : _Tox-pointer friendnumber : integer?
The self variant will return our own status message.
returns the status message (in bytes) of the friend on success.
return #f on failure.
procedure
(get-status-message-size tox friendnumber) → integer?
tox : _Tox-pointer friendnumber : integer?
returns #f on failure.
name must be a string of maximum TOX_MAX_NAME_LENGTH length.
length must be at least 1 byte.
length is the length of name with the NULL terminator.
return #t if success.
return #f if failure.
procedure
(set-status-message! tox status [len]) → boolean?
tox : _Tox-pointer status : string?
len : integer? =
(bytes-length (string->bytes/utf-8 status))
max length of the status is TOX_MAX_STATUSMESSAGE_LENGTH.
returns #t on success.
returns #f on failure.
userstatus must be one of TOX_USERSTATUS values.
returns #t on success.
returns #f on failure.
procedure
(set-user-is-typing! tox friendnumber istyping?) → boolean? tox : _Tox-pointer friendnumber : integer? istyping? : boolean?
You are responsible for turning it on or off.
returns #t on success.
returns #f on failure.
return #f on failure
procedure
(get-group-names tox groupnumber len) → (or/c boolean? list?)
tox : _Tox-pointer groupnumber : integer? len : integer?
Returns a list whose car is the lengths if the names in its cdr on success.
return #f on failure.
procedure
(get-group-peername tox groupnumber peernumber) → (or/c boolean? bytes?) tox : _Tox-pointer groupnumber : integer? peernumber : integer?
return #f on failure
procedure
(get-group-peer-pubkey tox groupnumber peernumber) → (or/c integer? bytes?) tox : _Tox-pointer groupnumber : integer? peernumber : integer?
procedure
(count-chatlist tox) → integer?
tox : _Tox-pointer
You should use this to determine how much memory to allocate for copy_chatlist.
procedure
tox : _Tox-pointer list-size : integer?
If list-size was too small, the contents of the return value will be truncated to list-size.
return 0 on failure.
procedure
(get-nospam tox) → integer?
tox : _Tox-pointer
procedure
(get-keys tox secret-key public-key) → void?
tox : _Tox-pointer secret-key : bytes? public-key : bytes?
public-key and secret-key must be 32 bytes long.
if the pointer is NULL, no data will be copied to it.
procedure
(group-set-title! tox groupnumber title) → boolean?
tox : _Tox-pointer groupnumber : integer? title : bytes?
return #t on success
return #f on failure.
procedure
tox : _Tox-pointer groupnumber : integer?
Return title (in bytes) on success.
return #f on failure.
3.2 Interact with Tox
procedure
(bootstrap-from-address tox address port public-key) → boolean? tox : _Tox-pointer address : string? port : integer? public-key : string?
address can be a hostname or an IP address (IPv4 or IPv6)
returns #t if the address was converted into an IP address
returns #f otherwise
procedure
(tox-connected? tox) → boolean?
tox : _Tox-pointer
return #t if we are.
procedure
(send-message tox friendnumber message) → integer?
tox : _Tox-pointer friendnumber : integer? message : bytes?
return the message id if packet was successfully put into the send queue.
return 0 if it was not.
maximum length of messages is TOX_MAX_MESSAGE_LENGTH, your client must split larger messages or else sending them will not work.
You will want to retain the return value, it will be passed to your read_receipt callback if one is received.
procedure
(send-action tox friendnumber action) → integer?
tox : _Tox-pointer friendnumber : integer? action : bytes?
return the message id if packet was successfully put into the send queue.
return 0 if it was not.
You will want to retain the return value, it will be passed to your read_receipt callback if one is received.
procedure
(group-message-send tox groupnumber message) → boolean?
tox : _Tox-pointer groupnumber : integer? message : bytes?
return #t on success.
return #f on failure.
procedure
(group-action-send tox groupnumber action) → boolean?
tox : _Tox-pointer groupnumber : integer? action : bytes?
return #t on success.
return #f on failure.
procedure
(group-peernumber-is-ours? tox groupnumber peernumber) → boolean? tox : _Tox-pointer groupnumber : integer? peernumber : integer?
returns #t if it does
returns #f if it does not.
struct
(struct Tox-Options ( ipv6-enabled? udp-disabled? proxy-type proxy-address proxy-port) #:extra-constructor-name make-Tox-Options) ipv6-enabled? : boolean? udp-disabled? : boolean? proxy-type : integer? proxy-address : string? proxy-port : integer?
Set udp-disabled? to #t to disable udp support. (default: #f) This will force Tox to use TCP only which may slow things down. Disabling udp support is necessary when using anonymous proxies or Tor.
proxy-type is a value from TOX_PROXY_TYPE enumerator.
proxy-address is the IP or domain of the proxy.
proxy-port is the port of the proxy in host byte order.
procedure
(tox-new opts) → _Tox-pointer
opts : _Tox-Options-pointer
Options are some options that can be passed to the Tox instance (see above struct).
If options is null, tox-new will use default settings.
Initializes a tox structure
return allocated instance of tox on success.
return 0 if there are problems.
Free all datastructures.
procedure
(tox-do tox) → void?
tox : _Tox-pointer
procedure
(tox-do-interval tox) → integer?
tox : _Tox-pointer
3.3 Saving and Loading Functions
procedure
(tox-size tox) → integer?
tox : _Tox-pointer
procedure
(tox-save tox) → bytes?
tox : _Tox-pointer
returns #t on success
returns #f on failure
3.4 Friend and Group Manipulation
procedure
(add-friend tox address message [ message-length]) → integer? tox : _Tox-pointer address : bytes? message : string? message-length : integer? = (bytes-length message)
Set the message that will be sent along with friend request. Must not be longer than TOX_MAX_FRIENDREQUEST_LENGTH length in bytes.
address is the address of the friend (returned by getaddress of the friend you wish to add) it must be TOX_ADDRESS_SIZE bytes.
message is the friend request message and message-length is the length of the message being sent.
return the friend number if success.
return TOX_FA_TOOLONG if message length is too long.
return TOX_FAERR_NOMESSAGE if no message (message length must be >= 1 byte).
return TOX_FAERR_OWNKEY if our own key.
return TOX_FAERR_ALREADYSENT if friend request already sent or already a friend.
return TOX_FAERR_UNKNOWN for unknown error.
return TOX_FAERR_BADCHECKSUM if bad checksum in address.
return TOX_FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different. (the nospam for that friend was set to a different one).
return TOX_FAERR_NOMEM if increasing the friend list size fails.
procedure
(add-friend-norequest tox public-key) → (or/c integer? boolean?)
tox : _Tox-pointer public-key : bytes?
return the friend number on success.
return #f on failure.
public-key is the bytes form of the Tox ID; e.g. (hex-string->bytes str).
return #t if success.
return #f if failure.
return group number on success.
return #f on failure.
procedure
(del-groupchat! tox groupnumber) → boolean?
tox : _Tox-pointer groupnumber : integer?
return #t on success.
return #f on failure.
procedure
(invite-friend tox friendnumber groupnumber) → boolean?
tox : _Tox-pointer friendnumber : integer? groupnumber : integer?
return #t on success.
return #f on failure.
procedure
(join-groupchat tox friendnumber data len)
→ (or/c integer? boolean?) tox : _Tox-pointer friendnumber : integer? data : bytes? len : integer?
return groupnumber on success.
return #f on failure.
3.5 Filesending Functions
procedure
(new-file-sender tox friendnumber filesize filename [ filename-length]) → (or/c integer? boolean) tox : _Tox-pointer friendnumber : integer? filesize : integer? filename : string?
filename-length : integer? =
(bytes-length (string->bytes/utf-8 filename))
Maximum filename length is 255 bytes.
return file number on success
return #f on failure
procedure
(send-file-control tox friendnumber receiving? filenumber message-id data len) → boolean? tox : _Tox-pointer friendnumber : integer? receiving? : boolean? filenumber : integer? message-id : integer? data : bytes? len : integer?
return #t on success
return #f on failure
procedure
(send-file-data tox friendnumber filenumber data len) → boolean? tox : _Tox-pointer friendnumber : integer? filenumber : integer? data : bytes? len : integer?
return #t on success
return #f on failure
If this function returns #f, you must tox-do, sleep tox-do-interval miliseconds, then attempt to send the data again.
procedure
(file-data-size tox friendnumber) → (or/c integer? boolean?)
tox : _Tox-pointer friendnumber : integer?
return size on success
return #f on failure (currently will never return #f)
procedure
(file-data-remaining tox friendnumber filenumber receiving?) → (or/c integer? boolean?) tox : _Tox-pointer friendnumber : integer? filenumber : integer? receiving? : boolean?
return number of bytes remaining to be sent/received on success
return #f on failure
3.6 Avatar Handling and Manipulation
procedure
(set-avatar! tox format data [len]) → boolean?
tox : _Tox-pointer format : integer? data : bytes? len : integer? = (bytes-length data)
This should be made before connecting, so we will not announce that the user have no avatar before setting and announcing a new one, forcing the peers to re-download it.
Notice that the library treats the image as raw data and does not interpret it by any way.
Arguments:
format - Avatar image format or NONE for user with no avatar (see TOX_AVATAR_FORMAT);
data - bytes containing the avatar data (may be NULL it the format is NONE);
len - length of image data. Must be <= TOX_AVATAR_MAX_DATA_LENGTH.
returns #t on success
returns #f on failure.
procedure
(unset-avatar! tox) → integer?
tox : _Tox-pointer
returns 0 on success (currently always returns 0).
returns a list containing the image hash and the image data.
returns #f on failure.
This function may be used by clients for any purpose, but is provided primarily for validating cached avatars.
This function is a wrapper to internal message-digest functions.
returns hash (in bytes) on success
returns #f on failure.
procedure
(request-avatar-info tox friendnumber) → boolean?
tox : _Tox-pointer friendnumber : integer?
Asks a friend to provide their avatar information (image format and hash). The friend may or may not answer this request and, if answered, the information will be provided through the callback ’avatar_info’.
returns #t on success
returns #f on failure.
Sends our avatar format and hash to a friend; he/she can use this information to validate an avatar from the cache and may (or not) reply with an avatar data request.
Notice: it is NOT necessary to send this notification after changing the avatar or connecting. The library already does this.
returns #t on success
returns #f on failure.
procedure
(request-avatar-data tox friendnumber) → boolean?
tox : _Tox-pointer friendnumber : integer?
Ask a friend to send their avatar data. The friend may or may not answer this request and, if answered, the information will be provided in callback ’avatar_data’.
returns #t on sucess
returns #f on failure.
3.7 Callbacks
3.7.1 General Callbacks
procedure
(callback-friend-request tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox public-key data len userdata)
procedure
(callback-friend-message tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber message len userdata).
procedure
(callback-friend-action tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber action len userdata)
procedure
(callback-name-change tox anonproc [userdata]) → void?
tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber newname len userdata)
procedure
(callback-status-message tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendstatus newstatus len userdata)
procedure
(callback-user-status tox anonproc [userdata]) → void?
tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber TOX_USERSTATUS userdata)
procedure
(callback-typing-change tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : prodecure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber typing? userdata) where typing? is a boolean value.
procedure
(callback-read-receipt tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber status userdata).
If you are keeping a record of returns from m_sendmessage; receipt might be one of those values, meaning the message has been received on the other side.
Since core doesn’t track ids for you, receipt may not correspond to any message. In that case, you should discard it.
procedure
(callback-connection-status tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber status userdata) where status is a string.
Status:
0 – friend went offline after being previously online
1 – friend went online
NOTE: This callback is not called when adding friends, thus the "after being previously online" part. it’s assumed that when adding friends, their connection status is offline.
3.7.2 File Sending Callbacks
procedure
(callback-file-send-request tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber filenumber filesize filename filename-length userdata) where filename is a string.
procedure
(callback-file-control tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber sending? filenumber control-type data len userdata) where control-type is a TOX_FILECONTROL enum value.
procedure
(callback-file-data tox anonproc [userdata?]) → void?
tox : _Tox-pointer anonproc : procedure? userdata? : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber filenumber data len userdata)
data is a byte string of length len.
3.7.3 Groupchat Callbacks
WARNING: Groupchats will be rewritten so these might change
procedure
(callback-group-invite tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox friendnumber type data len userdata)
procedure
(callback-group-message tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox groupnumber peernumber message len userdata)
procedure
(callback-group-action tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox groupnumber peernumber action len userdata)
procedure
(callback-group-title tox anonproc [userdata]) → void?
tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
anonproc is in the form (anonproc tox groupnumber peernumber title len userdata) where title is a byte string.
procedure
(callback-group-namelist-change tox anonproc [ userdata]) → void? tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
It gets called every time the name list changes (new peer/name, deleted peer)
anonproc is in the form (anonproc tox groupnumber peernumber change userdata)
change is a TOX_CHAT_CHANGE enum value.
3.7.4 Avatar Callbacks
Avatars must be in PNG format.
procedure
(callback-avatar-info tox anonproc [userdata]) → void?
tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
This callback will be called when avatar information are received from friends. These events can arrive at anytime, but are usually received upon connection and in reply of avatar information requests.
anonproc is in the form (anonproc tox friendnumber format hash userdata) where ’format’ is the avatar image format (see TOX_AVATAR_FORMAT) and ’hash’ is the hash of the avatar data (in a byte-string) for caching purposes and it is exactly TOX_HASH_LENGTH long. If the image format is NONE, the hash is zeroed.
procedure
(callback-avatar-data tox anonproc [userdata]) → void?
tox : _Tox-pointer anonproc : procedure? userdata : cpointer? = #f
This callback will be called when the complete avatar data was correctly received from a friend. This only happens in reply of an avatar data request (see request-avatar-data);
anonproc is in the form (anonproc tox friendnumber img-format img-hash data-ptr datalen userdata) where img-format is the avatar image format (see TOX_AVATAR_FORMAT); img-hash is the locally-calculated cryptographic hash of the avatar data (in a byte-string) and it is exactly TOX_HASH_LENGTH long; data-ptr is the avatar image data (as a pointer) and datalen is the length of such data.
If format is 'NONE, data-ptr is #f, datalen is zero, and the hash is zeroed. The hash is always validated locally with the function tox-hash and ensured to match the image data, so this value can be safely used to compare with cached avatars.
WARNING: users MUST treat all avatar image data received from another peer as untrusted and potentially malicious. The library only ensures that the data which arrived is the same the other user sent, and does not interpret or validate any image data.
4 Audio/Video
(require libtoxcore-racket/av) | |
package: libtoxcore-racket |
The functions in libtoxcore-racket/av pertain to Audio/Video interaction.
4.1 Structs
struct
(struct _ToxAvCSettings ( call_type video_bitrate video_width video_height audio_bitrate audio_frame_duration audio_sample_rate audio_channels) #:extra-constructor-name make-_ToxAvCSettings) call_type : integer? video_bitrate : integer? video_width : integer? video_height : integer? audio_bitrate : integer? audio_frame_duration : integer? audio_sample_rate : integer? audio_channels : integer?
video_bitrate is in kbit/s
video_width is in px
video_height is in px
audio_bitrate is in bits/s
audio_frame_duration is in ms
audio_sample_rate is in Hz
4.2 Procedures
procedure
(ToxAVCallback agent call-index arg) → void?
agent : cpointer? call-index : integer? arg : cpointer?
procedure
(ToxAvAudioCallback agent call-index pcm size data) → void? agent : cpointer? call-index : integer? pcm : bytes? size : integer? data : cpointer?
procedure
(ToxAvVideoCallback agent call-index img data) → void? agent : cpointer? call-index : integer? img : bytes? data : cpointer?
procedure
(av-new messenger max_calls) → _ToxAv-pointer
messenger : _Tox-pointer max_calls : integer?
return _ToxAv-pointer
return NULL On error.
return void
procedure
(toxav-do-interval av) → integer?
av : _ToxAv-pointer
procedure
(callback-callstate av callback id [userdata]) → void?
av : _ToxAv-pointer callback : procedure? id : integer? userdata : cpointer? = #f
callback is the ToxAvCallback procedure.
id is one of the ToxAvCallbackID values
return void
procedure
(callback-audio-recv av callback [userdata]) → void?
av : _ToxAv-pointer callback : procedure? userdata : cpointer? = #f
callback is in the ToxAvAudioCallback procedure.
return void
procedure
(callback-video-recv av callback) → void?
av : Tox-Av-pointer callback : procedure?
callback is in the ToxAvAudioCallback procedure.
return void
procedure
(av-call av call-index friend-id csettings ringing-seconds) → integer? av : _ToxAv-pointer call-index : bytes? friend-id : integer? csettings : cpointer? ringing-seconds : integer?
procedure
av : _ToxAv-pointer call-index : integer?
return #t on success.
return _ToxAvError on error.
procedure
(av-answer av call-index csettings) → (or/c boolean? integer?)
av : _ToxAv-pointer call-index : integer? csettings : cpointer?
return #t on success.
return _ToxAvError On error.
Optional reason. Set NULL if none.
return #t on success.
return _ToxAvError on error.
procedure
(av-change-settings av call-index csettings) → integer?
av : _ToxAv-pointer call-index : integer? csettings : cpointer?
return 0 on success
return _ToxAvError
Optional reason.
return 0 on success.
return _ToxAvError on error.
procedure
(av-stop-call av call-index) → integer?
av : _ToxAv-pointer call-index : integer?
return 0 on success.
return _ToxAvError on error.
procedure
(prepare-transmission av call-index support-video?) → integer? av : _ToxAv-pointer call-index : integer? support-video? : boolean?
Also, it must be called when call is started
procedure
(kill-transmission av call-index) → integer?
av : _ToxAv-pointer call-index : integer?
return 0 on success.
return _ToxAvError on error.
procedure
(prepare-video-frame av call-index dest dest-max input) → integer? av : _ToxAv-pointer call-index : integer? dest : cpointer? dest-max : integer? input : bytes?
procedure
(send-video av call-index frame frame-size) → integer?
av : _ToxAv-pointer call-index : integer? frame : cpointer? frame-size : integer?
return 0 on success.
return _ToxAvError on error.
procedure
(prepare-audio-frame av call-index dest dest-max frame frame-size) → integer? av : _ToxAv-pointer call-index : integer? dest : cpointer? dest-max : integer? frame : cpointer? frame-size : integer?
return >0 on success.
return _ToxAvError on error.
procedure
(send-audio av call-index frame frame-size) → integer?
av : _ToxAv-pointer call-index : inteder? frame : bytes? frame-size : integer?
frame is the frame (raw 16 bit signed pcm with AUDIO_CHANNELS channels audio.)
frame-size is its size in number of frames/samples (one frame/sample is 16 bits or 2 bytes). frame-size should be AUDIO_FRAME_SIZE.
return 0 on success.
return _ToxAvError on error.
procedure
(get-peer-csettings av call-index peer) → list?
av : _ToxAv-pointer call-index : integer? peer : integer?
return a list containing _ToxAvCallType and a csettings cpointer on success.
return a list containing _ToxAvError on error.
procedure
(get-peer-id av call-index peer) → integer?
av : _ToxAv-pointer call-index : integer? peer : integer?
return _ToxAvError when there is no peer id
procedure
(get-call-state av call-index) → integer?
av : _ToxAv-pointer call-index : integer?
returns integer from _ToxAvCallState.
procedure
(capability-supported? av call-index capability) → boolean? av : _ToxAv-pointer call-index : integer? capability : integer?
capability is on of ToxAvCapabilities.
procedure
(av-get-tox av) → _Tox-pointer
av : _ToxAv-pointer
procedure
(get-active-calls av) → integer?
av : _ToxAv-pointer
procedure
(add-av-groupchat tox audio-callback [ userdata]) → integer? tox : _Tox-pointer audio-callback : procedure? userdata : cpointer? = #f
audio-callback is in the form (audio-callback tox groupnumber peernumber pcm samples channels sample-rate userdata) where pcm is a byte string of the size (* samples channels (ctype-sizeof int16_t)).
return groupnumber on success.
return -1 on failure.
procedure
(join-av-groupchat tox friendnumber data data-len audio-callback [ userdata]) → integer? tox : _Tox-pointer friendnumber : integer? data : cpointer? data-len : integer? audio-callback : procedure? userdata : cpointer? = #f
audio-callback is in the form (audio-callback tox groupnumber peernumber pcm samples channels sample-rate userdata) where pcm is of size (* samples channels).
return groupnumber on success.
return -1 on failure.
procedure
(group-send-audio tox groupnumber pcm samples channels sample-rate) → integer? tox : _Tox-pointer groupnumber : integer? pcm : bytes? samples : integer? channels : integer? sample-rate : integer?
Note that pcm is a byte string of the size (* samples channels (ctype-sizeof int16_t)).
Valid number of samples are ((sample rate) * (audio length (Valid ones are: 2.5, 5, 10, 20, 40 or 60 ms)) / 1000)
Valid number of channels are 1 or 2.
Valid sample rates are 8000, 12000, 16000, 24000, or 48000.
Recommended values are: samples = 960, channels = 1, sample_rate = 48000
return 0 on success
return -1 on failure.
5 Licensing
5.1 Library License
Copyright (C) 2014 Lehi Toskin.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License and GNU Lesser General Public License for more details.
5.2 Documentation License
Copyright (C) 2014 Lehi Toskin.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".