TeamTalk 4 .NET DLL
Version 4.5A
|
The following sections gives a step-by-step tour of how to build an application which uses the TeamTalk 4 .NET DLL to transmit audio and video. This chapter assumes the developer has read the section Client Setup Guide on how to configure Visual Studio to work with the TeamTalk client DLL.
In order for the user application to interact with other clients a TeamTalk server must first be set up. Section Server Setup Guide explains how to do this. The job of the TeamTalk server is to provide user autentication and keep track of users. Once a client is connected and has been authenticated the client is presented with a tree structure where each node is a so-called "channel" which the client can join and from there interact with the other users who are in the same channel.
The following six steps explains how to build a TeamTalk client:
A new client instance is created by instantiating the BearWare.TeamTalk4-class. Once the new instance has been created its current state can be retrieved by calling the function TeamTalk4.GetFlags() which will return a bitmask describing the client's current state. Initially after creating the client instance a call to TeamTalk4.GetFlags() will return a bitmask with the value ClientFlag CLIENT_CLOSED since no operations have been performed on the client.
Here a code-snip which shows how to instantiate the BearWare.TeamTalk4 class.
Before connecting to a server it is a good idea to setup the user's sound and video devices. Sound devices are initialized using the TeamTalk4.InitSoundInputDevice() and TeamTalk4.InitSoundOutputDevice() functions. The video capture device is initialized using TeamTalk4.InitVideoCaptureDevice(). Initializing the video capture device can be quite tricky because there's many properties which needs to be configured. Look at the SDK sample applications to see how it is done.
Once sound and video devices has been initialized the function TeamTalk4.GetFlags() will return a mask containing ClientFlag CLIENT_SNDINPUT_READY, ClientFlag CLIENT_SNDOUTPUT_READY and ClientFlag CLIENT_VIDEO_READY.
Here a code-snip which shows how to extract extract sound and video devices:
By calling TeamTalk4.Connect() will make the client connect to the server running on the IP-address and port numbers specified as parameters to the function. After this call the TeamTalk4.GetFlags() function will have the ClientFlag CLIENT_CONNECTING bit set.
If the TeamTalk4.Connect() call fails the TeamTalk4.OnConnectFailed() event will be posted by the client instance and the ClientFlag CLIENT_CONNECTING bit will be cleared.
If the TeamTalk4.Connect() is successful the TeamTalk4.OnConnectSuccess() event will be posted by the client instance and the ClientFlag CLIENT_CONNECTED bit will be set and ClientFlag CLIENT_CONNECTING will be cleared.
Here is a code-snip which shows how to connect to a server:
Once connected the user application can call TeamTalk4.DoLogin() to log on to the server. All functions with the prefix Do*
are client to server commands (see Client/Server Commands). The TeamTalk4.DoLogin() requires that the user application provides a server password, account username and account password. A server may allow anonymous users (see UserRight USERRIGHT_GUEST_LOGIN) to log on in which case the account username and password can be left blank.
If the server rejects the login the TeamTalk4.OnCmdError() event is posted along with an error code (see ClientError).
If the server accepts the login information the TeamTalk4.OnCmdMyselfLoggedIn() event is posted and the the client instance will have the ClientFlag CLIENT_AUTHORIZED set.
For every channel on the server a TeamTalk4.OnCmdChannelNew() event will be posted and a TeamTalk4.OnCmdUserLoggedIn() will be posted for every user on the server. The TeamTalk4.OnCmdUserJoinedChannel() will also be posted for every user who is in a channel.
Here's a code-snip which shows how to log on to a server:
Now that the client is connected and authorized it is possible to join a channel on the server. This is done by either calling the function TeamTalk4.DoJoinChannel() to create a new channel or by calling TeamTalk4.DoJoinChannelByID() to join an existing channel.
If using the TeamTalk4.DoJoinChannelByID() command to join a channel the ID of the channel must be retrieved and also the password needed to join the channel. The ID of a channel is posted in the TeamTalk4.OnCmdChannelNew() event and the password must be known by the user.
If the call to TeamTalk4.DoJoinChannelByID() is successful the event TeamTalk4.OnCmdMyselfJoinedChannel() is posted and if the server rejected the command to join the TeamTalk4.OnCmdError() event is posted.
Here is a code-snip for joining a channel:
Having joined a channel now enables the client instance to start transmitting audio and video to the other users in the channel by calling TeamTalk4.EnableTransmission().
When the other users in the channel starts receiving audio they will receive the TeamTalk4.OnUserTalking() event. If video is also being transmitted the event TeamTalk4.OnUserVideoFrame() will be posted for every video frame which is received.
Here's a code-snip on how to transmit and display data: