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.LinphoneCall.State;
24 import org.linphone.core.LinphoneCallStats;
25 import org.linphone.core.LinphoneChatMessage;
26 import org.linphone.core.LinphoneChatRoom;
27 import org.linphone.core.LinphoneCore;
28 import org.linphone.core.LinphoneCore.EcCalibratorStatus;
29 import org.linphone.core.LinphoneCore.GlobalState;
30 import org.linphone.core.LinphoneCore.RegistrationState;
31 import org.linphone.core.LinphoneCoreException;
32 import org.linphone.core.LinphoneCoreFactory;
33 import org.linphone.core.LinphoneCoreListener;
34 import org.linphone.core.LinphoneFriend;
35 import org.linphone.core.LinphoneProxyConfig;
39 * This program is a _very_ simple usage example of liblinphone.
40 * It demonstrates how to send/receive SIP MESSAGE from a sip uri identity
41 * passed from the command line.
43 * Argument must be like sip:jehan@sip.linphone.org .
45 * ex chatroom sip:jehan@sip.linphone.org
46 * just takes a sip-uri as first argument and attempts to call it.
48 * Ported from chatroom.c
50 * @author Guillaume Beraudo
53 public class TutorialChatRoom implements LinphoneCoreListener, LinphoneChatMessage.StateListener {
54 private boolean running;
55 private TutorialNotifier TutorialNotifier;
58 public TutorialChatRoom(TutorialNotifier TutorialNotifier) {
59 this.TutorialNotifier = TutorialNotifier;
62 public TutorialChatRoom() {
63 this.TutorialNotifier = new TutorialNotifier();
68 public void show(LinphoneCore lc) {}
69 public void byeReceived(LinphoneCore lc, String from) {}
70 public void authInfoRequested(LinphoneCore lc, String realm, String username) {}
71 public void displayStatus(LinphoneCore lc, String message) {}
72 public void displayMessage(LinphoneCore lc, String message) {}
73 public void displayWarning(LinphoneCore lc, String message) {}
74 public void globalState(LinphoneCore lc, GlobalState state, String message) {}
75 public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,RegistrationState cstate, String smessage) {}
76 public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
77 public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
78 public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg){}
79 public void callStatsUpdated(LinphoneCore lc, LinphoneCall call, LinphoneCallStats stats) {}
80 public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status,int delay_ms, Object data) {}
81 public void callEncryptionChanged(LinphoneCore lc, LinphoneCall call,boolean encrypted, String authenticationToken) {}
82 public void notifyReceived(LinphoneCore lc, LinphoneCall call, LinphoneAddress from, byte[] event){}
83 public void dtmfReceived(LinphoneCore lc, LinphoneCall call, int dtmf) {}
85 public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {
91 public static void main(String[] args) {
92 // Check tutorial was called with the right number of arguments
93 // Takes the sip uri identity from the command line arguments
94 if (args.length != 1) {
95 throw new IllegalArgumentException("Bad number of arguments");
98 // Create tutorial object
99 TutorialChatRoom tutorial = new TutorialChatRoom();
101 String destinationSipAddress = args[1];
102 tutorial.launchTutorial(destinationSipAddress);
103 } catch (Exception e) {
110 public void launchTutorial(String destinationSipAddress) throws LinphoneCoreException {
112 // First instantiate the core Linphone object given only a listener.
113 // The listener will react to events in Linphone core.
114 LinphoneCore lc = LinphoneCoreFactory.instance().createLinphoneCore(this);
117 // Next step is to create a chat room
118 LinphoneChatRoom chatRoom = lc.createChatRoom(destinationSipAddress);
121 LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage("Hello world");
122 chatRoom.sendMessage(chatMessage, this);
124 // main loop for receiving notifications and doing background linphonecore work
130 } catch(InterruptedException ie) {
131 write("Interrupted!\nAborting");
137 write("Shutting down...");
138 // You need to destroy the LinphoneCore object when no longer used
145 public void stopMainLoop() {
150 private void write(String s) {
151 TutorialNotifier.notify(s);
155 public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr,
156 LinphoneChatMessage message) {
157 write("Message [" + message.getMessage() + "] received from [" + message.getFrom().asString() + "]");
161 public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg,
162 org.linphone.core.LinphoneChatMessage.State state) {
163 write("Sent message [" + msg.getMessage() + "] new state is " + state.toString());