Exemple #1
0
        /**
         * Processes messages associated with a Conversation.
         * Processes <em>only</em> messages of type:
         * <ul>
         *   <li>STARTED_LIVESESSION&#8212;lists details of in-coming and out-going calls</li>
         *   <li>POSTED_VOICE_MESSAGE&#8212;lists details of in-coming and out-going voicemails</li>
         *   <li>REQUESTED_AUTH&#8212;lists Contact authorization requests</li>
         *   <li>GRANTED_AUTH&#8212;lists Contacts granted authorization</li>
         * </ul>
         *
         * @param mySession
         *	Populated session object
         * @param myMessages
         *	Array of message strings to process.
         *
         * @since 1.0
         */
        static void doRenderHistory(MySession mySession, Message[] myMessages)
        {
            ParsePosition s_pos;
            ParsePosition e_pos;

            int msgTimeStamp;
            Date dateTimeStamp;
            DateFormat dateFmt = DateFormat.getDateTimeInstance();

            String author;
            String bodyXml;
            int bodyXmlLength;

            /*
             *         myXmlStrMgr.setVerboseDebug(true);
             */

            int msgCount = myMessages.Length;
            Message currMsg;
            Message.Type currMsgType;
            MySession.myConsole.printf("%d ...%n", msgCount);
            for (int i = 0; i < msgCount; i++)
            {
                currMsg = myMessages[i];
                currMsgType = currMsg.getType();

                if (currMsgType == Message.Type.STARTED_LIVE_SESSION)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    // Message.Property.P_AUTHOR tells who initiated the call.
                    author = currMsg.getAuthor();

                    // For duration we unfortunately have to parse the XML
                    // The duration we're interested in is
                    // <part identity="&me">%n...<duration>x</duration>...
                    //
                    // Real implementation should use a proper XML-parser here!
                    java.lang.StringBuffer partTag = new java.lang.StringBuffer("<part identity=\"");
                    partTag.append(mySession.myAccountName + "\">");
                    s_pos = myXmlStrMgr.getXmlSubStrPos(currMsg.getBodyXml(),
                                                        partTag.toString(), ZERO_POS);
                    if (s_pos == null)
                    {
                        MySession.myConsole.printf("%s: Could not find \"%s\" in xmlDoc%n%s%n%nSkipping...%n%n",
                                MY_CLASS_TAG, partTag.toString(),
                                currMsg.getBodyXml());
                        break;
                    }

                    int duration =
                        myXmlStrMgr.getXmlValueNum(currMsg.getBodyXml(),
                                                    "<duration>", s_pos);

                    // Ditto for counting how many parts the body has...
                    int num_parts = 0;
                    s_pos.setIndex(0);
                    do
                    {
                        e_pos = myXmlStrMgr.getXmlSubStrPos(currMsg.getBodyXml(),
                                                            "<part ", s_pos);
                        if (e_pos != null)
                        {
                            num_parts++;
                            s_pos.setIndex(e_pos.getIndex());
                        }
                    }
                    while (e_pos != null);

                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    // Last part is to fetch message reason
                    String reason = currMsg.getReason();

                    if (author.Equals(mySession.myAccountName))
                    {
                        // I initiated the call
                        MySession.myConsole.println("outgoing call to ");
                    }
                    else
                    {
                        // Somebody else called me
                        MySession.myConsole.println("incoming call from ");
                    }

                    // List identities
                    doListIdentities(currMsg);

                    if (duration >= 0)
                    {
                        MySession.myConsole.printf("duration %d seconds", duration);
                    }
                    else if (num_parts > 1)
                    {
                        if (reason.Equals("manual"))
                        {
                            MySession.myConsole.printf("refused");
                        }
                        else
                        {
                            MySession.myConsole.printf("failed (%s)", reason);
                        }
                    }
                    else
                    {
                        MySession.myConsole.printf("missed");
                    }

                    MySession.myConsole.printf(" (%d parts).%n", num_parts);
                }
                else if (currMsgType == Message.Type.POSTED_VOICE_MESSAGE)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    author = currMsg.getAuthor();
                    // XML parsing again...
                    bodyXml = currMsg.getBodyXml();
                    bodyXmlLength = myXmlStrMgr.getXmlValueNum(bodyXml, "<length>", ZERO_POS);
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    if (author.Equals(mySession.myAccountName))
                    {
                        // I initiated the call
                        MySession.myConsole.println("Sent voicemail to ");
                    }
                    else
                    {
                        // Somebody else called me
                        MySession.myConsole.println("Got voicemail from ");
                    }
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.printf("duration %d%n", bodyXmlLength);
                }
                else if (currMsgType == Message.Type.REQUESTED_AUTH)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    // Please note that REQUESTED_AUTH is not used to request authorization
                    // ALERT is used for that. REQUESTED_AUTH is used only for history
                    author = currMsg.getAuthor();
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    MySession.myConsole.printf("Authorization request from %s to ", author);
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.println("");
                }
                else if (currMsgType == Message.Type.GRANTED_AUTH)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    author = currMsg.getAuthor();
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    MySession.myConsole.printf("%s granted authorization to ", author);
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.println("");
                }

                else
                    MySession.myConsole.printf("%nIgnoring message of type %s%n", currMsgType.toString());
            }
        }
