📄 call.java
字号:
/*******************************************************************************
* Copyright (c) 2006 Koji Hisano <hisano@gmail.com> - UBION Inc. Developer
* Copyright (c) 2006 UBION Inc. <http://www.ubion.co.jp/>
*
* Copyright (c) 2006 Skype Technologies S.A. <http://www.skype.com/>
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Common Public License v1.0 which accompanies
* this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Koji Hisano - initial API and implementation
* Bart Lamot - good javadocs
******************************************************************************/
package com.skype;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.skype.connector.Connector;
import com.skype.connector.ConnectorException;
/**
* This class implements all features of the SKYPE CALL protocol.
* @see <a href="https://developer.skype.com/Docs/ApiDoc/Making_and_managing_voice_calls">Skype API reference - Commands - Making and managing voice calls</a>
* @see <a href="https://developer.skype.com/Docs/ApiDoc/Making_and_managing_video_calls">Skype API reference - Commands - Making and managing video calls</a>
* @see <a href="https://developer.skype.com/Docs/ApiDoc/CALL_object">Skype API reference - Objects - CALL object</a>
* @see <a href="https://developer.skype.com/Docs/ApiDoc/Call_notifications">Skype API reference - Notifications - Object notifications - Call notifications</a>
* @author Koji Hisano
*/
public final class Call extends SkypeObject {
/**
* Collection of Call objects, filled at runtime when new CALL objects are created (by events or by application).
*/
private static final Map<String, Call> calls = new HashMap<String, Call>();
/**
* Returns the Call object by the specified id.
* @param id whose associated Call object is to be returned.
* @return Call object with ID == id.
*/
static Call getInstance(final String id) {
synchronized(calls) {
if (!calls.containsKey(id)) {
calls.put(id, new Call(id));
}
return calls.get(id);
}
}
/**
* Enumeration of call status types.
*/
public enum Status {
/**
* UNPLACED - call was never placed.
* ROUTING - call is currently being routed.
* EARLYMEDIA - with pstn it is possible that before a call is established, early media is played. For example it can be a calling tone or a waiting message such as all operators are busy.
* FAILED - call failed - try to get a FAILUREREASON for more information.
* RINGING - currently ringing.
* INPROGRESS - call is in progress.
* ONHOLD - call is placed on hold.
* FINISHED - call is finished.
* MISSED - call was missed.
* REFUSED - call was refused.
* BUSY - destination was busy.
* CANCELLED (Protocol 2).
* VM_BUFFERING_GREETING - voicemail greeting is being downloaded.
* VM_PLAYING_GREETING - voicemail greeting is being played.
* VM_RECORDING - voicemail is being recorded.
* VM_UPLOADING - voicemail recording is finished and uploaded into server.
* VM_SENT - voicemail has successfully been sent.
* VM_CANCELLED - leaving voicemail has been cancelled.
* VM_FAILED - leaving voicemail failed; check FAILUREREASON.
*/
UNPLACED, ROUTING, EARLYMEDIA, FAILED, RINGING, INPROGRESS, ONHOLD, FINISHED, MISSED, REFUSED, BUSY, CANCELLED, VM_BUFFERING_GREETING, VM_PLAYING_GREETING, VM_RECORDING, VM_UPLOADING, VM_SENT, VM_CANCELLED, VM_FAILED
}
/**
* Enumeration of CALL types.
*/
public enum Type {
/**
* INCOMING_PSTN - incoming call from PSTN.
* OUTGOING_PSTN - outgoing call to PSTN.
* INCOMING_P2P - incoming call from P2P.
* OUTGOING_P2P - outgoing call to P2P.
*/
INCOMING_PSTN, OUTGOING_PSTN, INCOMING_P2P, OUTGOING_P2P;
}
/**
* Enumeration of video status types.
*/
public enum VideoStatus {
/**
* NOT_AVAILABLE - The user does not have video capability because video is disabled or a webcam is unplugged).
* AVAILABLE - The user is video-capable but the video is not running (can occur during a manual send).
* STARTING - The video is sending but is not yet running at full speed.
* REJECTED - The receiver rejects the video feed (can occur during a manual receive).
* RUNNING - The video is actively running.
* STOPPING - The active video is in the process of stopping but has not halted yet.
* PAUSED - The video call is placed on hold.
*/
NOT_AVAILABLE, AVAILABLE, STARTING, REJECTED, RUNNING, STOPPING, PAUSED
}
/**
* Enumeration of DTMF types.
*/
public enum DTMF {
TYPE_0, TYPE_1, TYPE_2, TYPE_3, TYPE_4, TYPE_5, TYPE_6, TYPE_7, TYPE_8, TYPE_9, TYPE_SHARP('#'), TYPE_ASTERISK('*');
private final char type;
DTMF() {
type = name().charAt("TYPE_".length());
}
DTMF(char type) {
this.type = type;
}
char getType() {
return type;
}
}
/**
* Enumeration of video enabled status types.
*/
private enum VideoEnabledStatus {
/**
* VIDEO_NONE.
* VIDEO_SEND_ENABLED.
* VIDEO_RECV_ENABLED.
* VIDEO_BOTH_ENABLED.
*/
VIDEO_NONE, VIDEO_SEND_ENABLED, VIDEO_RECV_ENABLED, VIDEO_BOTH_ENABLED;
}
/**
* The CALL objects ID.
*/
private final String id;
/**
* List of listeners to CALL objects.
*/
private final List<CallStatusChangedListener> listeners = Collections.synchronizedList(new ArrayList<CallStatusChangedListener>());
/**
* Previous status.
*/
private Status oldStatus;
/**
* Exception handler to CALL object.
*/
private SkypeExceptionHandler exceptionHandler;
/**
* Flag for fired events.
*/
private boolean isCallListenerEventFired;
/**
* Consturctor.
* Use getInstance instead of constructor.
* @param newId the ID of this CALL object.
*/
private Call(final String newId) {
this.id = newId;
}
/**
* Use the CALL ID as the hashcode.
* @return id.
*/
public int hashCode() {
return id.hashCode();
}
/**
* Implement a equals check method.
* Check ID field for equalness.
* @param compared the object to compare to.
* @return true if objects are equal.
*/
public boolean equals(final Object compared) {
if (compared instanceof Call) {
return id.equals(((Call) compared).id);
}
return false;
}
/**
* Return the ID of the CALL object.
* @return the ID.
*/
public String getId() {
return id;
}
/**
* Add a listener for the Status field.
* The listener will be triggered every time the status of this CALL object is changed.
* @param listener the listener to add.
*/
public void addCallStatusChangedListener(final CallStatusChangedListener listener) {
Utils.checkNotNull("listener", listener);
listeners.add(listener);
}
/**
* Remove a listener to the status of this CALL object.
* If listener is already removed nothing happens.
* @param listener the listener to remove.
*/
public void removeCallStatusChangedListener(final CallStatusChangedListener listener) {
Utils.checkNotNull("listener", listener);
listeners.remove(listener);
}
/**
* Trigger all Status listeners because the status of this CALL object has changed.
* @param status the new status.
*/
void fireStatusChanged(final Status status) {
CallStatusChangedListener[] listeners = this.listeners.toArray(new CallStatusChangedListener[0]);
if (status == oldStatus) {
return;
}
oldStatus = status;
for (CallStatusChangedListener listener : listeners) {
try {
listener.statusChanged(status);
} catch (Throwable e) {
Utils.handleUncaughtException(e, exceptionHandler);
}
}
}
/**
* Put this CALL on hold.
* @throws SkypeException when connection is bad.
*/
public void hold() throws SkypeException {
setStatus("ONHOLD");
}
/**
* Resume an on hold CALL.
* @throws SkypeException when connection is bad.
*/
public void resume() throws SkypeException {
setStatus("INPROGRESS");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -