Added some comments.

This commit is contained in:
Guillaume Beraudo 2010-11-05 17:29:11 +01:00
parent f2f81ad287
commit 7db8fc8c96
5 changed files with 63 additions and 21 deletions

View file

@ -1,7 +1,6 @@
/*
linphone
TutorialBuddyStatus
Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -66,10 +65,11 @@ public class TutorialBuddyStatus implements LinphoneCoreListener {
public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {
write("["+lf.getAddress().getUserName()+"] wants to see your status, accepting");
lf.edit();
lf.setIncSubscribePolicy(SubscribePolicy.SPAccept);
lf.done();
lf.edit(); // start editing friend
lf.setIncSubscribePolicy(SubscribePolicy.SPAccept); // accept incoming subscription request for this friend
lf.done(); // commit change
try {
// add this new friend to the buddy list
lc.addFriend(lf);
} catch (LinphoneCoreException e) {
write("Error while adding friend [" + lf.getAddress().getUserName() + "] to linphone in the callback");
@ -104,6 +104,7 @@ public class TutorialBuddyStatus implements LinphoneCoreListener {
// Create tutorial object
TutorialBuddyStatus tutorial = new TutorialBuddyStatus();
try {
// takes sip uri identity from the command line arguments
String userSipAddress = args[1];
tutorial.launchTutorial(userSipAddress);
} catch (Exception e) {
@ -123,29 +124,34 @@ public class TutorialBuddyStatus implements LinphoneCoreListener {
try {
// Create friend address
// Create friend object from string address
LinphoneFriend lf = lcFactory.createLinphoneFriend(sipAddress);
if (lf == null) {
write("Could not create friend; weird SIP address?");
return;
}
// configure this friend to emit SUBSCRIBE message after being added to LinphoneCore
lf.enableSubscribes(true);
// accept incoming subscription request for this friend
lf.setIncSubscribePolicy(SubscribePolicy.SPAccept);
try {
// add my friend to the buddy list, initiate SUBSCRIBE message
lc.addFriend(lf);
} catch (LinphoneCoreException e) {
write("Error while adding friend " + lf.getAddress().getUserName() + " to linphone");
return;
}
// set my status to online
lc.setPresenceInfo(0, null, OnlineStatus.Online);
// main loop for receiving notifications and doing background linphonecore work
running = true;
while (running) {
lc.iterate();
lc.iterate(); // first iterate initiates subscription
try{
Thread.sleep(50);
} catch(InterruptedException ie) {
@ -155,13 +161,16 @@ public class TutorialBuddyStatus implements LinphoneCoreListener {
}
// change my presence status to offline
lc.setPresenceInfo(0, null, OnlineStatus.Offline);
// just to make sure new status is initiate message is issued
lc.iterate();
lf.edit();
lf.enableSubscribes(false);
lf.done();
lc.iterate();
lf.edit(); // start editing friend
lf.enableSubscribes(false); // disable subscription for this friend
lf.done(); // commit changes triggering an UNSUBSCRIBE message
lc.iterate(); // just to make sure unsubscribe message is issued
} finally {

View file

@ -1,7 +1,6 @@
/*
linphone
TutorialChatRoom.java
Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -85,6 +84,7 @@ public class TutorialChatRoom implements LinphoneCoreListener {
public static void main(String[] args) {
// Check tutorial was called with the right number of arguments
// Takes the sip uri identity from the command line arguments
if (args.length != 1) {
throw new IllegalArgumentException("Bad number of arguments");
}
@ -108,7 +108,10 @@ public class TutorialChatRoom implements LinphoneCoreListener {
LinphoneCore lc = LinphoneCoreFactory.instance().createLinphoneCore(this);
try {
// Next step is to create a chat room
LinphoneChatRoom chatRoom = lc.createChatRoom(destinationSipAddress);
// Send message
chatRoom.sendMessage("Hello world");
// main loop for receiving notifications and doing background linphonecore work

View file

@ -1,7 +1,6 @@
/*
linphone
TutorialHelloWorld.java
Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,30 @@
/*
TutorialNotifier.java
Copyright (C) 2010 Belledonne Communications SARL
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 2
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 for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core.tutorials;
/**
* Notify to the standard output.
* Subclass to define another text output.
*
* @author Guillaume Beraudo
*
*/
public class TutorialNotifier {
public void notify(String s) {

View file

@ -1,7 +1,6 @@
/*
linphone
TutorialRegistration.java
Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -93,7 +92,9 @@ public class TutorialRegistration implements LinphoneCoreListener {
// Create tutorial object
TutorialRegistration tutorial = new TutorialRegistration();
try {
// takes sip uri identity from the command line arguments
String userSipAddress = args[1];
// takes password from the command line arguments
String userSipPassword = args[2];
tutorial.launchTutorial(userSipAddress, userSipPassword);
} catch (Exception e) {
@ -113,16 +114,20 @@ public class TutorialRegistration implements LinphoneCoreListener {
try {
// Parse identity
LinphoneAddress address = lcFactory.createLinphoneAddress(sipAddress);
String username = address.getUserName();
String domain = address.getDomain();
if (password != null) {
// create authentication structure from identity and add to linphone
lc.addAuthInfo(lcFactory.createAuthInfo(username, password, null));
}
// create proxy config
LinphoneProxyConfig proxyCfg = lcFactory.createProxyConfig(sipAddress, domain, null, true);
lc.addProxyConfig(proxyCfg);
lc.addProxyConfig(proxyCfg); // add it to linphone
lc.setDefaultProxyConfig(proxyCfg);
@ -131,7 +136,7 @@ public class TutorialRegistration implements LinphoneCoreListener {
// main loop for receiving notifications and doing background linphonecore work
running = true;
while (running) {
lc.iterate();
lc.iterate(); // first iterate initiates registration
try{
Thread.sleep(50);
} catch(InterruptedException ie) {
@ -141,6 +146,7 @@ public class TutorialRegistration implements LinphoneCoreListener {
}
// Automatic unregistration on exit
} finally {