Re: Wicket 6.0 WebSocket question: client API

2012-06-20 Thread Martin Grigorov
Hi Pierre,

Take a look at 
https://github.com/martin-g/wicket-native-websocket-example/blob/master/src/main/resources/org/apache/wicket/websocket/jetty/example/client.js

There is Wicket.WebSocket object which basically wraps native
window.WebSocket just to be able to intercept the calls and send
messages with Wicket.Event's PubSub.

You can use native window.WebSocket as well.

I'm working on a simplification which will create/open a single WS
connection for all WebSocketBehaviors you may have in your page. I
don't see why someone would need more than one websocket connection
per page. This way we/you can create components which use
WebSocketBehavior internally and use the default connection.

For example currently you need to do:
var ws = new Wicket.WebSocket();
ws.send('some text');

with the default connection it may look like:
WebSocketTextLink uses WebSocketBehavior to setup the connection and
to have the callback (#onTextMessage()), and additionally it will
register 'click' event listener for the link to read the text somehow
and send it with : Wicket.WebSocket.send(loadText())
Note that this way you don't care about creating the websocket at all
(new Wicket.WebSocket()). This will be done for you. You will just
need to provide a way to read the text that should be send.

I'll add some documentation about the client side API in the Wiki page soon.

On Wed, Jun 20, 2012 at 3:08 PM, Pierre Goupil goupilpie...@gmail.com wrote:
 Good afternoon,

 Thanks for the WebSocket support in Wicket 6.0, that's very good news to
 hear.

 But I have a couple of questions, though. Firstly, how am I supposed to
 send a message from the client-side? Am I supposed to use the plain-vanilla
 WebSocket API? For instance, would this do the trick:

 ---

 var ws = new WebSocket(ws://localhost:9998/echo);
 ws.onopen = function() {
      ws.send(Message to send);
 }

 --
  ?

 Or is there any other (more Wicket-way) of providing the server with a
 message?

 Secondly, how am I supposed to get the URL to provide to the client-side?
 Is there a #renderHead() method which could give it to me, like for the
 DefaultAjaxBehavior? I'm sorry I can't test it for the moment, so I'm just
 asking here.

 OK, thanks in advance guys!

 Regards,

 Pierre Goupil


 --
 Si tu penses que la violence ne résout rien, c'est que tu n'as pas tapé
 assez fort.



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket 6.0 WebSocket question: client API

2012-06-20 Thread Pierre Goupil
Great! Thanks a lot!

Regards,

Pierre



On Wed, Jun 20, 2012 at 2:31 PM, Martin Grigorov mgrigo...@apache.orgwrote:

 Hi Pierre,

 Take a look at
 https://github.com/martin-g/wicket-native-websocket-example/blob/master/src/main/resources/org/apache/wicket/websocket/jetty/example/client.js

 There is Wicket.WebSocket object which basically wraps native
 window.WebSocket just to be able to intercept the calls and send
 messages with Wicket.Event's PubSub.

 You can use native window.WebSocket as well.

 I'm working on a simplification which will create/open a single WS
 connection for all WebSocketBehaviors you may have in your page. I
 don't see why someone would need more than one websocket connection
 per page. This way we/you can create components which use
 WebSocketBehavior internally and use the default connection.

 For example currently you need to do:
 var ws = new Wicket.WebSocket();
 ws.send('some text');

 with the default connection it may look like:
 WebSocketTextLink uses WebSocketBehavior to setup the connection and
 to have the callback (#onTextMessage()), and additionally it will
 register 'click' event listener for the link to read the text somehow
 and send it with : Wicket.WebSocket.send(loadText())
 Note that this way you don't care about creating the websocket at all
 (new Wicket.WebSocket()). This will be done for you. You will just
 need to provide a way to read the text that should be send.

 I'll add some documentation about the client side API in the Wiki page
 soon.

 On Wed, Jun 20, 2012 at 3:08 PM, Pierre Goupil goupilpie...@gmail.com
 wrote:
  Good afternoon,
 
  Thanks for the WebSocket support in Wicket 6.0, that's very good news to
  hear.
 
  But I have a couple of questions, though. Firstly, how am I supposed to
  send a message from the client-side? Am I supposed to use the
 plain-vanilla
  WebSocket API? For instance, would this do the trick:
 
  ---
 
  var ws = new WebSocket(ws://localhost:9998/echo);
  ws.onopen = function() {
   ws.send(Message to send);
  }
 
  --
   ?
 
  Or is there any other (more Wicket-way) of providing the server with a
  message?
 
  Secondly, how am I supposed to get the URL to provide to the client-side?
  Is there a #renderHead() method which could give it to me, like for the
  DefaultAjaxBehavior? I'm sorry I can't test it for the moment, so I'm
 just
  asking here.
 
  OK, thanks in advance guys!
 
  Regards,
 
  Pierre Goupil
 
 
  --
  Si tu penses que la violence ne résout rien, c'est que tu n'as pas tapé
  assez fort.



 --
 Martin Grigorov
 jWeekend
 Training, Consulting, Development
 http://jWeekend.com

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-- 
Si tu penses que la violence ne résout rien, c'est que tu n'as pas tapé
assez fort.