Initializing

When starting the client, initialize the Client Lib with a call to

unsigned int ts3client_initClientLib(functionPointers,  
 functionRarePointers,  
 usedLogTypes,  
 logFileFolder,  
 resourcesFolder); 
const struct ClientUIFunctions* functionPointers;
const struct ClientUIFunctionsRare* functionRarePointers;
int usedLogTypes;
const char* logFileFolder;
const char* resourcesFolder;
 

Returns ERROR_ok on success, otherwise an error code as defined in public_errors.h.

[Note]Note

This function must not be called more than once.

The callback mechanism

The communication from Client Lib to Client UI takes place using callbacks. The Client UI has to define a series of function pointers using the struct ClientUIFunctions (see clientlib.h). These callbacks are used to forward any incoming server actions to the Client UI for further processing.

[Note]Note

All the clientlib callbacks are asynchronous, except for the sound callbacks which allow to directly manipulate the sound buffer.

A callback example in C:

static void my_onConnectStatusChangeEvent_Callback(uint64 serverConnectionHandlerID,
                                                   int newStatus,
                                                   int errorNumber) {
    /* Implementation */
}

C++ developers can also use static member functions for the callbacks.

Before calling ts3client_initClientLib, create an instance of struct ClientUIFunctions, initialize all function pointers with NULL and assign the structs function pointers to your callback functions:

unsigned int error;

/* Create struct */
ClientUIFunctions clUIFuncs;

/* Initialize all function pointers with NULL */
memset(&clUIFuncs, 0, sizeof(struct ClientUIFunctions));

/* Assign those function pointers you implemented */
clUIFuncs.onConnectStatusChangeEvent = my_onConnectStatusChangeEvent_Callback;
clUIFuncs.onNewChannelEvent          = my_onNewChannelEvent_Callback;
(...)

/* Initialize client lib with callback function pointers */
error = ts3client_initClientLib(&clUIFuncs, NULL, LogType_FILE | LogType_CONSOLE);
if(error != ERROR_ok) {
    printf("Error initializing clientlib: %d\n", error);
    (...)
}
[Important]Important

As long as you initialize unimplemented callbacks with NULL, the Client Lib won't attempt to call those function pointers. However, if you leave unimplemented callbacks undefined, the Client Lib will crash when trying to calling them.

[Note]Note

All callbacks used in the SDK are found in the struct ClientUIFunctions (see public_definitions.h). Callbacks bundled in the struct ClientUIFunctionsRare are not used by the SDK. These callbacks were split in a separate structs to avoid polluting the SDK headers with code used only internally.