2.2Enums
4.1Structs
9.0
top
← prev up next →

libtoxcore-racketπŸ”— i

Lehi Toskin

This library provides a Racket-like interface to the libtoxcore, libtoxav, and libtoxdns libraries. Be aware that Tox is currently thread-unsafe, so please take all proper precautions while using the library.

1ExamplesπŸ”— i

;simple1-to-1functionwrapper
(require libtoxcore-racket)
 
(define-values (my-toxnew-err)(tox-new TOX_ENABLE_IPV6_DEFAULT))
(define my-name"Toxizen5k")
(define my-status-message"TestingToxwiththeRacketwrapper!")
 
(set-self-name!my-toxmy-name)
(set-self-status-message!my-status-message)
 
(tox-kill! my-tox)

2Constants and EnumsπŸ”— i

Tox uses several enums and many different constants. It is important to be familiar with the enums, especially.

2.1ConstantsπŸ”— i

:
(ctype-sizeofuint32_t)(ctype-sizeofuint16_t))

Maximum length a message can be before it must be split.

value

TOX_HASH_LENGTH :32

2.2EnumsπŸ”— i

Tox uses various enumerations in many of its functions and they are explained below.

value

_TOX-USER-STATUS :'(availableawaybusy)

value

_TOX-MESSAGE-TYPE :'(normalaction)

value

_TOX-PROXY-TYPE :'(nonehttpsocks5)

value

_TOX-ERR-OPTIONS-NEW :'(okmalloc)

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)
'malloc is returned when the function was unable to allocate enough memory to store the internal structures for the Tox object.

'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 :'(oknullbad-hostbad-port)

value

_TOX-CONNECTION :'(nonetcpudp)

value

_TOX-ERR-SET-INFO :'(oknulltoo-long)

value

_TOX-ERR-FRIEND-SEND-MESSAGE :
'(ok
null
friend-not-found
friend-not-connected
sendq
too-long
empty)
'sendq is returned when an allocation error occurred while increasing the send queue size

value

_TOX-FILE-KIND :'(dataavatar)

'data is used when sending arbitrary file data. Clients can choose to handle it based on the file name or magic or any other way.

'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 :'(resumepausecancel)

'resume is used when accepting a file transfer or when resuming a paused transfer.

'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)
'not-found is returned when ; no file transfer with the given file number was found for the given friend.

'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)
'transfer-not-found is returned when no transfer with the given file number was found for the given friend.

'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 :'(okfriend-not-foundtransfer-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 :'(oknullfailed)

value

_TOX-ERR-ENCRYPTION :
'(ok
null
key-derivation-failed
encryption-failed)
'null is returned when some input data, or maybe the output pointer, was null.

'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 :'(textav)

value

_TOX-CHAT-CHANGE-PEER :'(adddelname)

'add is for when a new peer has joined the groupchat.

'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)
'Invite is when there has been a call invitation.

'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)
Represents the type of A/V call.

procedure

( _ToxAvCallState sym)(or/c false?integer? )

