2 TutorialHelloWorld.java
3 Copyright (C) 2010 Belledonne Communications SARL
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package org.linphone.core.tutorials;
21 import org.linphone.core.LinphoneAddress;
22 import org.linphone.core.LinphoneCall;
23 import org.linphone.core.LinphoneCallStats;
24 import org.linphone.core.LinphoneChatMessage;
25 import org.linphone.core.LinphoneChatRoom;
26 import org.linphone.core.LinphoneCore;
27 import org.linphone.core.LinphoneCore.EcCalibratorStatus;
28 import org.linphone.core.LinphoneCoreException;
29 import org.linphone.core.LinphoneCoreFactory;
30 import org.linphone.core.LinphoneCoreListener;
31 import org.linphone.core.LinphoneFriend;
32 import org.linphone.core.LinphoneProxyConfig;
33 import org.linphone.core.LinphoneCall.State;
34 import org.linphone.core.LinphoneCore.GlobalState;
35 import org.linphone.core.LinphoneCore.RegistrationState;
39 * This program is a _very_ simple usage example of liblinphone.
40 * It just takes a sip-uri as first argument and attempts to call it.
42 * Ported from helloworld.c
44 * @author Guillaume Beraudo
47 public class TutorialHelloWorld implements LinphoneCoreListener {
48 private boolean running;
49 private TutorialNotifier TutorialNotifier;
52 public TutorialHelloWorld(TutorialNotifier TutorialNotifier) {
53 this.TutorialNotifier = TutorialNotifier;
56 public TutorialHelloWorld() {
57 this.TutorialNotifier = new TutorialNotifier();
62 public void show(LinphoneCore lc) {}
63 public void byeReceived(LinphoneCore lc, String from) {}
64 public void authInfoRequested(LinphoneCore lc, String realm, String username) {}
65 public void displayStatus(LinphoneCore lc, String message) {}
66 public void displayMessage(LinphoneCore lc, String message) {}
67 public void displayWarning(LinphoneCore lc, String message) {}
68 public void globalState(LinphoneCore lc, GlobalState state, String message) {}
69 public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,RegistrationState cstate, String smessage) {}
70 public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
71 public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
72 public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
73 public void callStatsUpdated(LinphoneCore lc, LinphoneCall call, LinphoneCallStats stats) {}
74 public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status,int delay_ms, Object data) {}
75 public void callEncryptionChanged(LinphoneCore lc, LinphoneCall call,boolean encrypted, String authenticationToken) {}
76 public void notifyReceived(LinphoneCore lc, LinphoneCall call, LinphoneAddress from, byte[] event){}
78 * Call state notification listener
80 public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg){
81 write("State: " + msg);
83 if (State.CallEnd.equals(cstate))
88 public static void main(String[] args) {
89 // Check tutorial was called with the right number of arguments
90 if (args.length != 1) {
91 throw new IllegalArgumentException("Bad number of arguments");
94 // Create tutorial object
95 TutorialHelloWorld helloWorld = new TutorialHelloWorld();
97 String destinationSipAddress = args[1];
98 helloWorld.launchTutorial(destinationSipAddress);
99 } catch (Exception e) {
106 public void launchTutorial(String destinationSipAddress) throws LinphoneCoreException {
108 // First instantiate the core Linphone object given only a listener.
109 // The listener will react to events in Linphone core.
110 LinphoneCore lc = LinphoneCoreFactory.instance().createLinphoneCore(this);
115 // Send the INVITE message to destination SIP address
116 LinphoneCall call = lc.invite(destinationSipAddress);
118 write("Could not place call to " + destinationSipAddress);
122 write("Call to " + destinationSipAddress + " is in progress...");
126 // main loop for receiving notifications and doing background linphonecore work
132 } catch(InterruptedException ie) {
133 write("Interrupted!\nAborting");
140 if (!State.CallEnd.equals(call.getState())) {
141 write("Terminating the call");
142 lc.terminateCall(call);
145 write("Shutting down...");
146 // You need to destroy the LinphoneCore object when no longer used
153 public void stopMainLoop() {
158 private void write(String s) {
159 TutorialNotifier.notify(s);
163 public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr,
164 LinphoneChatMessage message) {
165 // TODO Auto-generated method stub