📄 serverclass.java
字号:
Vector crashedUsers = mClientInformer.informUser(Constants.CLEAR_YES_NO,null,
mUserManager.getUserConfigList(),outputStreamTable,null);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
return result;
}
/**
* This method is used by the user to raise hand.
*
* @returns <code>true</code> if the user successfully raising a hand
* <code>false</code> if not.
*/
public boolean raiseHand(String userName) throws RemoteException
{
boolean result = false;
Hashtable table = mUserManager.getUserConfigList();
UserConfig userConfig = (UserConfig) table.get(userName);
if(userConfig.getHandOrder() != 0)
return result;
result = mUserManager.raiseHand(userName);
Vector crashedUsers = mClientInformer.informUser(Constants.RAISE_HAND,userName,
mUserManager.getUserConfigList(),outputStreamTable,userConfig);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
return result;
}
/**
* This method is used by the user to put hand down.
* @returns <code>true</code> if the user successfully putting down a hand
* <code>false</code> if not.
*/
public boolean lowerHand(String userName) throws RemoteException
{
boolean result = mUserManager.lowerHand(userName);
Vector crashedUsers = mClientInformer.informUser(Constants.LOWER_HAND,userName,
mUserManager.getUserConfigList(),outputStreamTable,null);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
return result;
}
/**
* This method is used by the presenter to put all hands down.
*
* @returns <code>true</code> if the user successfully putting down all hands
* <code>false</code> if not.
*/
public boolean lowerAllHands() throws RemoteException
{
boolean result = mUserManager.lowerAllHands();
Vector crashedUsers = mClientInformer.informUser(Constants.LOWER_ALL_HANDS,null,
mUserManager.getUserConfigList(),outputStreamTable,null);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
return result;
}
/**
* This method is used by the user to step in or step out.
*
*/
public void stepInOut(String userName) throws RemoteException{
Hashtable table = mUserManager.getUserConfigList();
UserConfig userConfig = (UserConfig) table.get(userName);
mUserManager.stepInOut(userName);
Vector crashedUsers = mClientInformer.informUser(Constants.STEP_IN_OUT,userName,
mUserManager.getUserConfigList(),outputStreamTable,userConfig);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
}
/**
* This method is used by the user to send the feed back.
*
* @param pace The user's opinion of the pace
* @param clarity The clarity of the voice
*/
public void sendFeedback(int pace, int clarity) throws RemoteException{
// int n = 0;
switch(pace){
case Constants.PACE_TOO_FAST:
mPaceValues[0]++;
break;
case Constants.PACE_JUST_RIGHT:
mPaceValues[1]++;
break;
case Constants.PACE_TOO_SLOW:
mPaceValues[2]++;
break;
}
switch(clarity){
case Constants.CLARITY_CLEAR:
mClarityValues[0]++;
break;
case Constants.CLARITY_JUST_RIGHT:
mClarityValues[1]++;
break;
case Constants.CLARITY_CONFUSING:
mClarityValues[2]++;
break;
}
}
/**
* This method is used by the presenter to receive the feed back.
*
* @return a vector of the values of the feed back.
*/
public int [] receiveFeedback() throws RemoteException{
int feedback[] = {mPaceValues[0],mPaceValues[1],mPaceValues[2],
mClarityValues[0],mClarityValues[1],mClarityValues[2]};
return feedback;
}
/**
* This method is used by the presenter to clear the feed back.
*
* @returns <code>true</code> if the user successfully clearing feed back
* <code>false</code> if not.
*/
public boolean clearFeedback() throws RemoteException{
mPaceValues[0]=mPaceValues[1]=mPaceValues[2]=0;
mClarityValues[0]=mClarityValues[1]=mClarityValues[2]=0;
return true;
}
/**
* This method is used by the presenter to receive the pace feed back.
*
* @return a vector of the values of the pace feed back.
*/
public int [] receivePaceFeedback() throws RemoteException
{
return mPaceValues;
}
/**
* This method is used by the presenter to receive the clarity feed back.
*
* @return a vector of the values of the clarity feed back.
*/
public int [] receiveClarityFeedback() throws RemoteException
{
return mClarityValues;
}
/**
* This function delivers chat messages.
*
* @param msg The chat message
* @param sender The sender of msg
* @param receiver The receiver of msg
* @param type The type of msg(public or private)
*/
public void broadcastMessage(String msg,String sender,String receiver,Integer type) throws RemoteException{
Vector m = new Vector();
m.addElement(msg);
m.addElement(sender);
m.addElement(receiver);
m.addElement(type);
mChatMessages.addElement(m);
Hashtable table = mUserManager.getUserConfigList();
UserConfig userConfig = (UserConfig) table.get(sender);
Vector crashedUsers = null;
if(type.intValue() == 0){
crashedUsers = mClientInformer.informUser(Constants.PUBLIC_CHAT,msg,
mUserManager.getUserConfigList(),
outputStreamTable,userConfig);
}
else if(type.intValue() == 1){
UserConfig recConfig = (UserConfig) table.get(receiver);
Hashtable recTable =new Hashtable();
recTable.put(receiver,recConfig);
crashedUsers = mClientInformer.informUser(Constants.PRIVATE_CHAT,msg,
recTable,outputStreamTable, userConfig);
}
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
}
/**
* This method is used to get a hashtable of the users whose current category are presenter.
*
* @return a hashtable of the users.
*/
private Hashtable getPresenter(){
Hashtable table = mUserManager.getUserConfigList();
Enumeration e = table.elements();
UserConfig next = null;
while (e.hasMoreElements()) {
next = (UserConfig) e.nextElement();
if(next.getUserCategory() == Constants.PRESENTER){
table.put(next.getUserName(),next);;
}
}
return table;
}
/**
* This function checks if the microphone is locked
*
* @param userName The user name
*
* @returns <code>true</code> if microphone is locked
* <code>false</code> if not.
*/
public boolean isMicLocked(String userName) throws RemoteException
{
Hashtable table = mUserManager.getUserConfigList();
UserConfig userConfig = (UserConfig) table.get(userName);
return userConfig.getMicAvailable();
}
/**
* This function locks the microphone is locked
*
* @param userName The user name
*
* @returns <code>true</code> if the user successfully locking the microphone
* <code>false</code> if not.
*/
public boolean lockMic(String userName) throws RemoteException
{
locker = userName;
Hashtable table = mUserManager.getUserConfigList();
UserConfig userConfig = (UserConfig) table.get(userName);
boolean result = mUserManager.lockMic(userName);
Vector crashedUsers = mClientInformer.informUser(Constants.LOCK_MIC,userName,
mUserManager.getUserConfigList(),outputStreamTable,userConfig);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
if(result) lockedMic = true;
return result;
}
/**
* This function unlocks the microphone is locked
*
* @param userName The user name
*
* @returns <code>true</code> if the user successfully unlocking the microphone
* <code>false</code> if not.
*/
public boolean unLockMic(String userName) throws RemoteException
{
locker = "";
Hashtable table = mUserManager.getUserConfigList();
UserConfig userConfig = (UserConfig) table.get(userName);
boolean result = mUserManager.unlockMic(userName);
Vector crashedUsers = mClientInformer.informUser(Constants.UNLOCK_MIC,userName,
mUserManager.getUserConfigList(),outputStreamTable,userConfig);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
if(result) lockedMic = false;
return result;
}
/**
* This method is used by the presenter to give the microphone to a user.
*/
public void giveMicToNext() throws RemoteException{
boolean result = mUserManager.giveMicToNext();
if(result){
Vector crashedUsers = mClientInformer.informUser(Constants.NEXT_MIC,null,
mUserManager.getUserConfigList(),outputStreamTable,null);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
lockedMic = true;
}
}
/**
* This method is used to get the name of the user locking the micronphone.
*
* @return The user name locking the micronphone.
*/
public String getMicLocker() throws RemoteException{
return this.locker;
}
/**
* This method is used to start audio relay.
*
* @param userName The user name
*
* @return true if successfully starting audio relay, false for not.
*/
public boolean startAudioRelay(String usrName) throws RemoteException
{
return false;
}
/**
* This method is used to stop audio relay.
*
* @param userName The user name
*
* @return true if successfully stopping audio relay, false for not.
*/
public boolean stopAudioRelay(String userName) throws RemoteException
{
return false;
}
/**
* This method is used to remove the crashed users from the user configs hashtable.
*/
private void removeCrashedUsers(Vector userList) {
Hashtable table = mUserManager.getUserConfigList();
Enumeration e = userList.elements();
while (e.hasMoreElements()) {
String userName = (String) e.nextElement();
UserConfig userConfig = (UserConfig) table.get(userName);
mUserManager.logoutUser(userName);
if (lockedMic && (userConfig.getMicAvailable())) {
lockedMic = false;
}
}
}
/**
* This method changes the presenter URL and let the users know about it
*
* @param newURL The URL to which presenter has moved
*/
public void presenterURLChanged(String newURL) throws RemoteException
{
if (mUserManager.isInSession()) {
mClientInformer.notifyURLChanged(mUserManager.getContentManagerTable(),
mUserManager.getUserConfigList(), newURL,outputStreamTable);
}
}
/**
* This method when called creates a new socket to receive a file.
*
* @param strURL The URL Name with which to store the new file
* @param ClientAddress The host to receive files from
* @param fileUploadPort The port on which the host (Client is listening)
*
* @return boolean pass/fail status
*/
public boolean startReceivingFile(String strURL, InetAddress ClientAddress,
int fileUploadPort) throws RemoteException
{
if (strURL.indexOf("http:") != -1)
{
mUserManager.addURL(strURL);
Vector crashedUsers = mClientInformer.addToContentManager(
mUserManager.getContentManagerTable(),mUserManager.getUserConfigList(),
strURL,outputStreamTable);
if (crashedUsers != null) {
removeCrashedUsers(crashedUsers);
}
}
else
{
//In this case ReceiveFile adds file in UserManger and informs Clients.
if (strURL.indexOf("file:") != -1)
{
ReceiveFile rf = new ReceiveFile(strURL, ClientAddress,
fileUploadPort, mUserManager, mClientInformer,
outputStreamTable);
rf.start();
}
}
return true;
}
/**
* get the URL Table
*
* @return a Hashtable containing uploaded file URLs
*/
public Hashtable getURLTable() throws RemoteException
{
return mUserManager.getContentManagerTable();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -