<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 26, 2014 at 11:26 AM, Matthias Wessendorf <span dir="ltr">&lt;<a href="mailto:matzew@apache.org" target="_blank">matzew@apache.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><div class="">On Wed, Feb 26, 2014 at 10:40 AM, Erik Jan de Wit <span dir="ltr">&lt;<a href="mailto:edewit@redhat.com" target="_blank">edewit@redhat.com</a>&gt;</span> wrote:<br>

</div><div class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi,<div><br></div><div>As you may have experienced or seen the cordova push plugin is not always simple to get started with, there are still some things that are platform specific even though compared to the &lsquo;original&rsquo; it has improved there is room for improvement. Here are some suggestions to make it even simpler:</div>

<div><br></div><div>Right now the API looks like this:</div><div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:13px;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;color:rgb(51,51,51)">
<span style="font-weight:bold">var</span> <span>pushConfig</span> <span style="font-weight:bold">=</span> <span>{</span>
    <span style="color:rgb(153,153,136);font-style:italic">// senderID is only used in the Android/GCM case</span>
    <span>senderID</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;senderID e.g Google Project ID only for android&gt;&quot;</span><span>,</span>
    <span>pushServerURL</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;pushServerURL e.g http(s)//host:port/context &gt;&quot;</span><span>,</span>
    <span>variantID</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;variantID e.g. 1234456-234320&gt;&quot;</span><span>,</span>
    <span>variantSecret</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;variantSecret e.g. 1234456-234320&gt;&quot;</span><span>,</span>
    <span>alias</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;alias e.g. a username or an email address optional&gt;&quot;</span>
<span>}</span>

<span style="color:rgb(153,153,136);font-style:italic">//badge and sound are iOS specific, and ignored on Android</span>
<span>push</span><span>.</span><span>register</span><span>(</span><span>successHandler</span><span>,</span> <span>errorHandler</span><span>,</span> <span>{</span><span style="color:rgb(221,17,68)">&quot;badge&quot;</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;true&quot;</span><span>,</span> <span style="color:rgb(221,17,68)">&quot;sound&quot;</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;true&quot;</span><span>,</span>
    <span style="color:rgb(221,17,68)">&quot;ecb&quot;</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;onNotification&quot;</span><span>,</span> <span>pushConfig</span><span style="font-weight:bold">:</span> <span>pushConfig</span><span>});</span></pre>

<div>Suggestion number one, is to remove the successHandler and use that as the callback for notifications:</div></div><div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:13px;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;color:rgb(51,51,51)">
<span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">push</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">.</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">register</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">(</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">onNotification</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">,</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)"> </span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">errorHandler</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">,</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)"> </span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">{</span><span style="font-size:12px;color:rgb(221,17,68);line-height:16.799999237060547px;background-color:rgb(255,255,255)">&quot;badge&quot;</span><span style="color:rgb(0,0,0);font-size:12px;font-weight:bold;line-height:16.799999237060547px;background-color:rgb(255,255,255)">:</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)"> </span><span style="font-size:12px;color:rgb(221,17,68);line-height:16.799999237060547px;background-color:rgb(255,255,255)">&quot;true&quot;</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">,</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)"> </span><span style="font-size:12px;color:rgb(221,17,68);line-height:16.799999237060547px;background-color:rgb(255,255,255)">&quot;sound&quot;</span><span style="color:rgb(0,0,0);font-size:12px;font-weight:bold;line-height:16.799999237060547px;background-color:rgb(255,255,255)">:</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)"> </span><span style="font-size:12px;color:rgb(221,17,68);line-height:16.799999237060547px;background-color:rgb(255,255,255)">&quot;true&quot;</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">,</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)"> </span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">pushConfig</span><span style="color:rgb(0,0,0);font-size:12px;font-weight:bold;line-height:16.799999237060547px;background-color:rgb(255,255,255)">:</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)"> </span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">pushConfig</span><span style="color:rgb(0,0,0);font-size:12px;line-height:16.799999237060547px;background-color:rgb(255,255,255)">});</span></pre>

</div><div><span>Now the Javascript can verify that the callback is a function because it&rsquo;s no longer a string and the need for a separate successHandler is overrated as you will either get messages or your errorHandler gets invoked.&nbsp;</span></div>

</div></blockquote><div><br></div><div><br></div></div><div>I like the idea of passing in a function (instead of a string), for the notification handling.</div><div><br></div><div>However, the successHandler was meant to give feedback if registration w/ UPS was successful or not. Should we really remove that hook ?&nbsp;</div>
</div></div></div></blockquote><div><br></div><div>yes, we can: since error tells the app: something went wrong (with registration). So pretty much good enough to only have that one. If that is not invoked: well registration must have been successful :-)&nbsp;</div>
<div><br></div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="">
<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span><br></span></div><div><span>For iOS we have these badge and sound flags we could we get rid of those as well? </span></div>

</div></blockquote><div><br></div></div><div>yes, good point. Internally we set the to true; and if the message does not contain sound/badge -&gt; oh well :)&nbsp;</div><div>Good idea for simplification!</div><div class=""><div>
<br></div><div>&nbsp;</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span>When you don&rsquo;t want a badge then just don&rsquo;t send it in the message!? Then the pushConfig can be inlined making it look like this:</span></div>

<div><span><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:13px;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;color:rgb(51,51,51)">
<pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:16.799999237060547px;width:744px;margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<div><span>push</span><span>.</span><span>register</span><span>(</span><span>onNotification</span><span>,</span> <span>errorHandler</span><span>,</span> <span>{</span><span style="line-height:16.799999237060547px">  </span></div>

<div>    <span style="color:rgb(153,153,136);font-style:italic">// senderID is only used in the Android/GCM case</span></div><div>    <span>senderID</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;senderID e.g Google Project ID only for android&gt;&quot;</span><span>,</span></div>

<div>    <span>pushServerURL</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;pushServerURL e.g http(s)//host:port/context &gt;&quot;</span><span>,</span></div><div>    <span>variantID</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;variantID e.g. 1234456-234320&gt;&quot;</span><span>,</span></div>

<div>    <span>variantSecret</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;variantSecret e.g. 1234456-234320&gt;&quot;</span><span>,</span></div><div>    <span>alias</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;alias e.g. a username or an email address optional&gt;&quot;</span></div>

<div><span>});</span></div></pre></pre><div></div></span></div></div></blockquote></div><div>looks really compact now</div><div class=""><div><br></div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div style="word-wrap:break-word"><div><span><div>Till now all these changes can be made on the plugin, but we could take it even further. Two things that are still platform dependent the senderId and the variantID/secret. Now senderId is &lsquo;known&rsquo; by UPS so why do we need to specify it here? We could make senderId part of the response when registering a device on UPS then the client doesn&rsquo;t need to specify it and all configuration is in one place.</div>

</span></div></div></blockquote><div><br></div></div><div>It&#39;s optional on UPS, as only really Android clients need it. And I think originally Luke just added the &#39;senderID&#39; to UPS for having something handy (copy/paste usage).</div>

<div><br></div><div>So, I am not sure on that one, as that means we now have to enforce Android Variants always get the senderID attribute. Could be done, yes, but I am not sure.</div><div class=""><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div style="word-wrap:break-word"><div><span><div><br></div><div>That leaves variantID/secret and that is the boldest proposal. How about we make it possible to register for an application instead for a specific variant? Then based on the meta information (deviceType, operatingSystem and osVersion) we choose the right variant.</div>

</span></div></div></blockquote><div><br></div></div><div>-1</div><div><br></div><div>we should never &#39;deploy&#39; the masterSecret and the applicationID on clients. If that information is stolen (easy on devices), you can start sending dirty assaults to ALL the devices for that application. Same w/ all the different providers like Parse, Stackmob etc: they all use a MasterKey/Password for the actual send. And they _highly_ recommend NOT applying that to the clients (it&#39;s easy to leak that information)</div>

<div><br></div><div><br></div><div>-Matthias</div><div><br></div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><div style="word-wrap:break-word">
<div><span><div>
<br></div><div>If we do all of the above there will be no platform specific code at all and the final script could look as simple as this:</div><div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:13px;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;color:rgb(51,51,51)">
<pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:16.799999237060547px;width:744px;margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;line-height:16.799999237060547px;width:744px;margin-top:0px;margin-bottom:0px;padding:0px"><div><span>push</span><span>.</span><span>register</span><span>(</span><span style="font-weight:bold">function</span><span>(</span><span>event</span><span>)</span> <span>{</span></div>

<div>  <span>alert</span><span>(</span><span>event</span><span>.</span><span>alert</span><span>);</span></div><div><span>},</span> </div><div><span style="font-weight:bold">function</span><span>(</span><span>error</span><span>)</span> <span>{</span></div>

<div>  <span style="font-weight:bold">throw</span> <span>error</span><span>;</span></div><div><span>},</span> <span>{</span></div><div>    <span>pushServerURL</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;pushServerURL e.g http(s)//host:port/context &gt;&quot;</span><span>,</span></div>

<div>    <span>applicationID</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;applicationID e.g. 1234456-234320&gt;&quot;</span><span>,</span></div><div>    <span>secret</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;secret e.g. 1234456-234320&gt;&quot;</span><span>,</span></div>

<div>    <span>alias</span><span style="font-weight:bold">:</span> <span style="color:rgb(221,17,68)">&quot;&lt;alias e.g. a username or an email address optional&gt;&quot;</span></div><div><span>});</span></div></pre><div>

<br></div></div></pre></pre></div><div><span>Push notifications in one statement for all devices :)</span></div><div><span><br></span></div><div>WDYT</div><span><font color="#888888"><div><span style="white-space:pre-wrap">        </span>Erik Jan</div>

</font></span></span></div></div><br></div><div class="">_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org" target="_blank">aerogear-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br></div></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all">
<div><br></div>-- <br>Matthias Wessendorf <br>
<br>blog: <a href="http://matthiaswessendorf.wordpress.com/" target="_blank">http://matthiaswessendorf.wordpress.com/</a><br>sessions: <a href="http://www.slideshare.net/mwessendorf" target="_blank">http://www.slideshare.net/mwessendorf</a><br>

twitter: <a href="http://twitter.com/mwessendorf" target="_blank">http://twitter.com/mwessendorf</a>
</font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Matthias Wessendorf <br><br>blog: <a href="http://matthiaswessendorf.wordpress.com/" target="_blank">http://matthiaswessendorf.wordpress.com/</a><br>sessions: <a href="http://www.slideshare.net/mwessendorf" target="_blank">http://www.slideshare.net/mwessendorf</a><br>
twitter: <a href="http://twitter.com/mwessendorf" target="_blank">http://twitter.com/mwessendorf</a>
</div></div>