sym :
(or/c 'CallNonExistant
'CallInviting
'CallStarting
'CallActive
'CallHold
'CallHangedUp)
Represents the state of the current call.

'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)
'NoCall means we are trying to perform a call action while not in a call.

'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)
'AudioEncoding is equivalent to 1 << 0 or (expt 20)

'AudioDecoding is equivalent to 1 << 1 or (expt 21)

'VideoEncoding is equivalent to 1 << 2 or (expt 22)

'VideoDecoding is equivalent to 1 << 3 or (expt 23)

3FunctionsπŸ”— i

The functions in libtoxcore-racket/functions are the base wrappers for the functions found in libtoxcore.

3.1Getters and SettersπŸ”— i

procedure

( friendlist-lengthtox)integer?

tox:_Tox-pointer
Return the number of friends in the instance.

You should use this to determine how much memory to allocate for copy_friendlist.

procedure

( friend-exists? toxfriendnumber)boolean?

tox:_Tox-pointer
friendnumber:integer?
Checks if there exists a friend with given friendnumber.

return #t if friend exists.

return #f if friend doesn’t exist.

procedure

( get-self-addresstoxaddress)void?

tox:_Tox-pointer
address:bytes?
format: [public-key (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]

Return an address to give to others. (Must be transformed into hex format for ordinary usage).

procedure

( get-client-idtoxfriendnumber)integer?

tox:_Tox-pointer
friendnumber:integer?
Returns the public key associated to that friend id.

return public key if success.

return #f if failure.

procedure

( get-friend-connection-status tox
friendnumber)integer?
tox:_Tox-pointer
friendnumber:integer?
Checks friend’s connecting status.

return 1 if friend is connected to us (Online).

return 0 if friend is not connected to us (Offline).

return -1 on failure.

procedure

( get-friendlisttoxlist-size)(or/c integer? bytes? )

tox:_Tox-pointer
list-size:integer?
Copy a list of valid friend IDs into the array out-list.

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-numbertoxpublic-key)(or/c integer? boolean? )

tox:_Tox-pointer
public-key:bytes?
return the friend number associated to that public key.

return #f if no such friend

procedure

( is-typing?toxfriendnumber)boolean?

tox:_Tox-pointer
friendnumber:integer?
Get the typing status of a friend.

returns #t if friend is typing.

returns #f if friend is not typing.

procedure

( get-last-onlinetoxfriendnumber)(or/c integer? boolean? )

tox:_Tox-pointer
friendnumber:integer?
returns timestamp of last time friendnumber was seen online, or 0 if never seen.

returns #f on error.

procedure

( get-nametoxfriendnumber)(or/c boolean? bytes? )

tox:_Tox-pointer
friendnumber:integer?
return name (in bytes) if success.

return #f if failure.

procedure

( get-name-sizetoxfriendnumber)(or/c integer? boolean? )

tox:_Tox-pointer
friendnumber:integer?
returns the length of name on success.

returns #f on failure.

procedure

( get-num-online-friendstox)integer?

tox:_Tox-pointer
Return the number of online friends in the instance m.

procedure

( get-self-nametox)(or/c integer? bytes? )

tox:_Tox-pointer
return name (in bytes) on success

return 0 on error.

procedure

( get-self-name-sizetox)(or/c boolean? bytes? )

tox:_Tox-pointer
The self variant returns the length of our name on success

return #f on failure.

procedure

( get-self-status-messagetox)(or/c boolean? bytes? )

tox:_Tox-pointer
Like get-status-message, the self variant returns our status message.

procedure

( get-self-status-message-sizetox)(or/c integer? boolean? )

tox:_Tox-pointer
Like get-status-message-size, the self variant returns the length of our status message on success

return #f on failure.

procedure

( get-user-statustoxfriendnumber)integer?

tox:_Tox-pointer
friendnumber:integer?
return one of TOX_USERSTATUS values.

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-statustox)integer?

tox:_Tox-pointer
Like get-user-status, the self variant will return our own TOX_USERSTATUS.

procedure

( get-status-messagetoxfriendnumber)(or/c boolean? bytes? )

tox:_Tox-pointer
friendnumber:integer?
Return friendnumber’s status message.

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-sizetoxfriendnumber)integer?

tox:_Tox-pointer
friendnumber:integer?
returns the length of status message on success.

returns #f on failure.

procedure

( set-nametoxname)boolean?

tox:_Tox-pointer
name:string?
Set our nickname.

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!toxstatus[len])boolean?

tox:_Tox-pointer
status:string?
Set our status message.

max length of the status is TOX_MAX_STATUSMESSAGE_LENGTH.

returns #t on success.

returns #f on failure.

procedure

( set-user-status!toxuserstatus)boolean?

tox:_Tox-pointer
userstatus:integer?
Set our user status.

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?
Set our typing status for a friend.

You are responsible for turning it on or off.

returns #t on success.

returns #f on failure.

procedure

( get-group-number-peerstoxgroupnumber)

tox:_Tox-pointer
groupnumber:integer?
Return the number of peers in the group chat on success.

