// Path: src/android/org/eclipse/jetty/websocket/WebSocket.java
// public interface Connection
// {
//     String getProtocol();
//     String getExtensions();
//     void sendMessage(String data) throws IOException;
//     void sendMessage(byte[] data, int offset, int length) throws IOException;
// 
//     /** 
//      * Close the connection with normal close code.
//      */
//     void close();
// 
//     /** 
//      * Close the connection with normal close code.
//      * @param silent Whether telling the app this thing or not
//      */
//     void close(boolean silent);
// 
//     /** Close the connection with specific closeCode and message.
//      * @param closeCode The close code to send, or -1 for no close code
//      * @param message The message to send or null for no message
//      */
//     void close(int closeCode,String message);
// 
//     boolean isOpen();
// 
//     /**
//      * @param ms The time in ms that the connection can be idle before closing
//      */
//     void setMaxIdleTime(int ms);
// 
//     /**
//      * @param size size<0 No aggregation of frames to messages, >=0 max size of text frame aggregation buffer in characters
//      */
//     void setMaxTextMessageSize(int size);
// 
//     /**
//      * @param size size<0 no aggregation of binary frames, >=0 size of binary frame aggregation buffer
//      */
//     void setMaxBinaryMessageSize(int size);
// 
//     /**
//      * @return The time in ms that the connection can be idle before closing
//      */
//     int getMaxIdleTime();
// 
//     /**
//      * Size in characters of the maximum text message to be received
//      * @return size <0 No aggregation of frames to messages, >=0 max size of text frame aggregation buffer in characters
//      */
//     int getMaxTextMessageSize();
// 
//     /**
//      * Size in bytes of the maximum binary message to be received
//      * @return size <0 no aggregation of binary frames, >=0 size of binary frame aggregation buffer
//      */
//     int getMaxBinaryMessageSize();
// }


import android.util.SparseArray;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.cordova.CordovaPreferences;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.websocket.WebSocket.Connection;
import org.eclipse.jetty.websocket.WebSocketClientFactory;
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.knowledgecode.cordova.websocket;




/**
 * Cordova WebSocket Plugin for Android
 * This plugin is using Jetty under the terms of the Apache License v2.0.
 *
 * @author KNOWLEDGECODE <knowledgecode@gmail.com>
 * @version 0.12.2
 */
public class WebSocket extends CordovaPlugin {

    static final String CREATE_TASK = "create";
    static final String SEND_TASK = "send";
    static final String CLOSE_TASK = "close";
    static final String RESET_TASK = "reset";
    static final String DESTROY_TASK = "destroy";

    private WebSocketClientFactory _factory;
// Path: src/android/org/eclipse/jetty/websocket/WebSocket.java
// public interface Connection
// {
//     String getProtocol();
//     String getExtensions();
//     void sendMessage(String data) throws IOException;
//     void sendMessage(byte[] data, int offset, int length) throws IOException;
// 
//     /** 
//      * Close the connection with normal close code.
//      */
//     void close();
// 
//     /** 
//      * Close the connection with normal close code.
//      * @param silent Whether telling the app this thing or not
//      */
//     void close(boolean silent);
// 
//     /** Close the connection with specific closeCode and message.
//      * @param closeCode The close code to send, or -1 for no close code
//      * @param message The message to send or null for no message
//      */
//     void close(int closeCode,String message);
// 
//     boolean isOpen();
// 
//     /**
//      * @param ms The time in ms that the connection can be idle before closing
//      */
//     void setMaxIdleTime(int ms);
// 
//     /**
//      * @param size size<0 No aggregation of frames to messages, >=0 max size of text frame aggregation buffer in characters
//      */
//     void setMaxTextMessageSize(int size);
// 
//     /**
//      * @param size size<0 no aggregation of binary frames, >=0 size of binary frame aggregation buffer
//      */
//     void setMaxBinaryMessageSize(int size);
// 
//     /**
//      * @return The time in ms that the connection can be idle before closing
//      */
//     int getMaxIdleTime();
// 
//     /**
//      * Size in characters of the maximum text message to be received
//      * @return size <0 No aggregation of frames to messages, >=0 max size of text frame aggregation buffer in characters
//      */
//     int getMaxTextMessageSize();
// 
//     /**
//      * Size in bytes of the maximum binary message to be received
//      * @return size <0 no aggregation of binary frames, >=0 size of binary frame aggregation buffer
//      */
//     int getMaxBinaryMessageSize();
// }


// Path: src/android/com/knowledgecode/cordova/websocket/WebSocket.java
import android.util.SparseArray;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.cordova.CordovaPreferences;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.websocket.WebSocket.Connection;
import org.eclipse.jetty.websocket.WebSocketClientFactory;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.knowledgecode.cordova.websocket;




/**
 * Cordova WebSocket Plugin for Android
 * This plugin is using Jetty under the terms of the Apache License v2.0.
 *
 * @author KNOWLEDGECODE <knowledgecode@gmail.com>
 * @version 0.12.2
 */
public class WebSocket extends CordovaPlugin {

    static final String CREATE_TASK = "create";
    static final String SEND_TASK = "send";
    static final String CLOSE_TASK = "close";
    static final String RESET_TASK = "reset";
    static final String DESTROY_TASK = "destroy";

    private WebSocketClientFactory _factory;
    private SparseArray<Connection> _conn;