⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phonemodel.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 */
private boolean getSendDtmf() {
	return this.sendDtmf;
}
/**
 * Get the state of the phone.
 * Creation date: (2000-02-28 12:42:27)
 * @author: Richard Deadman
 * @return int
 */
public int getState() {
	return state;
}
/**
 * Hold the phone
 */
public boolean hold() {
	if (this.getState() == RawPhone.ACTIVE) {
		Leg l = this.getActiveLeg();
		this.setHeldLeg(l);
		this.setActiveLeg(null);
		this.setState(RawPhone.HOLD);
		this.onHold();
		return true;
	}
	return false;
}
/**
 * idle method comment.
 */
public void idle() {
	this.setState(PhoneModel.IDLE);
	this.getListener().idle();
}
/**
 * inCall method comment.
 */
public void inCall(Leg newLeg) {
	switch (newLeg.getState()) {
		case Leg.ALERTING: {
			this.setState(PhoneModel.RINGING);
			break;
		}
		case Leg.INPROGRESS:
		case Leg.CONNECTED: {
			this.setState(PhoneModel.ACTIVE);
			break;
		}
		case Leg.IDLE: {
			this.setState(PhoneModel.DIALTONE);
			break;
		}
		default: {
			System.err.println("Error in Call Leg state machine: adding leg in state " + newLeg.getState());
			return;
		}
	}
	this.getListener().inCall(newLeg);
}
/**
 * onHold method comment.
 */
public boolean onHold() {
	this.setState(PhoneModel.HOLD);
	// notify framework
	String endpoint = this.getAddress();
	this.getManager().getListener().terminalConnectionHeld(this.getHeldLeg().getCall(),
		endpoint,
		endpoint,
		Event.CAUSE_NORMAL);
	return this.getListener().onHold();
}
/**
 * Act on incoming DTMF signals
 */
public void receiveDTMF(String digits) {
	// store them for future retrieval
	StringBuffer sb = this.getDigitBucket();
	synchronized (sb) {
		sb.append(digits);
	}
	// act on any RTCs?

	// act on resource properties
	if (this.getSendDtmf()) {
		this.getManager().getListener().mediaSignalDetectorDetected(this.getAddress(),
			net.sourceforge.gjtapi.media.SymbolConvertor.convert(digits));
	}

	// notify views
	this.getListener().receiving(digits);
}
/**
 * receiving method comment.
 */
public void receiving(String digits) {
	this.getListener().receiving(digits);
}
/**
 * drop method comment.
 */
public boolean remove(Leg leg) {
	boolean flag = false;
	Leg active = this.getActiveLeg();
	Leg held = this.getHeldLeg();
	if (active != null && active.equals(leg)) {
		this.setActiveLeg(null);
		flag = true;
	}
	if (held != null && held.equals(leg)) {	// just in case it's on both
		this.setHeldLeg(null);
		flag = true;
	}
	
	if (flag) {
		// notify any listener's of the new state
		if (this.getActiveLeg() == null && this.getHeldLeg() == null) {
			this.idle();
		} else if (this.getActiveLeg() != null) {
			this.connected();
		} else	// held must still exist -- go into consult mode
			this.consult();
	}
	
	return true;
}
/**
 * reportDTMF method comment.
 */
public String reportDTMF(int num) {
	StringBuffer sb = this.getDigitBucket();
	String results;
	synchronized (sb) {
		int len = sb.length();
		num = num > len ? len : num;
		results = sb.substring(0, num);
		sb.delete(0, num);
	}
	return results;
}
/**
 * ringing method comment.
 */
public void ringing() {
	this.setState(PhoneModel.RINGING);
	this.getListener().ringing();
}
/**
 * Notes whether to send detected DTMF signals as events
 * Creation date: (2000-05-10 13:57:17)
 * @author: Richard Deadman
 * @param flag if true, send the events, otherwise suppress them
 */
public void sendDetectedDtmf(boolean flag) {
	this.sendDtmf = flag;
}
/**
 * Send the DTMF out to all legs of the call.
 */
public void sendDTMF(java.lang.String msg) {
	this.getActiveLeg().getCall().sendDTMF(msg);
	this.getListener().sending();
}

