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

📄 skype.java

📁 基于SKYPE API 控件的开发示例 JSkype is an JNI implementation which enables Java clients to use the Skyp API
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */
    public static Chat[] getAllBookmarkedChats() throws SkypeException {
        return getAllChats("BOOKMARKEDCHATS");
    }

    /**
     * Gets the all chats by the type.
     *
     * @return The all chats by the type
     *
     * @throws SkypeException If there is a problem with the connection or state at the Skype client.
     */
    private static Chat[] getAllChats(String type) throws SkypeException {
        try {
            String command = "SEARCH " + type;
            String responseHeader = "CHATS ";
            String response = Connector.getInstance().execute(command, responseHeader);
            String data = response.substring(responseHeader.length());
            String[] ids = Utils.convertToArray(data);
            Chat[] chats = new Chat[ids.length];
            for (int i = 0; i < ids.length; ++i) {
                chats[i] = Chat.getInstance(ids[i]);
            }
            return chats;
        } catch (ConnectorException ex) {
            Utils.convertToSkypeException(ex);
            return null;
        }
    }
    
    /**
     * Return User based on ID.
     * @param id ID of the User.
     * @return The user found.
     */
    public static User getUser(String id) {
        return User.getInstance(id);
    }

    /**
     * Add a listener for CHATMESSAGE events received from the Skype API.
     * @see ChatMessageListener
     * @param listener the Listener to add.
     * @throws SkypeException when connection has gone bad or ERROR reply.
     */
    public static void addChatMessageListener(ChatMessageListener listener) throws SkypeException {
        Utils.checkNotNull("listener", listener);
        synchronized (chatMessageListenerMutex) {
            chatMessageListeners.add(listener);
            if (chatMessageListener == null) {
                chatMessageListener = new AbstractConnectorListener() {
                    public void messageReceived(ConnectorMessageEvent event) {
                        String message = event.getMessage();
                        if (message.startsWith("CHATMESSAGE ")) {
                            String data = message.substring("CHATMESSAGE ".length());
                            String id = data.substring(0, data.indexOf(' '));
                            String propertyNameAndValue = data.substring(data.indexOf(' ') + 1);
                            String propertyName = propertyNameAndValue.substring(0, propertyNameAndValue.indexOf(' '));
                            if ("STATUS".equals(propertyName)) {
                                String propertyValue = propertyNameAndValue.substring(propertyNameAndValue.indexOf(' ') + 1);
                                ChatMessageListener[] listeners = chatMessageListeners.toArray(new ChatMessageListener[0]);
                                ChatMessage chatMessage = ChatMessage.getInstance(id);
                                if ("SENT".equals(propertyValue)) {
                                    for (ChatMessageListener listener : listeners) {
                                        try {
                                            listener.chatMessageSent(chatMessage);
                                        } catch (Throwable e) {
                                            handleUncaughtException(e);
                                        }
                                    }
                                } else if ("RECEIVED".equals(propertyValue)) {
                                    for (ChatMessageListener listener : listeners) {
                                        try {
                                            listener.chatMessageReceived(chatMessage);
                                        } catch (Throwable e) {
                                            handleUncaughtException(e);
                                        }
                                    }
                                }
                            }
                        }
                    }
                };
                try {
                    Connector.getInstance().addConnectorListener(chatMessageListener);
                } catch (ConnectorException e) {
                    Utils.convertToSkypeException(e);
                }
            }
        }
    }

    /**
     * Remove a listener for CHATMESSAGE events.
     * If the listener is already removed nothing happens.
     * @param listener The listener to remove.
     */
    public static void removeChatMessageListener(ChatMessageListener listener) {
        Utils.checkNotNull("listener", listener);
        synchronized (chatMessageListenerMutex) {
            chatMessageListeners.remove(listener);
            if (chatMessageListeners.isEmpty()) {
                Connector.getInstance().removeConnectorListener(chatMessageListener);
                chatMessageListener = null;
            }
        }
    }

    /**
     * Add a listener for CALL events received from the Skype API.
     * @see CallListener
     * @param listener the listener to add.
     * @throws SkypeException when connection has gone bad or ERROR reply.
     */
    public static void addCallListener(CallListener listener) throws SkypeException {
        Utils.checkNotNull("listener", listener);
        synchronized (callListenerMutex) {
            callListeners.add(listener);
            if (callListener == null) {
                callListener = new AbstractConnectorListener() {
                    public void messageReceived(ConnectorMessageEvent event) {
                        String message = event.getMessage();
                        if (message.startsWith("CALL ")) {
                            String data = message.substring("CALL ".length());
                            String id = data.substring(0, data.indexOf(' '));
                            String propertyNameAndValue = data.substring(data.indexOf(' ') + 1);
                            String propertyName = propertyNameAndValue.substring(0, propertyNameAndValue.indexOf(' '));
                            if ("STATUS".equals(propertyName)) {
                                String propertyValue = propertyNameAndValue.substring(propertyNameAndValue.indexOf(' ') + 1);
                                Call.Status status = Call.Status.valueOf(propertyValue);
                                Call call = Call.getInstance(id);
                                EXIT: if (status == Call.Status.RINGING) {
                                    synchronized(call) {
                                        if (call.isCallListenerEventFired()) {
                                            break EXIT;
                                        }
                                        call.setCallListenerEventFired(true);
                                        CallListener[] listeners = callListeners.toArray(new CallListener[0]);
                                        try {
                                            switch (call.getType()) {
                                                case OUTGOING_P2P:
                                                case OUTGOING_PSTN:
                                                    for (CallListener listener : listeners) {
                                                        try {
                                                            listener.callMaked(call);
                                                        } catch (Throwable e) {
                                                            handleUncaughtException(e);
                                                        }
                                                    }
                                                    break;
                                                case INCOMING_P2P:
                                                case INCOMING_PSTN:
                                                    for (CallListener listener : listeners) {
                                                        try {
                                                            listener.callReceived(call);
                                                        } catch (Throwable e) {
                                                            handleUncaughtException(e);
                                                        }
                                                    }
                                                    break;
                                                default: 
                                                	//Should an exception be thrown?
                                                	break;
                                            }
                                        } catch (Throwable e) {
                                            handleUncaughtException(e);
                                        }
                                    }
                                }
                                call.fireStatusChanged(status);
                            }
                        }
                    }
                };
                try {
                    Connector.getInstance().addConnectorListener(callListener);
                } catch (ConnectorException e) {
                    Utils.convertToSkypeException(e);
                }
            }
        }
    }

    /**
     * Remove a listener for CALL events.
     * If listener is already removed nothing happens.
     * @param listener The listener to add.
     */
    public static void removeCallListener(CallListener listener) {
        Utils.checkNotNull("listener", listener);
        synchronized (callListenerMutex) {
            callListeners.remove(listener);
            if (callListeners.isEmpty()) {
                Connector.getInstance().removeConnectorListener(callListener);
                callListener = null;
            }
        }
    }

    /**
     * Adds a listener for voice mail events received from the Skype API.
     * @param listener the added listener
     * @throws SkypeException if connection is bad or error is returned
     * @see VoicemaListener
     */
    public static void addVoiceMailListener(VoiceMailListener listener) throws SkypeException {
        Utils.checkNotNull("listener", listener);
        synchronized (voiceMailListenerMutex) {
            voiceMailListeners.add(listener);
            if (voiceMailListener == null) {
                voiceMailListener = new AbstractConnectorListener() {
                    public void messageReceived(ConnectorMessageEvent event) {
                        String message = event.getMessage();
                        if (message.startsWith("VOICEMAIL ")) {
                            String data = message.substring("VOICEMAIL ".length());
                            String id = data.substring(0, data.indexOf(' '));
                            String propertyNameAndValue = data.substring(data.indexOf(' ') + 1);
                            String propertyName = propertyNameAndValue.substring(0, propertyNameAndValue.indexOf(' '));
                            if ("TYPE".equals(propertyName)) {
                                String propertyValue = propertyNameAndValue.substring(propertyNameAndValue.indexOf(' ') + 1);
                                VoiceMail.Type type = VoiceMail.Type.valueOf(propertyValue);
                                VoiceMail voiceMail = VoiceMail.getInstance(id);
                                VoiceMailListener[] listeners = voiceMailListeners.toArray(new VoiceMailListener[0]);
                                switch (type) {
                                    case OUTGOING:
                                        for (VoiceMailListener listener : listeners) {
                                            try {
                                                listener.voiceMailMade(voiceMail);
                                            } catch (Throwable e) {
                                                handleUncaughtException(e);
                                            }
                                        }
                                        break;
                                    case INCOMING:
                                        for (VoiceMailListener listener : listeners) {
                                            try {
                                                listener.voiceMailReceived(voiceMail);
                                            } catch (Throwable e) {
                                                handleUncaughtException(e);
                                            }
                                        }
                                        break;
                                    case DEFAULT_GREETING:
                                    case CUSTOM_GREETING:
                                    case UNKNOWN:
                                    default:
                                        // do nothing
                                        break;
                                }
                            }
                        }
                    }
                };
                try {
                    Connector.getInstance().addConnectorListener(voiceMailListener);
                } catch (ConnectorException e) {
                    Utils.convertToSkypeException(e);
                }
            }
        }
    }

    /**
     * Remove a listener for VOICEMAIL events.
     * If listener is already removed nothing happens.
     * @param listener The listener to add.
     */
    public static void removeVoiceMailListener(VoiceMailListener listener) {
        Utils.checkNotNull("listener", listener);
        synchronized (voiceMailListenerMutex) {
            voiceMailListeners.remove(listener);
            if (voiceMailListeners.isEmpty()) {
                Connector.getInstance().removeConnectorListener(voiceMailListener);
                voiceMailListener = null;
            }
        }
    }

    /**
     * Use another exceptionhandler then the default one.
     * @see SkypeExceptionHandler
     * @param handler the handler to use.
     */
    public static void setSkypeExceptionHandler(SkypeExceptionHandler handler) {
        if (handler == null) {
            handler = defaultExceptionHandler;
        }
        exceptionHandler = handler;
    }

    /**
     * Handle uncaught exceptions in a default way.
     * @param e the uncaught exception.
     */
    static void handleUncaughtException(Throwable e) {
        exceptionHandler.uncaughtExceptionHappened(e);
    }

    /** 
     * Private constructor.
     * Please use this object staticly.
     */
    private Skype() {
    }
}

⌨️ 快捷键说明

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