return #f on failure

procedure

( get-group-namestoxgroupnumberlen)(or/c boolean? list? )

tox:_Tox-pointer
groupnumber:integer?
len:integer?
List all the peers in the group chat.

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 the name of peernumber who is in groupnumber.

return #f on failure

procedure

( get-group-peer-pubkey tox
groupnumber
peernumber)(or/c integer? bytes? )
tox:_Tox-pointer
groupnumber:integer?
peernumber:integer?
Return the public key (in bytes) of peernumber who is in groupnumber.

procedure

( count-chatlist tox)integer?

tox:_Tox-pointer
Return the number of group chats in the instance tox.

You should use this to determine how much memory to allocate for copy_chatlist.

procedure

( get-chatlisttoxlist-size)(or/c integer? list? )

tox:_Tox-pointer
list-size:integer?
Returns a list of valid chat ID’s.

If list-size was too small, the contents of the return value will be truncated to list-size.

return 0 on failure.

procedure

( get-nospamtox)integer?

tox:_Tox-pointer
Procedure to get the nospam part of the ID.

procedure

( set-nospam!toxnospam)void?

tox:_Tox-pointer
nospam:integer?
Procedure to set the nospam part of the ID.

procedure

( get-keystoxsecret-keypublic-key)void?

tox:_Tox-pointer
secret-key:bytes?
public-key:bytes?
Copy the public and secret key from the Tox object.

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!toxgroupnumbertitle)boolean?

tox:_Tox-pointer
groupnumber:integer?
title:bytes?
Set the group’s title, limited to TOX_MAX_NAME_LENGTH .

return #t on success

return #f on failure.

procedure

( group-get-titletoxgroupnumber)(or/c boolean? bytes? )

tox:_Tox-pointer
groupnumber:integer?
Get group’s title from groupnumber.

Return title (in bytes) on success.

return #f on failure.

3.2Interact with ToxπŸ”— i

procedure

( bootstrap-from-address tox
address
port
public-key)boolean?
tox:_Tox-pointer
address:string?
port:integer?
public-key:string?
Resolves address into an IP address. If successful, sends a "get nodes" request to the given node with ip, port (in host byte order) and public_key to setup connections

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 #f if we are not connected to the DHT.

return #t if we are.

procedure

( send-messagetoxfriendnumbermessage)integer?

tox:_Tox-pointer
friendnumber:integer?
message:bytes?
Send a text chat message to an online friend.

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-actiontoxfriendnumberaction)integer?

tox:_Tox-pointer
friendnumber:integer?
action:bytes?
Send an action to an online friend.

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 toxgroupnumbermessage)boolean?

tox:_Tox-pointer
groupnumber:integer?
message:bytes?
Send a group message.

return #t on success.

return #f on failure.

procedure

( group-action-send toxgroupnumberaction)boolean?

tox:_Tox-pointer
groupnumber:integer?
action:bytes?
Send a group action.

return #t on success.

return #f on failure.

procedure

( group-peernumber-is-ours? tox
groupnumber
peernumber)boolean?
tox:_Tox-pointer
groupnumber:integer?
peernumber:integer?
Check if the current peernumber corresponds to ours.

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-namemake-Tox-Options )
ipv6-enabled?:boolean?
udp-disabled?:boolean?
proxy-type:integer?
proxy-address:string?
proxy-port:integer?
The type of UDP socket created depends on ipv6-enabled?: If set to #f, creates an IPv4 socket which subsequently only allows IPv4 communication. If set to #t (default), creates an IPv6 socket which allows both IPv4 AND IPv6 communication.

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
Run this function at startup.

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.

procedure

( tox-kill! tox)void?

tox:_Tox-pointer
Run this before closing shop.

Free all datastructures.

procedure

( tox-dotox)void?

tox:_Tox-pointer
The main loop that needs to be run in intervals of tox-do-interval ms.

procedure

( tox-do-intervaltox)integer?

tox:_Tox-pointer
Return the time in milliseconds before tox-do should be called again for optimal performance.

