3

I'm writing a mobile chat client for Microsoft Lync using Sencha Touch.

On the server side I'm using the JSONP-enabled WCF service from the lyncwidget codeplex project (http://lyncwidget.codeplex.com) Upon being called, the WCF service returns any messages that were queued on the server as JSON data.

The idea is that the client(s) poll the service regularly to retrieve any new messages.

I want to implement the polling behaviour directly in my Store's Proxy, if this is possible. So in the "ChatMessagesStore".

Any advice on how to implement this in a neat way?

Thanks.

ps: I'm a newbie at Sencha Touch.

Thomas Stock
  • 10,927
  • 14
  • 62
  • 79

2 Answers2

2

The best would be to extend the Ext.data.ScriptTagProxy class. Then have a property inside called "pool-interval" and a method that would call the sync() function and it self. Example:

makeRequest(){
  this.sync();
  setTimeout("this.makeRequest()",pool-interval);
};

This way if you have multiple stores with proxy like this you wouldn't have to bother with setting multiple setInterval calls and the need to change them when you change the store's name.

ilija139
  • 2,925
  • 3
  • 20
  • 23
  • 1
    If you are going to have makeRequest call itself, then you should probably use `setTimeout` rather than `setInterval`...? – Rom1 Sep 23 '11 at 08:03
1

What about regularly calling sync() on the store?

For instance, calling

 setInterval("MyApp.stores.myStore.sync()", 3000);

would sync your store every three seconds.

A short remark about polling from mobile applications: it drains battery like crazy. Anybody has ideas for alternatives / workarounds?

Rom1
  • 3,167
  • 2
  • 22
  • 39