Exemple #2
0
        /**
         * Call someone in your Contacts.
         * <ol>
         *   <li>Obtain the list of available playback and recording devices.</li>
         *   <li>Set the current devices (input, output, notification) to the first device
         *   	 in their respective list, and display their names.</li>
         *   <li>Obtain the list of my Contacts, and find the target caller in it.
         *   	 If not found, display an appropriate message and return.</li>
         *   <li>Attempt to call that Contact.</li>
         *   <li>Wait until the call finishes</li>
         * </ol>
         *
         * @param mySession
         *	Populated session object
         * @param myCallTarget
         * 	The Skype Name of the person to call.
         *
         * @since 1.0
         */
        static void doMakeCall(MySession mySession, String myCallTarget)
        {
            // Get available playback/recording devices; choose first of each
            if (mySession.setupAudioDevices(0, 0))
            {
                MySession.myConsole.printf("%s: Audio device set-up completed!%n", mySession.myTutorialTag);
            }
            else
            {
                MySession.myConsole.printf("%s: Audio device set-up failed - exiting!%n", mySession.myTutorialTag);
                return;
            }

            String[] callTargets = { myCallTarget }; // Create & initialize the array in one step...
            Conversation myConversation =
                (Conversation)mySession.mySkype.getConversationByParticipants(callTargets, true, true);

            Participant[] convParticipantList = myConversation.getParticipants(Conversation.ParticipantFilter.ALL);

            int i;
            int j = convParticipantList.Length;
            bool callTargetFound = false;
            for (i = 0; i < j; i++)
            {
                if (convParticipantList[i].getIdentity().Equals(myCallTarget))
                {
                    callTargetFound = true;
                    break;
                }
            }

            if (!callTargetFound)
            {
                MySession.myConsole.printf("Could not find call target  %s%n", myCallTarget);
                return;
            }

            MySession.myConsole.printf("Calling %s%n", myCallTarget);	// Initiate the call
            mySession.callActive = true;
            convParticipantList[i].ring(myCallTarget, false, 0, 10, false,
                                        mySession.myAccount.getSkypeName());

            // Loop until the call finishes
            while (mySession.callActive)
            {
                try
                {
                    Thread.Sleep(SignInMgr.DELAY_INTERVAL);
                }
                catch (java.lang.InterruptedException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    return;
                }
            }
        }
Exemple #3
0
        /**
         * Handles event history.
         * <ol>
         * 	<li>Obtains an unfiltered list of all Conservations</li>
         * 	<li>For each conversation:
         * 	  <ol style="list-style-type:lower-alpha">
         * 	    <li>Lists associated context messages</li>
         * 	    <li>Lists associated unconsumed messages</li>
         * 	  </ol>
         *   </li>
         * </ol>
         *
         * @param mySession
         *	Populated session object
         *
         * @since 1.0
         */
        static void doEventHistory(MySession mySession)
        {
            Conversation[] myConversationList =
                mySession.mySkype.getConversationList(Conversation.ListType.REALLY_ALL_CONVERSATIONS);
            int conversationListCount = myConversationList.Length;

            for (int i = 0; i < conversationListCount; i++)
            {
                Conversation currConv = myConversationList[i];
                MySession.myConsole.printf("%n%s: Processing Conversation \"%s\" (%d of %d)...%n",
                                    MY_CLASS_TAG, currConv.getDisplayName(),
                                    (i + 1), conversationListCount);
                // Get messages after midnight 01 December, 2010 local time
                // Replace timestamp argument with '0' to get only messages within the last 24 hours
                Calendar calTimeStamp = Calendar.getInstance();
                calTimeStamp.set(2010, Calendar.DECEMBER, 1, 0, 0, 0);
                long l_calTimeStamp = calTimeStamp.getTimeInMillis() / 1000L;
                Conversation.GetLastMessagesResponse currConvMsgList = currConv.getLastMessages((int)l_calTimeStamp);
                /*
                 *     		Conversation.GetLastMessagesResponse currConvMsgList = currConv.GetLastMessages(0);
                 */
                MySession.myConsole.printf("%s: Rendering context messages... found ", MY_CLASS_TAG);
                doRenderHistory(mySession, currConvMsgList.contextMessages);
                MySession.myConsole.printf("%s: Rendering unconsumed messages... found ", MY_CLASS_TAG);
                doRenderHistory(mySession, currConvMsgList.unconsumedMessages);
            }

            MySession.myConsole.printf("%s: Press Enter to quit.%n%n", mySession.myTutorialTag);
            try
            {
                while (true)
                {
                    int keyboardChar = (int)System.Console.ReadKey().KeyChar;
                    // Some platforms think ENTER is 0x0D; others think it's 0x0A...
                    if ((keyboardChar == 0x0D) || (keyboardChar == 0x0A))
                    {
                        break;
                    }
                }
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return;
            }
        }