3.3Saving and Loading FunctionsπŸ”— i

procedure

( tox-sizetox)integer?

tox:_Tox-pointer
return size of messenger data (for saving).

procedure

( tox-savetox)bytes?

tox:_Tox-pointer
Return a byte string containing the saved Tox data.

procedure

( tox-loadtoxdata)boolean?

tox:_Tox-pointer
data:bytes?
Load the messenger from data of size length.

returns #t on success

returns #f on failure

3.4Friend and Group ManipulationπŸ”— i

procedure

( add-friend tox
address
message
[ message-length])integer?
tox:_Tox-pointer
address:bytes?
message:string?
message-length:integer? =(bytes-length message)
Add a friend.

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-norequesttoxpublic-key)(or/c integer? boolean? )

tox:_Tox-pointer
public-key:bytes?
Add a friend without sending a friendrequest.

return the friend number on success.

return #f on failure.

public-key is the bytes form of the Tox ID; e.g. (hex-string->bytesstr).

procedure

( del-friend!toxfriendnumber)integer?

tox:_Tox-pointer
friendnumber:integer?
Remove a friend.

return #t if success.

return #f if failure.

procedure

( add-groupchattox)(or/c integer? boolean? )

tox:_Tox-pointer
Creates a new groupchat and puts it in the chats array.

return group number on success.

return #f on failure.

procedure

( del-groupchat! toxgroupnumber)boolean?

tox:_Tox-pointer
groupnumber:integer?
Delete a groupchat.

return #t on success.

return #f on failure.

procedure

( invite-friend toxfriendnumbergroupnumber)boolean?

tox:_Tox-pointer
friendnumber:integer?
groupnumber:integer?
Invite friendnumber to groupnumber.

return #t on success.

return #f on failure.

procedure

( join-groupchat toxfriendnumberdatalen)

tox:_Tox-pointer
friendnumber:integer?
data:bytes?
len:integer?
Join a group (you need to have been invited first.)

return groupnumber on success.

return #f on failure.

3.5Filesending FunctionsπŸ”— i

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? =
(string->bytes/utf-8 filename))
Send a file send request.

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?
Send a file control request.

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?
Send file data.

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-sizetoxfriendnumber)(or/c integer? boolean? )

tox:_Tox-pointer
friendnumber:integer?
Returns the recommended/maximum size of the filedata you send with send-file-data

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?
Give the number of bytes left to be sent/received.

return number of bytes remaining to be sent/received on success

return #f on failure

3.6Avatar Handling and ManipulationπŸ”— i

procedure

( set-avatar!toxformatdata[len])boolean?

tox:_Tox-pointer
format:integer?
data:bytes?
len:integer? =(bytes-length data)
Set the user avatar image 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
Unsets the user avatar.

returns 0 on success (currently always returns 0).

procedure

( get-self-avatartoxformatlen)(or/c boolean? list? )

tox:_Tox-pointer
format:integer?
len:integer?
Get avatar data from the current user.

returns a list containing the image hash and the image data.

returns #f on failure.

procedure

( tox-hash data)(or/c boolean? bytes? )

data:bytes?
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 function is a wrapper to internal message-digest functions.

returns hash (in bytes) on success

returns #f on failure.

procedure

( request-avatar-infotoxfriendnumber)boolean?

tox:_Tox-pointer
friendnumber:integer?
Request avatar information from a friend.

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.

procedure

( send-avatar-infotoxfriendnumber)boolean?

tox:_Tox-pointer
friendnumber:integer?
Send an unrequested avatar information to a friend.

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-datatoxfriendnumber)boolean?

tox:_Tox-pointer
friendnumber:integer?
Request the avatar data from a friend.

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.7CallbacksπŸ”— i

3.7.1General CallbacksπŸ”— i

procedure

anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the function that will be executed when a friend request is received.

anonproc is in the form (anonproctoxpublic-keydatalenuserdata)

procedure

anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the function that will be executed when a message from a friend is received.

