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

📄 impssession.java

📁 Android平台上即时通讯聊天工具源代码。 支持手机聊天。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public Contact getLoginUser() {        return mLoginUser;    }    /**     * Sets the Login information. After login successfully, the login     * information should be saved in the session context so that we can auto     * login when reconnect to the server.     *     * @param loginInfo the login information.     * @throws ImException     */    private void setLoginInfo(LoginInfo loginInfo) throws ImException {        try {            ImpsAddress address = new ImpsUserAddress(loginInfo.getUserName());            mLoginUser = new Contact(address, address.getScreenName());            mLoginInfo = loginInfo;        } catch (IllegalArgumentException e) {            throw new ImException(ImErrorInfo.INVALID_USERNAME,                    "Invalid username");        }    }    /**     * Gets a collection of CIR methods that are supported by both the client     * and the server.     *     * @return a collection of supported CIR methods     */    public List<CirMethod> getSupportedCirMethods() {        return mSupportedCirMethod;    }    public CirMethod getCurrentCirMethod() {        return mCurrentCirMethod;    }    public void setCurrentCirMethod(CirMethod cirMethod) {        mCurrentCirMethod = cirMethod;    }    /**     * Gets the IP address for standalone TCP/IP CIR method.     *     * @return the IP address for standalone TCP/IP CIR method     */    public String getCirTcpAddress() {        return mCirTcpAddress;    }    /**     * Gets the port number for the standalone TCP/IP CIR method.     *     * @return the port number for the standalone TCP/IP CIR method.     */    public int getCirTcpPort() {        return mCirTcpPort;    }    /**     * Gets the minimum time interval (in seconds) that MUST pass before two     * subsequent PollingRequest transactions.     *     * @return the minimum time interval in seconds.     */    public long getServerPollMin() {        return mServerPollMin;    }    /**     * Gets the URL used for standalone HTTP binding of CIR channel.     *     * @return the URL.     */    public String getCirHttpAddress() {        return mCirHttpAddress;    }    /**     * Gets the service tree of the features and functions that the server     * supports.     *     * @return the service tree.     */    public PrimitiveElement getServiceTree() {        return mServiceTree;    }    /**     * Perform client capability negotiation with the server asynchronously.     *     * @param completion Async completion object.     */    public void negotiateCapabilityAsync(AsyncCompletion completion) {        Primitive capabilityRequest = buildCapabilityRequest();        AsyncTransaction tx = new AsyncTransaction(                mConnection.getTransactionManager(), completion) {            @Override            public void onResponseOk(Primitive response) {                extractCapability(response);            }            @Override            public void onResponseError(ImpsErrorInfo error) { }        };        tx.sendRequest(capabilityRequest);    }    /**     * Perform service negotiation with the server asynchronously.     *     * @param completion Async completion object.     */    public void negotiateServiceAsync(AsyncCompletion completion) {        Primitive serviceRequest = buildServiceRequest();        AsyncTransaction tx = new AsyncTransaction(                mConnection.getTransactionManager(), completion) {            @Override            public void onResponseOk(Primitive response) {                mServiceTree = response.getElement(ImpsTags.AllFunctions).getFirstChild();            }            @Override            public void onResponseError(ImpsErrorInfo error) { }        };        tx.sendRequest(serviceRequest);    }    private Primitive buildCapabilityRequest() {        Primitive capabilityRequest = new Primitive(ImpsTags.ClientCapability_Request);        PrimitiveElement list = capabilityRequest.addElement(ImpsTags.CapabilityList);        list.addChild(ImpsTags.ClientType, ImpsClientCapability.getClientType());        list.addChild(ImpsTags.AcceptedContentLength, Integer                .toString(ImpsClientCapability.getAcceptedContentLength()));        list.addChild(ImpsTags.ParserSize,                Integer.toString(ImpsClientCapability.getParserSize()));        list.addChild(ImpsTags.MultiTrans,                Integer.toString(ImpsClientCapability.getMultiTrans()));        // TODO: MultiTransPerMessage is IMPS 1.3        //list.addChild(ImpsTags.MultiTransPerMessage,        //        Integer.toString(ImpsClientCapability.getMultiTransPerMessage()));        list.addChild(ImpsTags.InitialDeliveryMethod,                ImpsClientCapability.getInitialDeliveryMethod());        list.addChild(ImpsTags.ServerPollMin, Long.toString(mServerPollMin));        for(TransportType supportedBear : ImpsClientCapability.getSupportedBearers()) {            list.addChild(ImpsTags.SupportedBearer, supportedBear.toString());        }        for(CirMethod supportedCirMethod : ImpsClientCapability.getSupportedCirMethods()) {            list.addChild(ImpsTags.SupportedCIRMethod, supportedCirMethod.toString());            if (CirMethod.SUDP.equals(supportedCirMethod)) {                list.addChild(ImpsTags.UDPPort,                        Integer.toString(mConnection.getConfig().getUdpPort()));            }        }        return capabilityRequest;    }    /* keep this method package private instead of private to avoid the     * overhead of calling from a inner class.     */    void extractCapability(Primitive capabilityResponse) {        mSupportedCirMethod = new ArrayList<CirMethod>();        PrimitiveElement agreedList = capabilityResponse.getContentElement()                .getFirstChild();        for (PrimitiveElement element : agreedList.getChildren()) {            String tag = element.getTagName();            if (tag.equals(ImpsTags.SupportedCIRMethod)) {                try {                    mSupportedCirMethod.add(CirMethod.valueOf(element.getContents()));                } catch (IllegalArgumentException e) {                    ImpsLog.log("Unrecognized CIR method " + element.getContents());                }            } else if (tag.equals(ImpsTags.TCPAddress)) {                mCirTcpAddress = element.getContents();            } else if (tag.equals(ImpsTags.TCPPort)) {                mCirTcpPort = (int)ImpsUtils.parseLong(element.getContents(),                        DEFAULT_TCP_PORT);            } else if (tag.equals(ImpsTags.ServerPollMin)) {                long defaultPollMin = mConnection.getConfig().getDefaultServerPollMin();                mServerPollMin = ImpsUtils.parseLong(element.getContents(),                        defaultPollMin);                if (mServerPollMin <= 0) {                    mServerPollMin = defaultPollMin;                }            } else if (tag.equals(ImpsTags.CIRHTTPAddress)                    || tag.equals(ImpsTags.CIRURL)) {                // This tag is CIRHTTPAddress in 1.3 and CIRURL in 1.2                mCirHttpAddress = element.getChildContents(ImpsTags.URL);            }        }    }    private Primitive buildServiceRequest() {        Primitive serviceRequest = new Primitive(ImpsTags.Service_Request);        PrimitiveElement functions = serviceRequest.addElement(ImpsTags.Functions);        PrimitiveElement features = functions.addChild(ImpsTags.WVCSPFeat);        features.addChild(ImpsTags.FundamentalFeat);        features.addChild(ImpsTags.PresenceFeat);        features.addChild(ImpsTags.IMFeat);        features.addChild(ImpsTags.GroupFeat);        serviceRequest.addElement(ImpsTags.AllFunctionsRequest, true);        return serviceRequest;    }}

⌨️ 快捷键说明

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