Exemple #4
0
        /**
         * Finds and list conversations
         * <ol>
         *   <li>List the display name of my conversations associated with the participants listed in {@link #participantNames}.</li>
         *   <li>List the type and display name of <em>all</em> my conversations.</li>
         * </ol>
         *
         * @param mySession
         *	Populated session object
         *
         * @since 1.0
         */
        static void doConversation(MySession mySession)
        {
            int i;			// Index variable
            int j;			// Loop counter variable
            Conversation myConversation;
            String displayName = null;

            // One Conversation (using GetConversationByParticipants)
            bool createIfNonExisting = false;
            bool ignoreBookmarkedOrNamed = false;

            j = participantNames.Length;
            if ((myConversation = mySession.mySkype.getConversationByParticipants(participantNames, createIfNonExisting, ignoreBookmarkedOrNamed)) != null)
            {
                displayName = myConversation.getDisplayName();
                MySession.myConsole.printf("Conversation display name is %s%n", displayName);
                String pluralSfx = (j < 2) ? "" : "s";
                MySession.myConsole.printf("%d other Participant%s:%n", j, pluralSfx);
            }
            else
            {
                MySession.myConsole.println("No conversation on this account with participants:");
            }
            j = participantNames.Length;
            for (i = 0; i < j; i++)
            {
                MySession.myConsole.printf("\t%s%n", participantNames[i]);
            }

            MySession.myConsole.println("");

            // List of Conversations (using GetConversationList)
            Conversation[] myInbox = mySession.mySkype.getConversationList(Conversation.ListType.INBOX_CONVERSATIONS);

            j = myInbox.Length;
            MySession.myConsole.printf("%d Conversations in myInbox:%n", j);
            for (i = 0; i < j; i++)
            {
                myConversation = myInbox[i];

                // Getting Conversation properties
                Conversation.Type conversationType = myConversation.getType();
                displayName = myConversation.getDisplayName();
                MySession.myConsole.printf("\tType = %d (%s); Display Name = %s%n",
                    conversationType, conversationType.toString(), displayName);

                // Getting Conversation participants, which always includes ourselves
                Participant[] convParticipants = myConversation.getParticipants(Conversation.ParticipantFilter.ALL);
                int p;
                int q = convParticipants.Length;
                String pluralSfx = (q <= 2) ? "" : "s";
                MySession.myConsole.printf("\t%d other Participant%s:%n", (q - 1), pluralSfx);
                for (p = 0; p < q; p++)
                {
                    Participant myParticipant = convParticipants[p];
                    String identity = myParticipant.getIdentity();

                    if (identity.CompareTo(mySession.myAccountName) == 0)
                    {
                        continue;	// Don't list ourselves!
                    }
                    MySession.myConsole.printf("\t\t%s", identity);
                    String liveIdentity = myParticipant.getLiveIdentity();
                    if ((liveIdentity != null) && (liveIdentity.Length != 0))
                    {
                        MySession.myConsole.printf(" (%s)%n", liveIdentity);
                    }
                    else
                    {
                        MySession.myConsole.println("");
                    }
                }
                MySession.myConsole.println("");
            }
        }