/**
 * sending method comment.
 */
public void sending() {
	this.getListener().sending();
}
/**
 * Insert the method's description here.
 * Creation date: (2000-02-28 12:43:03)
 * @author: 
 * @param newActiveCall net.sourceforge.gjtapi.raw.emulator.RawCall
 */
private void setActiveLeg(Leg newActiveLeg) {
	activeCall = newActiveLeg;
}
/**
 * Insert the method's description here.
 * Creation date: (2000-02-28 12:45:43)
 * @author: 
 * @param newAddress java.lang.String
 */
private void setAddress(java.lang.String newAddress) {
	address = newAddress;
}
/**
 * Set a call leg as on hold
 * Creation date: (2000-02-28 12:43:28)
 * @author: Richard Deadman
 * @param newHeldLeg The new leg that is on hold
 */
private void setHeldLeg(Leg newHeldLeg) {
	heldCall = newHeldLeg;
}
/**
 * Set the RawListener that receives my events.
 * Creation date: (2000-03-01 9:46:36)
 * @author: Richard Deadman
 * @param newListener A listener interface for Raw events.
 */
private void setListener(PhoneListener newListener) {
	listener = newListener;
}
/**
 * Insert the method's description here.
 * Creation date: (2000-02-29 13:50:27)
 * @author: 
 * @param newManager net.sourceforge.gjtapi.raw.emulator.PhoneManager
 */
private void setManager(PhoneManager newManager) {
	manager = newManager;
}
/**
 * Set the Player thread associated with the phone.
 * Creation date: (2000-05-10 15:27:55)
 * @author: Richard Deadman
 * @param newPlayThread A Thread playing audio on the active call.
 */
void setPlayThread(java.lang.Thread newPlayThread) {
	playThread = newPlayThread;
}
/**
 * Set the Recorder thread associated with the phone.
 * Creation date: (2000-05-10 15:27:55)
 * @author: Richard Deadman
 * @param newPlayThread A Thread recording audio from the active call.
 */
void setRecordThread(Thread newRecordThread) {
	this.recordThread = newRecordThread;
}
/**
 * Change the state of the Terminal/Address
 * Creation date: (2000-02-28 12:42:27)
 * @author: Richard Deadman
 * @param newState int
 */
private void setState(int newState) {
	state = newState;
}
/**
 * setStatus method comment.
 */
public void setStatus(String status) {
	System.out.println(this.getAddress() + " received " + status);
}
/**
 * swap method comment.
 */
public void swap(Leg oldLeg, Leg newLeg) {
	if (activeCall != null && activeCall.equals(oldLeg))
		this.setActiveLeg(newLeg);
	else if (heldCall != null && heldCall.equals(oldLeg))
		this.setHeldLeg(newLeg);
}
/**
 * swap method comment.
 */
public Leg swap(RawCall newCall, Leg oldLeg, TelephonyListener sink) {
	Leg active = this.getActiveLeg();
	Leg held = this.getHeldLeg();
	Leg l = null;
	// test if we need to merge the active and held calls
	if (held != null && held.getCall().equals(newCall)) {
		l = held;
		this.setActiveLeg(l);
		this.setHeldLeg(null);
		this.setState(PhoneModel.ACTIVE);
	}
	// test if we need to merge the active and held calls
	if (active != null && active.getCall().equals(newCall)) {
		l = active;
		this.setHeldLeg(null);
		this.setState(PhoneModel.ACTIVE);
	}
	if (l == null)
		l = new Leg(newCall, oldLeg, sink);
	return l;
}
/**
 * unHold method comment.
 */
public boolean unHold() {
	if (this.getState() == RawPhone.HOLD) {
		Leg l = this.getHeldLeg();
		this.setActiveLeg(l);
		this.setHeldLeg(null);
		this.setState(RawPhone.ACTIVE);
		// notify framework
		String endpoint = this.getAddress();
		this.getManager().getListener().terminalConnectionTalking(l.getCall(),
			endpoint,
			endpoint,
			Event.CAUSE_NORMAL);
		return true;
	}
	return false;
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -