tutorial_10.cpp

C++ Tutorial Step 10: Creating Public Chat Join BLOBs

The program will take two arguments:

..and it will return a html link with the new public chat join BLOB in it.

Code Walkthrough

Public chat functionality has existed in the Skype desktop clients and Public API since Windows desktop version 3.0, but was never really promoted in the desktop UI. Normally, to join an already existing Skype conversation, one needs to get added to it by someone already in that conversation. The public chat mechanism provides a way to join a conversation without explicit invitation.

The basic problem with joining a chat that exists somewhere - but not in the local machine - is that the chat needs to be identified somehow. Public chats do this identification with join BLOBs. A join BLOB is a globally unique string identifier of a conversation. Once a join BLOB is obtained, it can be used to retrieve matching conversation object and join it. For example, Windows desktop client provides following URI syntax for joining a public chat:

<a href="skype:?chat&blob=kKBEYRv4Qbib2lm3zy0W5yVrE1hJdVTqYbczwBBk4EgQsWENrC-5PpF104YjY5EX">Click here.</a>

..where the sequence of characters after chat&blob= is the join BLOB.

Now, where does one get the join BLOB from? In Windows desktop client, a conversation BLOB can be had by typing /get uri in the chat. In SkypeKit, you can use Skype::GetJoinBlob method.

But first there are a few limitations how public chats can be made. SkypeKit does not support converting one-on-one dialogs into public chats. To create a new public chat, you will have to create a new conversation. Also, before asking for the join BLOB, you will need to set conversation options. Those options are stored in Conversation class properties that start with P_OPT_ prefix.

Creation of a new public chat and retrieving the join BLOB would thus go like this:

Conversation::Ref conv;
skype->CreateConference(conv);
conv->SetOption(Conversation::P_OPT_JOINING_ENABLED,  true);
conv->SetOption(Conversation::P_OPT_ENTRY_LEVEL_RANK, Participant::SPEAKER);
conv->SetOption(Conversation::P_OPT_DISCLOSE_HISTORY, true);
SEString blob;
conv->GetJoinBlob(blob);
// Hyperlink:
printf("<a href=\"skype:?chat&blob=%s\">Click here.</a>\n\n", (const char*)blob);

Full code of this example

/****************************************************************************

Getting Started With SkypeKit. Tutorial Application, Step 10.

In this step we will create a html snipped that can be used to join public chats
by clicking on a web page.

**/

#include "skype-embedded_2.h"
#include "keypair.h"
#include "tutorial_common.h"

using namespace Sid;

SEString myAccountName;
SEString myAccountPsw;

//----------------------------------------------------------------------------
// Interface section

class MySkype : public Skype
{
public:
  MySkype() : Skype() {};
  Account* newAccount(int oid) {return new MyAccount(oid, this);}
};

//----------------------------------------------------------------------------
// Main

MySkype* skype;

int main(int argc, char * argv[])
{
  printf("*****************************************************************\n");
  printf(" SkypeKit Tutorial, Step 10. - Creating Public Chat BLOB.\n");
  printf("*****************************************************************\n");

  if (argc < 3)
  {
    printf("usage: tutorial_10 <skypename> <password>\n");
    return 0;
  };

  myAccountName     = argv[1];
  myAccountPsw      = argv[2];

  printf("Creating skype ..\n");
  skype = new MySkype();

  // Starting the skype thread and submitting the Application Token.
  getKeyPair ();
  skype->init(keyBuf, inetAddr, portNum, "streamlog.txt");
  skype->start();

  printf("Retrieving account ..\n");
  MyAccount::Ref account;

  if (skype->GetAccount(myAccountName, account))
  {
    printf("Logging in..\n");
    account->LoginWithPassword(myAccountPsw, false, true);
    account->BlockWhileLoggingIn();
    printf("Loggin complete.\n");
    
    Conversation::Ref conv;
    if (skype->CreateConference(conv))
    {      
      // NB! Setting chat options must be done before asking for a join BLOB.
      conv->SetOption(Conversation::P_OPT_JOINING_ENABLED,  true);
      conv->SetOption(Conversation::P_OPT_ENTRY_LEVEL_RANK, Participant::SPEAKER);
      conv->SetOption(Conversation::P_OPT_DISCLOSE_HISTORY, true);
      
      SEString blob;
      if (conv->GetJoinBlob(blob))
      {
        printf("You can copy&paste the following html link and use it in a web page to join Public Chat:\n\n");
        printf("<a href=\"skype:?chat&blob=%s\">Click here.</a>\n\n", (const char*)blob);
        printf("Note that the creator of this chat - %s - needs to be online for joining to function.\n", 
          (const char*)myAccountName);
      }
      else 
      {
        printf("Unable to retrieve join BLOB from conversation.\n");
      };
    }
    else
    {
      printf("Unable to create conversation.\n");
    };
    
    printf("Press ENTER to quit.\n");
    getchar();

    printf("Logging out..\n");
    account->Logout(false);
    account->BlockWhileLoggingOut();
    printf("Logout complete.\n");
  }
  else
  {
      printf("Account does not exist\n");
  };
  
  printf("Cleaning up.\n");
  skype->stop();
  delete skype;
  printf("Done.\n");
  return 0;
};
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

(c) Skype Technologies S.A. Confidential/Proprietary

Last updated: Fri Mar 16 2012