1.1 --- a/json/src/main/java/org/apidesign/html/json/spi/Proto.java Sun Jan 05 22:37:59 2014 +0100
1.2 +++ b/json/src/main/java/org/apidesign/html/json/spi/Proto.java Sun Jan 05 22:48:45 2014 +0100
1.3 @@ -182,6 +182,18 @@
1.4 return JSON.read(context, modelClass, data);
1.5 }
1.6
1.7 + /** Initializes asynchronous JSON connection to specified URL. The
1.8 + * method returns immediately and later does callback later.
1.9 + *
1.10 + * @param index the callback index to be used when a reply is received
1.11 + * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}.
1.12 + *
1.13 + * @param urlBefore the part of the URL before JSON-P callback parameter
1.14 + * @param urlAfter the rest of the URL or <code>null</code> if no JSON-P is used
1.15 + * @param method method to use for connection to the server
1.16 + * @param data string, number or a {@link Model} generated class to send to
1.17 + * the server when doing a query
1.18 + */
1.19 public void loadJSON(final int index,
1.20 String urlBefore, String urlAfter, String method,
1.21 final Object data
1.22 @@ -200,6 +212,15 @@
1.23 JSON.loadJSON(context, new Rcvr(), urlBefore, urlAfter, method, data);
1.24 }
1.25
1.26 + /** Opens new WebSocket connection to the specified URL.
1.27 + *
1.28 + * @param index the index to use later during callbacks to
1.29 + * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}
1.30 + * @param url the <code>ws://</code> or <code>wss://</code> URL to connect to
1.31 + * @param data data to send to server (usually <code>null</code>)
1.32 + * @return returns a non-null object representing the socket
1.33 + * which can be used when calling {@link #wsSend(java.lang.Object, java.lang.String, java.lang.Object) }
1.34 + */
1.35 public Object wsOpen(final int index, String url, Object data) {
1.36 class WSrcvr extends RcvrJSON {
1.37 @Override
1.38 @@ -225,6 +246,15 @@
1.39 return JSON.openWS(context, new WSrcvr(), url, data);
1.40 }
1.41
1.42 + /** Sends a message to existing socket.
1.43 + *
1.44 + * @param webSocket the socket to send message to
1.45 + * @param url the <code>ws://</code> or <code>wss://</code> URL to connect to,
1.46 + * preferably the same as the one used when the socket was
1.47 + * {@link #wsOpen(int, java.lang.String, java.lang.Object) opened}
1.48 + * @param data the data to send or <code>null</code> if the socket is
1.49 + * supposed to be closed
1.50 + */
1.51 public void wsSend(Object webSocket, String url, Object data) {
1.52 ((JSON.WS)webSocket).send(context, url, data);
1.53 }
1.54 @@ -250,7 +280,7 @@
1.55 public Number toNumber(Object data, String propName) {
1.56 return JSON.toNumber(context, data, propName);
1.57 }
1.58 -
1.59 +
1.60 public <T> T toModel(Class<T> type, Object data, String propName) {
1.61 return JSON.toModel(context, type, data, propName);
1.62 }