51CTO-Flex+Red5语音视频聊天程序实现.doc
文本预览下载声明
Flex+Red5语音视频聊天程序实现??
2010-12-06 09:30:32|??分类: 程序代码 |??标签:red5?? |字号大中小?订阅
java代码部分
package first;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;
import org.red5.server.adapter.ApplicationAdapter;import org.red5.server.api.IConnection;import org.red5.server.api.IScope;import org.red5.server.api.Red5;import org.red5.server.api.service.IServiceCapableConnection;import org.red5.server.api.so.ISharedObject;
public class Application extends ApplicationAdapter { ??// 属性 ?private IScope appScope; ??private String userName; ?//共享存储在线用户?private ISharedObject listSO;??private MapString,IConnection onlineList = new HashMapString, IConnection();// 在线用户表?//程序运行时志向?public boolean appStart(IScope app) { ??if (!super.appStart(app)) { ????? return false; ??} ??appScope = app; ??return true; ?}?@Override?public boolean appConnect(IConnection arg0, Object[] arg1) {??/**?? *? 用户首次连接server 时触发,检查用户是否重复登录,将用户添加到在线用户表中?? */??String userId=arg0.getClient().getId();??if(!super.appConnect(arg0, arg1)){???return false;??}??if (arg1 != null ) {???userName = (String) arg1[0];??}??if(onlineList.get(userName) != null){???rejectClient(请不要重复登录);???return false;??}??onlineList.put(userName, arg0);??listSO = getSharedObject(appScope, listSO, false);???listSO.setAttribute(userId, userName); ??System.out.println(The user:+userName+,+userName+ logined successfully);??return true;?}?/**? * 通知所有人当前用户登录? * @param params? */?public void getOnloadUser(Object[] params) {?????String clientName = params[0].toString();????if(null == clientName || .equals(clientName)) {???? return ;?? }??//给所有客户端数据?? IScope scope = Red5.getConnectionLocal().getScope();?? Iterator it = scope.getConnections().iterator();?? for (;it.hasNext();) {??? Set connections = (Set)it.next();??? IConnection tempConn = (IConnection)connections.iterator().next();??? if (tempConn instanceof IServiceCapableConnection) {???? IServiceCapab
显示全部