anonproc is in the form (anonproctoxfriendnumbermessagelenuserdata).

procedure

( callback-friend-action tox
anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the function that will be executed when an action from a friend is received.

anonproc is in the form (anonproctoxfriendnumberactionlenuserdata)

procedure

( callback-name-changetoxanonproc[userdata])void?

tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for name changes.

anonproc is in the form (anonproctoxfriendnumbernewnamelenuserdata)

procedure

( callback-status-message tox
anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for status message changes.

anonproc is in the form (anonproctoxfriendstatusnewstatuslenuserdata)

procedure

( callback-user-statustoxanonproc[userdata])void?

tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for status type changes.

anonproc is in the form (anonproctoxfriendnumberTOX_USERSTATUSuserdata)

procedure

( callback-typing-change tox
anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:prodecure?
userdata:cpointer?=#f
Set the callback for typing changes.

anonproc is in the form (anonproctoxfriendnumbertyping?userdata) where typing? is a boolean value.

procedure

( callback-read-receipt tox
anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for read receipts.

anonproc is in the form (anonproctoxfriendnumberstatususerdata).

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
This function is kind of tricky because the C library requires a function as a parameter (anonproc). This wrapper procedure is kind of tricky and shouldn’t be considered complete.

anonproc is in the form (anonproctoxfriendnumberstatususerdata) 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.2File Sending CallbacksπŸ”— i

procedure

( callback-file-send-request tox
anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for file send requests.

anonproc is in the form (anonproctoxfriendnumberfilenumberfilesizefilenamefilename-lengthuserdata) where filename is a string.

procedure

( callback-file-control tox
anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for file control requests.

anonproc is in the form (anonproctoxfriendnumbersending?filenumbercontrol-typedatalenuserdata) where control-type is a TOX_FILECONTROL enum value.

procedure

( callback-file-datatoxanonproc[userdata?])void?

tox:_Tox-pointer
anonproc:procedure?
userdata?:cpointer?=#f
Set the callback for file data.

anonproc is in the form (anonproctoxfriendnumberfilenumberdatalenuserdata)

data is a byte string of length len.

3.7.3Groupchat CallbacksπŸ”— i

WARNING: Groupchats will be rewritten so these might change

procedure

anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for group invites.

anonproc is in the form (anonproctoxfriendnumbertypedatalenuserdata)

procedure

anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for group messages.

anonproc is in the form (anonproctoxgroupnumberpeernumbermessagelenuserdata)

procedure

anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback for group actions.

anonproc is in the form (anonproctoxgroupnumberpeernumberactionlenuserdata)

procedure

( callback-group-title toxanonproc[userdata])void?

tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set callback function for groupchat title changes.

anonproc is in the form (anonproctoxgroupnumberpeernumbertitlelenuserdata) where title is a byte string.

procedure

anonproc
[ userdata])void?
tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set callback function for peer name list changes.

It gets called every time the name list changes (new peer/name, deleted peer)

anonproc is in the form (anonproctoxgroupnumberpeernumberchangeuserdata)

change is a TOX_CHAT_CHANGE enum value.

3.7.4Avatar CallbacksπŸ”— i

Avatars must be in PNG format.

procedure

( callback-avatar-infotoxanonproc[userdata])void?

tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback function for avatar information.

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 (anonproctoxfriendnumberformat 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-datatoxanonproc[userdata])void?

tox:_Tox-pointer
anonproc:procedure?
userdata:cpointer?=#f
Set the callback function for avatar data.

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 (anonproctoxfriendnumberimg-formatimg-hashdata-ptrdatalenuserdata) 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.

4Audio/VideoπŸ”— i

The functions in libtoxcore-racket/av pertain to Audio/Video interaction.

4.1StructsπŸ”— i

struct

(struct _ToxAvCSettings ( call_type
video_bitrate
video_width
video_height
audio_bitrate
audio_frame_duration
audio_sample_rate
audio_channels)
#:extra-constructor-namemake-_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?
call_type is a _ToxAvCallType enum value.

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.2ProceduresπŸ”— i

procedure

( ToxAVCallback agentcall-indexarg)void?

agent:cpointer?
call-index:integer?
arg:cpointer?
Commonly reused callback form.

procedure

call-index
pcm
size
data)void?
agent:cpointer?
call-index:integer?
pcm:bytes?
size:integer?
data:cpointer?
Commonly reused audio callback form.

procedure

call-index
img
data)void?
agent:cpointer?
call-index:integer?
img:bytes?
data:cpointer?
Commonly reused video callback form.

procedure

( av-new messengermax_calls)_ToxAv-pointer

messenger:_Tox-pointer
max_calls:integer?
Start new A/V session. There can only be one session at the time. If you register more it will result in undefined behaviour.

return _ToxAv-pointer

return NULL On error.

procedure

( av-kill! av)void?

av:_ToxAv-pointer
Remove A/V session.

return void

procedure

( toxav-do-interval av)integer?

av:_ToxAv-pointer
Returns the amount of time you should sleep before running tox-do again. If there is no call at the moment, it returns 200.

procedure

( toxav-do av)void?

av:_ToxAv-pointer
Main loop for the session. Best called right after tox-do.

procedure

( callback-callstate avcallbackid[userdata])void?

av:_ToxAv-pointer
callback:procedure?
userdata:cpointer?=#f
Register callback for call state.

callback is the ToxAvCallback procedure.

id is one of the ToxAvCallbackID values

return void

procedure

( callback-audio-recv avcallback[userdata])void?

av:_ToxAv-pointer
callback:procedure?
userdata:cpointer?=#f
Register callback for receiving audio data.

callback is in the ToxAvAudioCallback procedure.

return void

procedure

( callback-video-recv avcallback)void?

av:Tox-Av-pointer
callback:procedure?
Register callback for receiving video data.

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?
Call user. Use its friend-id.

procedure

( av-hangup avcall-index)(or/c boolean? integer? )

av:_ToxAv-pointer
call-index:integer?
Hangup active call.

return #t on success.

return _ToxAvError on error.

procedure

( av-answer avcall-indexcsettings)(or/c boolean? integer? )

av:_ToxAv-pointer
call-index:integer?
csettings:cpointer?
Answer incoming call.

return #t on success.

return _ToxAvError On error.

procedure

( av-reject avcall-indexreason)(or/c boolean? integer? )

av:_ToxAv-pointer
call-index:integer?
reason:string?
Reject incoming call.

Optional reason. Set NULL if none.

return #t on success.

return _ToxAvError on error.

procedure

( av-change-settings avcall-indexcsettings)integer?

av:_ToxAv-pointer
call-index:integer?
csettings:cpointer?
Notify peer that we are changing call settings.

return 0 on success

return _ToxAvError

procedure

( av-cancel avcall-indexpeer-idreason)integer?

av:_ToxAv-pointer
call-index:integer?
peer-id:integer?
reason:string?
Cancel outgoing request.

Optional reason.

return 0 on success.

return _ToxAvError on error.

procedure

( av-stop-call avcall-index)integer?

av:_ToxAv-pointer
call-index:integer?
Terminate transmission. Note that transmission will be terminated without informing remote peer.

return 0 on success.

return _ToxAvError on error.

procedure

call-index
support-video?)integer?
av:_ToxAv-pointer
call-index:integer?
support-video?:boolean?
Allocates transmission data. Must be called before calling toxav_prepare_* and toxav_send_*.

Also, it must be called when call is started

procedure

( kill-transmission avcall-index)integer?

av:_ToxAv-pointer
call-index:integer?
Call this at the end of the transmission.

return 0 on success.

return _ToxAvError on error.

procedure

call-index
dest
dest-max
input)integer?
av:_ToxAv-pointer
call-index:integer?
dest:cpointer?
dest-max:integer?
input:bytes?
Encode video frame.

procedure

( send-video avcall-indexframeframe-size)integer?

av:_ToxAv-pointer
call-index:integer?
frame:cpointer?
frame-size:integer?
Encode and send video packet.

return 0 on success.

return _ToxAvError on error.

procedure

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?
Encode audio frame.

return >0 on success.

return _ToxAvError on error.

procedure

( send-audio avcall-indexframeframe-size)integer?

av:_ToxAv-pointer
call-index:inteder?
frame:bytes?
frame-size:integer?
Send audio frame.

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 avcall-indexpeer)list?

av:_ToxAv-pointer
call-index:integer?
peer:integer?
Get peer transmission type. It can either be audio or video.

return a list containing _ToxAvCallType and a csettings cpointer on success.

return a list containing _ToxAvError on error.

procedure

( get-peer-id avcall-indexpeer)integer?

av:_ToxAv-pointer
call-index:integer?
peer:integer?
Get id of peer participating in conversation

return _ToxAvError when there is no peer id

procedure

( get-call-state avcall-index)integer?

av:_ToxAv-pointer
call-index:integer?
Get current call state.

returns integer from _ToxAvCallState .

procedure

call-index
capability)boolean?
av:_ToxAv-pointer
call-index:integer?
capability:integer?
Is a certain capability supported?

capability is on of ToxAvCapabilities.

procedure

( av-get-tox av)_Tox-pointer

av:_ToxAv-pointer
Return the _Tox-pointer being used with the _ToxAv-pointer.

procedure

( get-active-calls av)integer?

av:_ToxAv-pointer
Returns number of active calls or -1 on error.

procedure

audio-callback
[ userdata])integer?
tox:_Tox-pointer
audio-callback:procedure?
userdata:cpointer?=#f
Create a new ToxAV group.

audio-callback is in the form (audio-callbacktoxgroupnumberpeernumberpcmsampleschannelssample-rateuserdata) where pcm is a byte string of the size (* sampleschannels(ctype-sizeofint16_t)).

return groupnumber on success.

return -1 on failure.

procedure

friendnumber
data
data-len
audio-callback
[ userdata])integer?
tox:_Tox-pointer
friendnumber:integer?
data:cpointer?
data-len:integer?
audio-callback:procedure?
userdata:cpointer?=#f
Join AV group (you need to have been invited first).

audio-callback is in the form (audio-callbacktoxgroupnumberpeernumberpcmsampleschannelssample-rateuserdata) where pcm is of size (* sampleschannels).

return groupnumber on success.

return -1 on failure.

procedure

groupnumber
pcm
samples
channels
sample-rate)integer?
tox:_Tox-pointer
groupnumber:integer?
pcm:bytes?
samples:integer?
channels:integer?
sample-rate:integer?
Send audio to the groupchat.

