<div dir="ltr">Great Ideas Erik !<div>Comments inline</div><div class="gmail_extra"><br><br><div class="gmail_quote">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>
<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 style>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>True but it would be nice if we can still pass optionally a function for the registration successHandler, depending on the developer needs maybe I still wants to do something with his backend once the registration is suceesful. But I agree to have a default &quot;hidden&quot; function for that ... but should be able to override it.&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 style><br></span></div><div><span style>For iOS we have these badge and sound flags we could we get rid of those as well? 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></blockquote><div><br></div><div>Not really understand here what you mean, could you elaborate a bit ? &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 style><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>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>That will be a convention to skip the senderId when the variant is an Android &quot;type&quot;, yeah why not, I like that.&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 style><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>I like the idea but that can be tricky since multiple variants can have the same meta information (like &quot;Android Free&quot;/&quot;Android Premium&quot;), we should think about a convention. But again I like the idea and it is worth thinking about it.&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 style><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 class="HOEnZb"><font color="#888888"><div><span style="white-space:pre-wrap">        </span>Erik Jan</div>
</font></span></span></div></div><br>_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org">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></blockquote></div><br></div></div>