Exemple #5
0
        /**
         * List, add, or delete Contacts.
         *
         * @param mySession
         *	Populated session object.
         * @param pstn
         * 	Properly formatted phone number of the target PSTN Contact.
         * @param displayName
         * 	Display name of the target PSTN Contact (used by add <em>only</em>).
         * @param commandOpt
         * 	Command string, which must be one of:
         * 	<ul>
         * 	  <li>{@link #ADD_CONTACT}</li>
         * 	  <li>{@link #DELETE_CONTACT}</li>
         * 	  <li>{@link #LIST_CONTACTS}</li>
         * 	</ul>
         *
         * @since 1.0
         */
        static void doPstnContact(MySession mySession, String pstn, String displayName, String commandOpt)
        {
            // Verify that our command option is valid -- something our invoker should have already done!
            if ((!(commandOpt.Equals(LIST_CONTACTS))) && (!(commandOpt.Equals(ADD_CONTACT))) &&
                (!(commandOpt.Equals(DELETE_CONTACT))))
            {
                // We shouldn't get here -- the invoker should have already validated the command.
                MySession.myConsole.printf("%s: Unrecognized command option: %s%n", mySession.myTutorialTag, commandOpt);
                return;
            }

            int contactIdx;
            Skype.NormalizeIdentityResponse nrmlResponse = null;

            ContactGroup soContactGroup = mySession.mySkype.getHardwiredContactGroup(ContactGroup.Type.SKYPEOUT_BUDDIES);
            Contact[] soContactList = soContactGroup.getContacts();
            int contactCount = soContactList.Length;

            // Handle list operations...
            if (commandOpt.Equals(LIST_CONTACTS))
            {
                // Make sure there's something to list!
                if (contactCount == 0)
                {
                    MySession.myConsole.printf("%s: There are no PSTN contacts.%n", mySession.myTutorialTag);
                    return;
                }
                MySession.myConsole.printf("%s: Current list of PSTN contacts:%n", mySession.myTutorialTag);
                for (contactIdx = 0; contactIdx < contactCount; contactIdx++)
                {
                    MySession.myConsole.printf("%s: %d. %s (%s)%n", mySession.myTutorialTag, (contactIdx + 1),
                                            soContactList[contactIdx].getPstnNumber(),
                                            soContactList[contactIdx].getDisplayName());
                }
                return;
            }

            //Handle add & delete operations...
            String contactPstn;
            bool contactAlreadyListed = false;

            // Ensure that the pstn argument contains a valid contact identity
            nrmlResponse = getNormalizationStr(pstn);
            if (nrmlResponse.result != Skype.NormalizeResult.IDENTITY_OK)
            {
                MySession.myConsole.printf("%s: Cannot normalize pstn %s using %s%n",
                                        mySession.myTutorialTag, pstn,
                                        mySession.mySkype.getIsoCountryInfo().countryPrefixList[0]);
                return;
            }

            // Check whether the PSTN contact already exists, which is relevant to both
            // adding and removing contacts. In current wrapper version, the only way to do this
            // is to loop over a contact group.
            for (contactIdx = 0; contactIdx < contactCount; contactIdx++)
            {
                contactPstn = soContactList[contactIdx].getPstnNumber();
                if (contactPstn.Equals(nrmlResponse.normalized))
                {
                    contactAlreadyListed = true;
                }
            }

            // Handle adding a Contact. The Contact must not exist in that group!
            if (commandOpt.Equals(ADD_CONTACT))
            {
                if (contactAlreadyListed)
                {
                    MySession.myConsole.printf("%s: Error: %s already present in ContactGroup.%n",
                                            mySession.myTutorialTag, nrmlResponse.normalized);
                    return;
                }
                MySession.myConsole.printf("%s: Adding PSTN Contact...%n", mySession.myTutorialTag);
                Contact newContact = mySession.mySkype.getContact(nrmlResponse.normalized);
                if ((newContact != null) && (soContactGroup.canAddContact(newContact)))
                {
                    newContact.giveDisplayName(displayName);
                    soContactGroup.addContact(newContact);
                    MySession.myConsole.printf("%s: Contact %s (%s) added.%n",
                                            mySession.myTutorialTag, nrmlResponse.normalized, displayName);
                }
                else
                {
                    ContactGroup.Type soContactGroupType = soContactGroup.getType();
                    MySession.myConsole.printf("%s: Cannot add Contact %s (%s) to ContactGroup %s (\"%s\") using AddContact():%n",
                                            mySession.myTutorialTag, nrmlResponse.normalized, displayName,
                                            soContactGroupType.toString(),
                                            soContactGroup.getGivenDisplayName());
                    if (newContact == null)
                    {
                        MySession.myConsole.println("\tCould not create new Contact (normalized PSTN likely invalid)");
                    }
                    else if (!(soContactGroup.canAddContact(newContact)))
                    {
                        MySession.myConsole.println("\tCannot add Contacts to target ContactGroup");
                    }
                    else
                    {
                        MySession.myConsole.println("\tReason unknown?!?%n");
                    }
                }
                return;
            }

            // Handle deleting a Contact. The Contact must exist in that group!
            if (!contactAlreadyListed)
            {
                MySession.myConsole.printf("%s: PSTN Contact %s not present in ContactGroup.%n",
                                        mySession.myTutorialTag, nrmlResponse.normalized);
                return;
            }

            MySession.myConsole.printf("%s: Removing PSTN Contact...%n", mySession.myTutorialTag);
            Contact removableContact = mySession.mySkype.getContact(nrmlResponse.normalized);
            if ((removableContact != null) && (soContactGroup.canRemoveContact()))
            {
                String removableDisplayName = removableContact.getDisplayName();
                soContactGroup.removeContact(removableContact);
                // Can't include any Contact-specific identifying information in the message that we haven't already
                // extracted since RemoveContact leaves the target Contact instance in an undefined (mostly nulled-out) state!
                MySession.myConsole.printf("%s: Removed PSTN Contact %s (\"%s\").%n",
                        mySession.myTutorialTag, nrmlResponse.normalized, removableDisplayName);
            }
            else
            {
                ContactGroup.Type soContactGroupType = soContactGroup.getType();
                MySession.myConsole.printf("%s: Cannot remove Contact %s from ContactGroup %s (\"%s\") using RemoveContact():%n",
                                        mySession.myTutorialTag, nrmlResponse.normalized,
                                        soContactGroupType.toString(),
                                        soContactGroup.getGivenDisplayName());
                if (removableContact == null)
                {
                    MySession.myConsole.println("\tCould not remove Contact (normalized PSTN likely invalid)");
                }
                else if (!(soContactGroup.canRemoveContact()))
                {
                    MySession.myConsole.println("\tCannot remove Contacts from target ContactGroup");
                }
                else
                {
                    MySession.myConsole.println("\tReason unknown?!?%n");
                }
            }

            return;
        }