Note that pcm is a byte string of the size (* sampleschannels(ctype-sizeofint16_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.

5LicensingπŸ”— i

5.1Library LicenseπŸ”— i

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.2Documentation LicenseπŸ”— i

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".

IndexπŸ”— i

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

_TOX-CHAT-CHANGE-PEER
_TOX-CONNECTION
_TOX-ERR-BOOTSTRAP
_TOX-ERR-DECRYPTION
_TOX-ERR-ENCRYPTION
_TOX-ERR-FILE-CONTROL
_TOX-ERR-FILE-GET
_TOX-ERR-FILE-SEEK
_TOX-ERR-FILE-SEND
_TOX-ERR-FILE-SEND-CHUNK
_TOX-ERR-FRIEND-CUSTOM-PACKET
_TOX-ERR-FRIEND-SEND-MESSAGE
_TOX-ERR-KEY-DERIVATION
_TOX-ERR-NEW
_TOX-ERR-OPTIONS-NEW
_TOX-ERR-SET-INFO
_TOX-FILE-CONTROL
_TOX-FILE-KIND
_TOX-GROUPCHAT-TYPE
_TOX-MESSAGE-TYPE
_TOX-PROXY-TYPE
_TOX-USER-STATUS
_ToxAvCallbackID
_ToxAvCallState
_ToxAvCallType
_ToxAvCapabilities
_ToxAvCSettings (struct)
_ToxAvCSettings-audio_bitrate
_ToxAvCSettings-audio_channels
_ToxAvCSettings-audio_frame_duration
_ToxAvCSettings-audio_sample_rate
_ToxAvCSettings-call_type
_ToxAvCSettings-video_bitrate
_ToxAvCSettings-video_height
_ToxAvCSettings-video_width
_ToxAvCSettings?
_ToxAvError
add-av-groupchat
add-friend
add-friend-norequest
add-groupchat
Audio/Video
av-answer
av-call
av-cancel
av-change-settings
av-get-tox
av-hangup
av-kill!
av-new
av-reject
av-stop-call
Avatar Callbacks
Avatar Handling and Manipulation
bootstrap-from-address
callback-audio-recv
callback-avatar-data
callback-avatar-info
callback-callstate
callback-connection-status
callback-file-control
callback-file-data
callback-file-send-request
callback-friend-action
callback-friend-message
callback-friend-request
callback-group-action
callback-group-invite
callback-group-message
callback-group-namelist-change
callback-group-title
callback-name-change
callback-read-receipt
callback-status-message
callback-typing-change
callback-user-status
callback-video-recv
Callbacks
capability-supported?
Constants
Constants and Enums
count-chatlist
del-friend!
del-groupchat!
Documentation License
Enums
Examples
File Sending Callbacks
file-data-remaining
file-data-size
Filesending Functions
Friend and Group Manipulation
friend-exists?
friendlist-length
Functions
General Callbacks
get-active-calls
get-call-state
get-chatlist
get-client-id
get-friend-connection-status
get-friend-number
get-friendlist
get-group-names
get-group-number-peers
get-group-peer-pubkey
get-group-peername
get-keys
get-last-online
get-name
get-name-size
get-nospam
get-num-online-friends
get-peer-csettings
get-peer-id
get-self-address
get-self-avatar
get-self-name
get-self-name-size
get-self-status-message
get-self-status-message-size
get-self-user-status
get-status-message
get-status-message-size
get-user-status
Getters and Setters
group-action-send
group-get-title
group-message-send
group-peernumber-is-ours?
group-send-audio
group-set-title!
Groupchat Callbacks
Interact with Tox
invite-friend
is-typing?
join-av-groupchat
join-groupchat
kill-transmission
Library License
libtoxcore-racket
libtoxcore-racket
libtoxcore-racket/av
libtoxcore-racket/functions
Licensing
make-_ToxAvCSettings
make-Tox-Options
new-file-sender
prepare-audio-frame
prepare-transmission
prepare-video-frame
Procedures
request-avatar-data
request-avatar-info
Saving and Loading Functions
send-action
send-audio
send-avatar-info
send-file-control
send-file-data
send-message
send-video
set-avatar!
set-name
set-nospam!
set-status-message!
set-user-is-typing!
set-user-status!
struct:_ToxAvCSettings
struct:Tox-Options
Structs
tox-connected?
tox-do
tox-do-interval
tox-hash
tox-kill!
tox-load
tox-new
Tox-Options (struct)
Tox-Options-ipv6-enabled?
Tox-Options-proxy-address
Tox-Options-proxy-port
Tox-Options-proxy-type
Tox-Options-udp-disabled?
Tox-Options?
tox-save
tox-size
TOX_ADDRESS_SIZE
TOX_FILE_ID_LENGTH
TOX_HASH_LENGTH
TOX_MAX_CUSTOM_PACKET_SIZE
TOX_MAX_FILENAME_LENGTH
TOX_MAX_FRIEND_REQUEST_LENGTH
TOX_MAX_MESSAGE_LENGTH
TOX_MAX_NAME_LENGTH
TOX_MAX_STATUS_MESSAGE_LENGTH
TOX_PUBLIC_KEY_SIZE
TOX_SECRET_KEY_SIZE
toxav-do
toxav-do-interval
ToxAvAudioCallback
ToxAVCallback
ToxAvVideoCallback
TOXDNS_MAX_RECOMMENDED_NAME_LENGTH
unset-avatar!

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /