1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.gibberish;
import java.text.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* A Gibberish implementation of a basic telephony operation set.
* @author Yana Stamcheva
*/
public class OperationSetBasicTelephonyGibberishImpl
extends AbstractOperationSetBasicTelephony
implements CallChangeListener
{
private static final Logger logger
= Logger.getLogger(OperationSetBasicTelephonyGibberishImpl.class);
/**
* A reference to the <tt>ProtocolProviderServiceSipImpl</tt> instance
* that created us.
*/
private ProtocolProviderServiceGibberishImpl protocolProvider = null;
/**
* A table mapping call ids against call instances.
*/
private Hashtable<String, Call> activeCalls = new Hashtable<String, Call>();
/**
* Creates an instance of <tt>OperationSetBasicTelephonyGibberishImpl</tt>
* by specifying the corresponding <tt>protocolProvider</tt>
* @param protocolProvider the protocol provider, where this operation set
* is registered
*/
public OperationSetBasicTelephonyGibberishImpl(
ProtocolProviderServiceGibberishImpl protocolProvider)
{
this.protocolProvider = protocolProvider;
}
/**
* Indicates a user request to answer an incoming call from the specified
* CallPeer.
*
* @param peer the call peer that we'd like to answer.
* @throws OperationFailedException with the corresponding code if we
* encounter an error while performing this operation.
*/
public void answerCallPeer(CallPeer peer) throws
OperationFailedException
{
CallPeerGibberishImpl callPeer
= (CallPeerGibberishImpl) peer;
if(peer.getState().equals(CallPeerState.CONNECTED))
{
logger.info("Ignoring user request to answer a CallPeer "
+ "that is already connected. CP:" + peer);
return;
}
callPeer.setState(CallPeerState.CONNECTED, null);
}
/**
* Create a new call and invite the specified CallPeer to it.
*
* @param uri the address of the callee that we should invite to a new
* call.
* @return CallPeer the CallPeer that will represented by
* the specified uri. All following state change events will be
* delivered through that call peer. The Call that this
* peer is a member of could be retrieved from the
* CallParticipatn instance with the use of the corresponding method.
* @throws OperationFailedException with the corresponding code if we
* fail to create the call.
* @throws ParseException if <tt>callee</tt> is not a valid sip address
* string.
*/
public Call createCall(String uri) throws OperationFailedException,
ParseException
{
return createNewCall(uri);
}
/**
* Create a new call and invite the specified CallPeer to it.
*
* @param callee the address of the callee that we should invite to a
* new call.
* @return CallPeer the CallPeer that will represented by
* the specified uri. All following state change events will be
* delivered through that call peer. The Call that this
* peer is a member of could be retrieved from the
* CallParticipatn instance with the use of the corresponding method.
* @throws OperationFailedException with the corresponding code if we
* fail to create the call.
*/
public Call createCall(Contact callee) throws OperationFailedException
{
return createNewCall(callee.getAddress());
}
private Call createNewCall(String address)
{
CallGibberishImpl newCall = new CallGibberishImpl(protocolProvider);
newCall.addCallChangeListener(this);
activeCalls.put(newCall.getCallID(), newCall);
CallPeerGibberishImpl callPeer
= new CallPeerGibberishImpl(address, newCall);
newCall.addCallPeer(callPeer);
this.fireCallEvent(CallEvent.CALL_INITIATED, newCall);
return newCall;
}
/**
* Returns an iterator over all currently active calls.
*
* @return Iterator
*/
public Iterator<Call> getActiveCalls()
{
return activeCalls.values().iterator();
}
/**
* Indicates a user request to end a call with the specified call
* particiapnt.
*
* @param peer the peer that we'd like to hang up on.
* @throws OperationFailedException with the corresponding code if we
* encounter an error while performing this operation.
*/
public void hangupCallPeer(CallPeer peer) throws
OperationFailedException
{
//do nothing if the call is already ended
if (peer.getState().equals(CallPeerState.DISCONNECTED))
{
logger.debug("Ignoring a request to hangup a call peer "
+"that is already DISCONNECTED");
return;
}
CallPeerGibberishImpl callPeer
= (CallPeerGibberishImpl) peer;
logger.info("hangupCallPeer");
callPeer.setState(CallPeerState.DISCONNECTED, null);
CallGibberishImpl call = (CallGibberishImpl) callPeer.getCall();
call.removeCallPeer(callPeer);
}
/**
* Resumes communication with a call peer previously put on hold.
*
* @param peer the call peer to put on hold.
* @throws OperationFailedException if we encounter an error while
* performing this operation
*/
public void putOffHold(CallPeer peer)
throws OperationFailedException
{
this.putOnHold(peer, false);
}
/**
* Puts the specified CallPeer "on hold".
*
* @param peer the peer that we'd like to put on hold.
* @throws OperationFailedException with the corresponding code if we
* encounter an error while performing this operation.
*/
public void putOnHold(CallPeer peer) throws
OperationFailedException
{
this.putOnHold(peer, true);
}
public void callPeerAdded(CallPeerEvent evt)
{
}
public void callPeerRemoved(CallPeerEvent evt)
{
}
public void callStateChanged(CallChangeEvent evt)
{
if(evt.getEventType().equals(CallChangeEvent.CALL_STATE_CHANGE)
&& ((CallState)evt.getNewValue()).equals(CallState.CALL_ENDED))
{
CallGibberishImpl sourceCall = (CallGibberishImpl) this.activeCalls
.remove(evt.getSourceCall().getCallID());
logger.trace( "Removing call " + sourceCall + " from the list of "
+ "active calls because it entered an ENDED state");
fireCallEvent(CallEvent.CALL_ENDED, sourceCall);
}
}
/**
* Sets the mute state of the audio stream being sent to a specific
* <tt>CallPeer</tt>.
* <p>
* The implementation sends silence through the audio stream.
* </p>
*
* @param peer the <tt>CallPeer</tt> who receives the audio
* stream to have its mute state set
* @param mute <tt>true</tt> to mute the audio stream being sent to
* <tt>peer</tt>; otherwise, <tt>false</tt>
*/
public void setMute(CallPeer peer, boolean mute)
{
CallPeerGibberishImpl gibberishPeer = (CallPeerGibberishImpl) peer;
gibberishPeer.setMute(mute);
}
/**
* Puts the specified <tt>CallPeer</tt> on or off hold.
*
* @param peer the <tt>CallPeer</tt> to be put on or off hold
* @param on <tt>true</tt> to have the specified <tt>CallPeer</tt>
* put on hold; <tt>false</tt>, otherwise
* @throws OperationFailedException
*/
private void putOnHold(CallPeer peer, boolean on)
throws OperationFailedException
{
CallPeerGibberishImpl gibberishPeer = (CallPeerGibberishImpl) peer;
CallPeerState state = gibberishPeer.getState();
if (CallPeerState.ON_HOLD_LOCALLY.equals(state))
{
if (!on)
gibberishPeer.setState(CallPeerState.CONNECTED);
}
else if (CallPeerState.ON_HOLD_MUTUALLY.equals(state))
{
if (!on)
gibberishPeer.setState(CallPeerState.ON_HOLD_REMOTELY);
}
else if (CallPeerState.ON_HOLD_REMOTELY.equals(state))
{
if (on)
gibberishPeer.setState(CallPeerState.ON_HOLD_MUTUALLY);
}
else if (on)
{
gibberishPeer.setState(CallPeerState.ON_HOLD_LOCALLY);
}
}
}
|