Exemple #6
0
        /**
         * Find Contacts associated with this user (if any), and wait for changes in their availability/status.
         * <ol>
         *   <li>List the displayname of each Contact.</li>
         *   <li>Wait for any change in their status.</li>
         * </ol>
         *
         * @param mySession
         *	Populated session object
         *
         * @since 1.0
         */
        static void doContacts(MySession mySession)
        {
            Contact[] myContactList =
               mySession.mySkype.getHardwiredContactGroup(ContactGroup.Type.SKYPE_BUDDIES).getContacts();
            int i;
            int j = myContactList.Length;
            for (i = 0; i < j; i++)
            {
                MySession.myConsole.printf("%d. %s%n", (i + 1), myContactList[i].getDisplayName());
            }

            MySession.myConsole.printf("%s: Waiting for Contact status change events...%nPress Enter to quit.%n%n",
                                         mySession.myTutorialTag);
            try
            {
                while (true)
                {
                    int keyboardChar = (int)System.Console.ReadKey().KeyChar;
                    // Some platforms think ENTER is 0x0D; others think it's 0x0A...
                    if ((keyboardChar == 0x0D) || (keyboardChar == 0x0A))
                    {
                        break;
                    }
                }
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return;
            }

            MySession.myConsole.println();
        }
Exemple #7
0
        /**
         * Handles Contact authorization requests.
         * <ol>
         *   <li>Obtains a list of Contacts awaiting authorization.</li>
         *   <li>Wait for status changes on those Contacts.</li>
         * </ol>
         *
         * @param mySession
         *	Populated session object.
         *
         * @since 1.0
         */
        static void doGetContactRequest(MySession mySession)
        {
            // Here we will get ourselves a ContactGroup object, so that we can get
            // OnChange events when an incoming authorization request occurs.
            ContactGroup waitingForAuthList =
                (ContactGroup)mySession.mySkype.getHardwiredContactGroup(ContactGroup.Type.CONTACTS_WAITING_MY_AUTHORIZATION);

            // The following may look just like a decoration but in fact, you MUST read at least one property
            // of the object (waitingForAuthList) to start getting OnChange events. We'll randomly pick nrofcontacts
            // and ignore its value.
            waitingForAuthList.getContactCount();

            // The rest of the interesting stuff will take place in ContactGroup.OnChange
            MySession.myConsole.printf("%s: Waiting for authorization request events...%nPress Enter to quit.%n%n",
                                mySession.myTutorialTag);
            try
            {
                while (true)
                {
                    int keyboardChar = (int)System.Console.ReadKey().KeyChar;
                    // Some platforms think ENTER is 0x0D; others think it's 0x0A...
                    if ((keyboardChar == 0x0D) || (keyboardChar == 0x0A))
                    {
                        break;
                    }
                }
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return;
            }

            MySession.myConsole.println();
        }
 public Listeners(MySession mySession)
 {
     this.mySession = mySession;
     MySession.myConsole.println("\tRegistering the listeners...");
     registerAllListeners();
 }
 public Listeners(MySession mySession)
 {
     this.mySession = mySession;
     MySession.myConsole.println("\tRegistering the listeners...");
     registerAllListeners();
 }
Exemple #10
0
        /**
         * Conference with at least two other participants.
         * <ol>
         *   <li>Obtain the list of available playback and recording devices.</li>
         *   <li>Set the current devices (input, output, notification) to the first device
         *   	 in their respective list, and display their names.</li>
         *   <li>Create a conference conversation.</li>
         *   <li>Add each of the specified call targets (Skype Names) to the conversation as consumers.</li>
         *   <li>Obtain the resultant list of conversation participants, which will include
         * 		 the conference creator.</li>
         *   <li>Attempt to call each participant <em>except the conference creator</em>,
         *   	 and wait for them to answer.</li>
         *   <li>Wait until the call finishes.</li>
         * </ol>
         *
         * @param mySession
         *	Populated session object
         * @param myCallTargets
         * 	The Skype Names of the people to conference with.
         *
         * @since 1.0
         */
        static void doMakeConferenceCall(MySession mySession, String[] myCallTargets)
        {
            // Get available playback/recording devices; choose first of each
            if (mySession.setupAudioDevices(0, 0))
            {
                MySession.myConsole.printf("%s: Audio device set-up completed!%n", mySession.myTutorialTag);
            }
            else
            {
                MySession.myConsole.printf("%s: Audio device set-up failed - exiting!%n", mySession.myTutorialTag);
                return;
            }

            Conversation myConversation = (Conversation)mySession.mySkype.createConference();

            // *** DEBUG ***
            for (int m = 0; m < myCallTargets.Length; m++)
            {
                MySession.myConsole.printf("\tCall target name %d: %s%n", m, myCallTargets[m]);
            }

            myConversation.addConsumers(myCallTargets);

            Participant[] convParticipantList =
                myConversation.getParticipants(Conversation.ParticipantFilter.ALL);

            mySession.callActive = false;
            String partIdentity;
            int i;
            int j = convParticipantList.Length;
            int k = 0;
            for (i = 0; i < j; i++)
            {
                partIdentity = convParticipantList[i].getIdentity();

                if (partIdentity != mySession.myAccountName)
                {
                    k++;
                    MySession.myConsole.printf("Calling %s%n", partIdentity);
                    convParticipantList[i].ring(partIdentity, false, 1, 40, false,
                                                mySession.myAccount.getSkypeName());
                    int m = 0;
                    while ((m < SignInMgr.DELAY_CNT) && (!isRinging(convParticipantList[i])))
                    {
                        try
                        {
                            Thread.Sleep(SignInMgr.DELAY_INTERVAL);
                        }
                        catch (java.lang.InterruptedException e)
                        {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        MySession.myConsole.printf("\t%d...%n", m++);
                    }

                    if (m >= SignInMgr.DELAY_CNT)
                    {
                        MySession.myConsole.printf("%s: Ring timed out for %s; skipping!%n",
                                MY_CLASS_TAG, convParticipantList[i]);
                        continue;
                    }
                    mySession.callActive = true;
                }
            }

            if (k == 0)
            {
                MySession.myConsole.println("No one (except maybe ourselves) to conference in ?!?");
                return;
            }

            while (!mySession.callActive)
            {
                try
                {
                    Thread.Sleep(SignInMgr.DELAY_INTERVAL);
                }
                catch (java.lang.InterruptedException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    return;
                }
            }
        }
Exemple #11
0
        /**
         * Join a conversation.
         * <ol>
         *   <li>Creates a conference conversation.</li>
         *   <li>Establishes its properties to enable joining as a SPEAKER with history visible.</li>
         *   <li>Obtains the conversation's join BLOB.</li>
         *   <li>Writes the href for joining the conversation to the console.</li>
         * </ol>
         *
         * @param mySession
         *	Populated session object
         *
         * @since 1.0
         */
        static void doPublicChat(MySession mySession)
        {
            Conversation myConversation;

            if ((myConversation = mySession.mySkype.createConference()) != null)
            {
                // NB! Setting chat options must be done before asking for a join BLOB.
                myConversation.setOption(Conversation.Property.P_OPT_JOINING_ENABLED.getId(), 1);
                myConversation.setOption(Conversation.Property.P_OPT_ENTRY_LEVEL_RANK.getId(), Participant.Rank.SPEAKER.getId());
                myConversation.setOption(Conversation.Property.P_OPT_DISCLOSE_HISTORY.getId(), 1);

                String convBlob;
                if ((convBlob = myConversation.getJoinBlob()) != null)
                {
                    MySession.myConsole.printf("You can copy/paste the following HTML link and use it in a Web page to join Public Chat:%n%n");
                    MySession.myConsole.printf("<a href=\"skype:?chat&blob=%s\">Click here.</a>%n%n", convBlob);
                    MySession.myConsole.printf("Note that the creator of this chat - %s - needs to be online for you to actually join.%n", mySession.myAccountName);
                }
                else
                {
                    MySession.myConsole.printf("%s: Unable to retrieve join BLOB from conversation.%n", mySession.myTutorialTag);
                }
            }
            else
            {
                MySession.myConsole.printf("%s: Unable to create conversation.%n", mySession.myTutorialTag);
            }
        }
Exemple #12
0
        /**
         * Find available input/output devices, then wait for incoming calls..
         * <ol>
         *   <li>List the available playback and recording devices.</li>
         *   <li>Set the current devices (input, output, notification) to the first device in their respective list.</li>
         *   <li>Initialize the speaker volume level.</li>
         *   <li>Wait for in-coming calls.</li>
         * </ol>
         *
         * @param mySession
         *	Populated session object
         *
         * @since 1.0
         */
        static void doAcceptCalls(MySession mySession)
        {
            int i;
            int j;

            Skype.GetAvailableOutputDevicesResponse outputDevices = mySession.mySkype.getAvailableOutputDevices();
            Skype.GetAvailableRecordingDevicesResponse inputDevices = mySession.mySkype.getAvailableRecordingDevices();

            // Getting a list of audio output devices.
            MySession.myConsole.println("** Playback devices:");
            j = outputDevices.handleList.Length;
            for (i = 0; i < j; i++)
            {
                MySession.myConsole.printf("\t%d. %s (%s)%n", i, outputDevices.nameList[i], outputDevices.productIdList[i]);
            }
            MySession.myConsole.println("");

            // Getting a list of audio input devices.
            MySession.myConsole.println("** Recording devices:");
            j = inputDevices.handleList.Length;
            for (i = 0; i < j; i++)
            {
                MySession.myConsole.printf("\t%d. %s (%s)%n", i, inputDevices.nameList[i], inputDevices.productIdList[i]);
            }
            MySession.myConsole.println("");

            // Currently setting the sound devices to the first input/output device.
            // The output and notification are routed through the same device. If you want more control,
            // don't invoke SetupAudioDevices -- instead invoke:
            // 	mySession.mySkype.SelectSoundDevices(inputDevices.handleList[0],
            //											outputDevices.handleList[0],
            //											outputDevices.handleList[0]);
            //	mySession.mySkype.SetSpeakerVolume(100);
            //
            // If your microphone or speakers fail to work, you might want
            // to change these values.

            if (mySession.setupAudioDevices(0, 0))
            {
                MySession.myConsole.printf("%s: Audio device set-up completed!%n", mySession.myTutorialTag);
            }
            else
            {
                MySession.myConsole.printf("%s: Audio device set-up failed - exiting!%n", mySession.myTutorialTag);
                return;
            }

            MySession.myConsole.printf("%s: Now accepting incoming calls...%nPress Enter to quit.%n%n", mySession.myTutorialTag);
            try
            {
                while (true)
                {
                    int keyboardChar = (int)System.Console.ReadKey().KeyChar;
                    // Some platforms think ENTER is 0x0D; others think it's 0x0A...
                    if ((keyboardChar == 0x0D) || (keyboardChar == 0x0A))
                    {
                        break;
                    }
                }
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return;
            }

            MySession.myConsole.println("");
        }
Exemple #13
0
        /**
         * Capture chat messages sent to us, and echo it to the console.
         * <br /><br />
         * Stop capturing chat messages when the user presses <strong>ENTER</strong>
         *
         * @param mySession
         *	Populated session object
         *
         * @since 1.0
         */
        static void doChat(MySession mySession)
        {
            MySession.myConsole.printf("%s: Waiting for incoming chat messages...%nPress Enter to quit.%n%n",
                    mySession.myTutorialTag);
            try
            {
                while (true)
                {
                    int keyboardChar = (int)System.Console.ReadKey().KeyChar;
                    // Some platforms think ENTER is 0x0D; others think it's 0x0A...
                    if ((keyboardChar == 0x0D) || (keyboardChar == 0x0A))
                    {
                        break;
                    }
                }
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return;
            }

            // End capturing chat text
            MySession.myConsole.println();
        }
Exemple #14
0
 /**
  * Make a datagram-based command-line chat between two instances of the same SkypeKit client.
  *
  * @param mySession
  *	Populated session object
  *	@param myContactName
  *	 Skype Name of person to connect with.
  *
  * @since 1.0
  */
 static void doApp2AppDatagram(MySession mySession, String myContactName)
 {
 }
        /**
         * Common SkypeKit tutorial logout processing.
         * <ul>
         *   <li>writes message to the console indicating success/failure/timeout</li>
         *   <li>writes stack trace if I/O error setting up the transport!</li>
         * </ul>
         *
         * Delays the logout by a second or so to ensure that the SkypeKit runtime has fully settled in
         * if the interval between sign-in and sign-out is really, really short (such as exists in
         * {@link com.skype.tutorial.step1.Tutorial_1}). We don't want to see
         * Account.LOGOUTREASON.APP_ID_FAILURE unless our AppToken is truly bogus!
         *
         * @param myTutorialTag
         * 	Invoker's {@link #MY_CLASS_TAG}.
         * @param mySession
         * 	Populated session object providing access to the invoker's
         *  Skype and Account objects.
         *
         * @see #LOGOUT_DELAY
         *
         * @since 1.0
         */
        public void Logout(String myTutorialTag, MySession mySession)
        {
            // Give the runtime a chance to catch its breath if it needs to...
            try
            {
                Thread.Sleep(SignInMgr.LOGOUT_DELAY);
            }
            catch (Exception e)
            {
                // TODO Auto-generated catch block
                MessageBox.Show(e.Message);
            }

            if (!mySession.isLoggedIn())
            {
                // Already logged out...
                MySession.myConsole.printf("%s: %s already logged out! (IP Addr %s:%d)%n",
                                    myTutorialTag, mySession.myAccountName,
                                    MySession.IP_ADDR, MySession.PORT_NUM);
                return;
            }

            // Issue logout request
            mySession.myAccount.logout(false);

            // Loop until AccountListener shows we are logged out or we time-out...
            MySession.myConsole.printf("%s: Waiting for logout to complete...%n", myTutorialTag);
            int i = 0;
            /*
             * 		while ((i < SignInMgr.DELAY_CNT) && (SignInMgr.isLoggedIn(mySession.myAccount))) {
             */
            while ((i < SignInMgr.DELAY_CNT) && (mySession.isLoggedIn()))
            {
                try
                {
                    Thread.Sleep(SignInMgr.DELAY_INTERVAL);
                }
                catch (Exception e)
                {
                    // TODO Auto-generated catch block#
                    MessageBox.Show(e.Message);
                    return;
                }
                MySession.myConsole.printf("\t%d...%n", i++);
            }

            if (i < SignInMgr.DELAY_CNT)
            {
                // Successful Logout
                MySession.myConsole.printf("%s: %s logged out (IP Addr %s:%d)%n",
                                    myTutorialTag, mySession.myAccountName,
                                    MySession.IP_ADDR, MySession.PORT_NUM);
            }
            else
            {
                MySession.myConsole.printf("%s: Logout timed out for %s! (IP Addr %s:%d)%n",
                                    myTutorialTag, mySession.myAccountName,
                                    MySession.IP_ADDR, MySession.PORT_NUM);
            }
        }
        /**
         * Common SkypeKit tutorial login processing.
         * <ul>
         *   <li>populates the session's Account instance</li>
         *   <li>writes message to the console indicating success/failure/timeout</li>
         *   <li>writes stack trace if I/O error setting up the transport!</li>
         * </ul>
         *
         * @param myTutorialTag
         * 	Invoker's {@link #MY_CLASS_TAG}.
         * @param mySession
         *	Partially initialized session instance providing access to this sessions's Skype object.
         *
         * @return
         *   <ul>
         * 	   <li>true: success; {@link com.skype.tutorial.util.MySession#myAccount} populated</li>
         *	   <li>false: failure</li>
         *   </ul>
         *
         * @since 1.0
         */
        public bool Login(String myTutorialTag, MySession mySession, String myAccountPword)
        {
            if (mySession.isLoggedIn())
            {
                // Already logged in...
                MySession.myConsole.printf("%s: %s already logged in! (IP Addr %s:%d)%n",
                                    myTutorialTag, mySession.myAccountName,
                                    MySession.IP_ADDR, MySession.PORT_NUM);
                return (true);
            }

            // Issue login request
            MySession.myConsole.printf("%s: Issuing login request%n", myTutorialTag);
            mySession.myAccount.loginWithPassword(myAccountPword, false, true);

            // Loop until AccountListener shows we are logged in or time-out...
            MySession.myConsole.printf("%s: Waiting for login to complete...%n", myTutorialTag);
            int i = 0;
            while ((i < SignInMgr.DELAY_CNT) && (!mySession.isLoggedIn()))
            {
                try
                {
                    Thread.Sleep(SignInMgr.DELAY_INTERVAL);
                }
                catch (Exception e)
                {
                    // TODO Auto-generated catch block
                    MessageBox.Show(e.Message);
                    return (false);
                }
                MySession.myConsole.printf("\t %d...%n", i++);
            }

            if (i < SignInMgr.DELAY_CNT)
            {
                // Successful Login
                MySession.myConsole.printf("%s: %s Logged In (IP Addr %s:%d)%n",
                                    myTutorialTag, mySession.myAccountName,
                                    MySession.IP_ADDR, MySession.PORT_NUM);
                return (true);
            }
            else
            {
                MySession.myConsole.printf("%s: Login timed out for %s! (IP Addr %s:%d)%n",
                                    myTutorialTag, mySession.myAccountName,
                                    MySession.IP_ADDR, MySession.PORT_NUM);
                return (false);
            }
        }