<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vishal Mishra on Medium]]></title>
        <description><![CDATA[Stories by Vishal Mishra on Medium]]></description>
        <link>https://medium.com/@vishal_mishra?source=rss-c3d742668a25------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MOQOG09iYvay4xxjMK8wJQ.jpeg</url>
            <title>Stories by Vishal Mishra on Medium</title>
            <link>https://medium.com/@vishal_mishra?source=rss-c3d742668a25------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 05:43:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vishal_mishra/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Presenting the Adobe I/O Runtime Plugin]]></title>
            <link>https://medium.com/adobetech/presenting-the-adobe-i-o-runtime-plugin-5e579c17d632?source=rss-c3d742668a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e579c17d632</guid>
            <category><![CDATA[plugins]]></category>
            <category><![CDATA[cli]]></category>
            <category><![CDATA[adobe-io]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Vishal Mishra]]></dc:creator>
            <pubDate>Fri, 07 Jun 2019 01:23:13 GMT</pubDate>
            <atom:updated>2019-06-10T17:47:14.672Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B8wtV07ZhlV4YhUlsxEvIg.png" /></figure><p>The Adobe I/O Extensible Command Line Interface (CLI), <a href="https://github.com/adobe/aio-cli">aio-cli</a>, is an extensible cli based on <a href="http://oclif.io/">Open CLI Framework</a> (OCLIF), and we’re now announcing the Runtime plugin for aio-cli, <a href="https://github.com/adobe/aio-cli-plugin-runtime">aio-cli-plugin-runtime</a>. This can be used to create, run, and manage Adobe Runtime serverless entities like Packages, Actions, Triggers, Rules, APIs, Activations, and Property. Each of these entities has subcommands like create , invoke etc.</p><p>The runtime plugin commands can be used with the following template:</p><pre>aio runtime &lt;command&gt; &lt;subcommand&gt; &lt;arguments&gt; &lt;flags&gt;</pre><h3>Installation</h3><ul><li>Install the aio cli</li></ul><pre>npm install -g @adobe/aio-cli</pre><ul><li>Install the aio cli runtime plugin for aio-cli</li></ul><pre>aio plugins install @adobe/aio-cli-plugin-runtime</pre><h3>Usage</h3><ul><li>The available commands can be listed by executing the following:</li></ul><pre>aio runtime</pre><ul><li>Creating a runtime action:</li></ul><pre>aio runtime action create &lt;action name&gt; &lt;path to js or zip file&gt;</pre><ul><li>Retrieve an action:</li></ul><pre>aio runtime action get &lt;action name&gt;</pre><ul><li>Invoke an action:</li></ul><pre>aio runtime action invoke &lt;action name&gt; &lt;optional parameters&gt;</pre><p>The possible arguments and flags for each command can be found out by using the --help flag.</p><ul><li>Deploying a manifest file: This command deploys the contents of the manifest file to the server. If no path to manifest file is provided, the command assumes there is a manifest.yaml or manifest.yml file in the current working directory.</li></ul><pre>aio runtime deploy -m &lt;path to manifest.yaml file&gt;</pre><ul><li>Undeploy a manifest file: This command deletes the contents of the package listed in the manifest file. If no path to manifest file is provided, the command assumes there is a manifest.yaml or manifest.yml file in the current working directory.</li></ul><pre>aio runtime deploy undeploy -m &lt;path to manifest.yaml file&gt;</pre><h3><strong>Demo</strong></h3><p>This demo video shows some examples of using the aio cli plugin runtime.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FP9tkE9QhWcU%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DP9tkE9QhWcU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FP9tkE9QhWcU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d45f490cbf311fdb759baba0ab839ce/href">https://medium.com/media/4d45f490cbf311fdb759baba0ab839ce/href</a></iframe><h3>Work in progress</h3><p>The aio cli plugin runtime is a new plugin and is actively being developed. We are capturing features we would like to add to the plugin, and invite you to review those on the <a href="https://github.com/adobe/aio-cli-plugin-runtime/wiki/Feature-Matrix">Feature Matrix</a>.</p><h3>Contact us</h3><p>Your feedback is graciously accepted and appreciated!</p><p><a href="https://github.com/adobe/aio-cli-plugin-runtime">Please submit your pull requests and issues here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e579c17d632" width="1" height="1" alt=""><hr><p><a href="https://medium.com/adobetech/presenting-the-adobe-i-o-runtime-plugin-5e579c17d632">Presenting the Adobe I/O Runtime Plugin</a> was originally published in <a href="https://medium.com/adobetech">Adobe Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PhoneGap Media Recorder Plugin]]></title>
            <link>https://medium.com/phonegap/phonegap-media-recorder-plugin-e511caa2a4bc?source=rss-c3d742668a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/e511caa2a4bc</guid>
            <category><![CDATA[w3c]]></category>
            <category><![CDATA[phonegap]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[apache-cordova]]></category>
            <dc:creator><![CDATA[Vishal Mishra]]></dc:creator>
            <pubDate>Tue, 10 Oct 2017 00:12:28 GMT</pubDate>
            <atom:updated>2017-11-16T01:56:37.677Z</atom:updated>
            <content:encoded><![CDATA[<p>We are happy to present the <a href="https://github.com/phonegap/phonegap-plugin-media-recorder">PhoneGap Media Recorder Plugin</a> for Android and iOS. It provides an implementation for recording audio and video with a device camera and is based on the <a href="https://www.w3.org/TR/mediastream-recording/">W3C Media Recorder API</a>. This plugin uses the <a href="https://github.com/phonegap/phonegap-plugin-media-stream">PhoneGap Media Stream Plugin</a> which is based on the <a href="https://www.w3.org/TR/mediacapture-streams/">W3C Media Stream API</a> to access the stream which is used to build a MediaRecorder object.</p><h4>Quickstart</h4><p>The implementation in iOS allows the user to open a camera view and record a video. Android has integrated support for the <a href="https://www.w3.org/TR/mediacapture-streams/">W3C Media Stream API</a> and the <a href="https://www.w3.org/TR/mediastream-recording/">W3C Media Recorder API</a>.</p><p>The camera view in the iOS implementation looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*RjuNVe4R4Xq82K31fhl5bA.gif" /></figure><p>The Android version of the plugin allows the user to stream the video capture on a &lt;video&gt; tag and the user can then take a picture which is returned as a Blob:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*atAuz0DdSsoTiPStof00XQ.gif" /></figure><h4>How to Install</h4><p>This plugin can be installed by using one of the following commands:</p><pre>phonegap plugin add phonegap-plugin-media-recorder</pre><pre>phonegap plugin add <a href="https://github.com/phonegap/phonegap-plugin-media-recorder">https://github.com/phonegap/phonegap-plugin-media-recorder</a></pre><h4>Quickstart</h4><p>The MediaRecorder constructor uses the MediaStream obtained from the <a href="https://github.com/phonegap/phonegap-plugin-media-stream">Phonegap Media Stream Plugin</a> as shown below:</p><pre>navigator.mediaDevices.getUserMedia({<br>    &#39;audio&#39;: true,<br>    &#39;video&#39;: {facingMode: &#39;user&#39;}<br> }).then(function(stream) {<br>    var mediaRecorder = new MediaRecorder(stream);<br> });</pre><p>This mediaRecorder object can then be used to start recording audio/video using mediaRecorder.start(). The start() method gets the recording started as shown below:</p><pre>mediaRecorder.onstart = function() {<br>    console.log(&#39;Recording Started&#39;);<br>};<br>mediaRecorder.start();</pre><p>The start() method also accepts an optional timeslice parameter which allows the user to pass the number of milliseconds after which the recorded data will be available in chunks.</p><pre>mediaRecorder.onstop = function() {<br>    console.log(&#39;Recording Stopped&#39;);<br>};</pre><pre>mediaRecorder.start(10000);  // mediaRecorder.ondataavailable fired            <br>                                every 10 seconds</pre><p>The above functionality is currently not supported on iOS and passing a timeslice parameter does not work to record content in chunks.</p><p>The recording can be stopped by using mediaRecorder.stop() as shown below:</p><pre>mediaRecorder.onstop = function() {<br>    console.log(&#39;Recording Stopped&#39;);<br>};<br>mediaRecorder.stop();</pre><p>When the recording is finished, the recorded data can be retrieved and played from mediaRecorder.ondataavailable which is triggered after media.start() (only for iOS video) , media.stop() and mediaRecorder.requestData() (only when recording state is notinactive) as shown below:</p><pre>mediaRecorder.ondataavailable = function(blob) {<br>    var videoTag = document.getElementById(&quot;vid&quot;);// video tag<br>    if(device.platform === &#39;iOS&#39;) {               // iOS device<br>        videoTag.src = mediaRecorder.src;<br>    } else {                                     // Android device<br>        var recordedChunks = [];<br>        recordedChunks.push(blob.data);<br>        videoTag.src = URL.createObjectURL(<strong>new<br>                       </strong>Blob(recordedChunks));<br>    }<br>}<br>mediaRecorder.requestData();</pre><p>The mediaRecorder object has other methods like <em>pause() and resume()</em> which, along with full example code are explained in detail <a href="https://github.com/phonegap/phonegap-plugin-media-recorder/blob/master/README.md">here</a>.</p><h4>Quirks</h4><p>In order to add a blob object as a source for a video tag, blob: should be added to the media-src part of the Content-Security-Policy meta tag in your index.html.</p><h4>Contact Us</h4><p>Your feedback is graciously accepted and appreciated!</p><p><a href="https://github.com/phonegap/phonegap-plugin-media-recorder">Please submit your pull requests and issues here.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e511caa2a4bc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/phonegap/phonegap-media-recorder-plugin-e511caa2a4bc">PhoneGap Media Recorder Plugin</a> was originally published in <a href="https://medium.com/phonegap">PhoneGap</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PhoneGap Image Capture Plugin]]></title>
            <link>https://medium.com/phonegap/phonegap-image-capture-plugin-6c132e791c04?source=rss-c3d742668a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c132e791c04</guid>
            <category><![CDATA[phonegap]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[w3c]]></category>
            <dc:creator><![CDATA[Vishal Mishra]]></dc:creator>
            <pubDate>Wed, 16 Aug 2017 14:48:49 GMT</pubDate>
            <atom:updated>2017-08-16T14:48:49.787Z</atom:updated>
            <content:encoded><![CDATA[<p>The <a href="https://github.com/phonegap/phonegap-plugin-image-capture">PhoneGap Image Capture Plugin</a> for Android and iOS was introduced recently. It provides an implementation for taking pictures with a device camera and is based on the <a href="https://www.w3.org/TR/image-capture/">W3C Media Capture API</a> . This plugin uses the <a href="https://github.com/phonegap/phonegap-plugin-media-stream">PhoneGap Media Stream Plugin</a> which is based on the <a href="https://www.w3.org/TR/mediacapture-streams/">W3C Media Stream API</a> to access a track which is used to build an ImageCapture object.</p><h4>Quickstart</h4><p>The implementation in iOS allows the user to open a camera view and click a picture. Android has integrated support for the <a href="https://www.w3.org/TR/mediacapture-streams/">W3C Media Stream API</a> and the <a href="https://www.w3.org/TR/image-capture/">W3C MediaStream Image Capture API</a> from Chrome 59 and the latest Android System Webview.</p><p>The camera view in the iOS implementation looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*ozi3NofE77FVn8YaG5HT1w.png" /><figcaption>Camera View in iOS</figcaption></figure><p>The Android version of the plugin allows the user to stream the video capture on a &lt;video&gt; tag and the user can then take a picture which is returned as a Blob:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*FUMIFM8cnkPiyTvz9i3BQw.png" /><figcaption>Image Capture for Android</figcaption></figure><h4>How to Install</h4><p>This plugin can be installed by using one of the following commands:</p><pre>phonegap plugin add phonegap-plugin-image-capture</pre><pre>phonegap plugin add <a href="https://github.com/phonegap/phonegap-plugin-image-capture.git">https://github.com/phonegap/phonegap-plugin-image-capture.git</a></pre><h4><strong>Quickstart</strong></h4><p>The ImageConstructor uses the mediastream track obtained from the <a href="https://github.com/phonegap/phonegap-plugin-media-stream">Phonegap Media Stream Plugin</a> as shown below:</p><pre> navigator.mediaDevices.getUserMedia({<br>    &#39;audio&#39;: true,<br>    &#39;video&#39;: {facingMode: &#39;user&#39;}<br> }).then(function(getmedia) {<br>    var track = getmedia.getVideoTracks()[0];<br>    var imageCapture = new ImageCapture(track);<br> });</pre><p>This imageCapture object can then be used to take a picture using takePhoto(). The takePhoto() promise resolves with a blob on successful capture of a picture as shown below:</p><pre> imageCapture.takePhoto().then(blob =&gt; {<br>      console.log(&#39;Photo taken&#39;);<br>     // img is an &lt;img&gt; tag<br>      const image = document.querySelector(&#39;img&#39;); <br>      image.src = URL.createObjectURL(blob);<br>  })<br>  .catch(err =&gt; console.error(&#39;takePhoto() failed: &#39;));</pre><p>The imageCapture object has other properties like <em>getPhotoCapabilities()</em>, <em>getPhotoSettings()</em> and <em>grabFrame()</em> which are explained in detail <a href="https://github.com/phonegap/phonegap-plugin-image-capture/blob/master/README.md">here</a>.</p><h4>Quirks</h4><p>In order to add a blob object as a source for an img tag, blob: should be added to the img-src part of the Content-Security-Policy meta tag in your index.html .</p><h4><strong>Contact Us</strong></h4><p>Your feedback is graciously accepted and appreciated!</p><p><a href="https://github.com/phonegap/phonegap-plugin-image-capture">Please submit your pull requests and issues here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c132e791c04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/phonegap/phonegap-image-capture-plugin-6c132e791c04">PhoneGap Image Capture Plugin</a> was originally published in <a href="https://medium.com/phonegap">PhoneGap</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating from the Cordova Device Motion Plugin]]></title>
            <link>https://medium.com/phonegap/migrating-from-the-cordova-device-motion-plugin-ddd8176632ed?source=rss-c3d742668a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddd8176632ed</guid>
            <category><![CDATA[w3c]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[phonegap]]></category>
            <dc:creator><![CDATA[Vishal Mishra]]></dc:creator>
            <pubDate>Thu, 10 Aug 2017 18:29:22 GMT</pubDate>
            <atom:updated>2017-08-10T18:29:22.265Z</atom:updated>
            <content:encoded><![CDATA[<p>The <a href="https://github.com/apache/cordova-plugin-device-motion">Cordova Device Motion Plugin</a> will see its sunset soon. This plugin provides access to the device’s accelerometer which detects the change (<em>delta</em>) in movement relative to the current device orientation, in three dimensions along the <em>x</em>, <em>y</em>, and <em>z</em> axes. The <a href="https://www.w3.org/TR/2016/CR-orientation-event-20160818/#devicemotion">W3C Device Motion and Orientation API</a> now defines a way to access the accelerometer of the device and is supported across iOS, Android and Windows devices.</p><h4>Migrating from the plugin to the W3C Device Motion API</h4><p>The access to the device accelerometer in the Cordova plugin is obtained by a global navigator.accelerometer object which provides a method navigator.accelerometer.watchAcceleration that allows the users to gather the acceleration of the device along the x, y and z axes. An example to obtain these values is shown below:</p><pre>function onSuccess(acceleration) {<br>    alert(&#39;Acceleration X: &#39; + acceleration.x + &#39;\n&#39; +<br>          &#39;Acceleration Y: &#39; + acceleration.y + &#39;\n&#39; +<br>          &#39;Acceleration Z: &#39; + acceleration.z + &#39;\n&#39; +<br>          &#39;Timestamp: &#39;      + acceleration.timestamp + &#39;\n&#39;);<br>}</pre><pre>function onError() {<br>    alert(&#39;onError!&#39;);<br>}</pre><pre>var options = { frequency: 3000 };  // Update every 3 seconds</pre><pre>var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);</pre><p>However, in the <a href="https://www.w3.org/TR/2016/CR-orientation-event-20160818/#devicemotion">W3C Device Motion and Orientation API</a>, before we gather values from the device’s accelerometer and compass, we need to calibrate the compass of the device by instructing the user to calibrate the compass:</p><pre>window.addEventListener(&quot;compassneedscalibration&quot;,function(event) {<br>      // ask user to wave device in a figure-eight motion .   <br>      event.preventDefault();<br>}, true);</pre><p>Once the compass has been calibrated, the devicemotion listener can be obtained by:</p><pre>function processEvent(event) {<br>    // process the event object<br>}</pre><pre>window.addEventListener(&quot;devicemotion&quot;,processEvent, true);</pre><p>When the devicemotion event has been registered, the following properties can be obtained:</p><ul><li><em>acceleration along the x, y and z axes: </em>These are the<em> </em>values which we used to obtain from the watchAcceleration method of the Cordova Device Motion plugin. Sample code to obtain these values using the W3C API is provided below:</li></ul><pre>console.log(Math.round(event.acceleration.x));<br>console.log(Math.round(event.acceleration.y));<br>console.log(Math.round(event.acceleration.z));</pre><ul><li><em>accelerationIncludingGravity along the x, y and z axes: </em>The W3C Device Motion API also provides information about the <em>accelerationIncludingGravity property </em>of the device which was not available in the Cordova Device Motion plugin<em>.</em>Sample code to obtain this property is provided below:</li></ul><pre>console.log(Math.round(event.accelerationIncludingGravity.x));<br>console.log(Math.round(event.accelerationIncludingGravity.y));<br>console.log(Math.round(event.accelerationIncludingGravity.z));</pre><ul><li><em>rotationRate: </em>The <a href="https://www.w3.org/TR/2016/CR-orientation-event-20160818/#deviceorientation">alpha, beta and gamma</a> values can be obtained using the following sample code :</li></ul><pre>console.log(Math.round(event.rotationRate.alpha));<br>console.log(Math.round(event.rotationRate.beta));<br>console.log(Math.round(event.rotationRate.gamma));</pre><p>In the Cordova Device Motion Plugin, the listener for the watchAcceleration property was removed by using the clearWatch method as shown below:</p><pre>// watchID created while adding the watchAcceleration listener<br>navigator.accelerometer.clearWatch(watchID);</pre><p>However, according to the <a href="https://www.w3.org/TR/2016/CR-orientation-event-20160818/#devicemotion">W3C Device Motion and Orientation API</a> , the devicemotion listener can be removed by:</p><pre>window.removeEventListener(&quot;devicemotion&quot;,processEvent);</pre><p>Your feedback is graciously accepted and appreciated!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddd8176632ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/phonegap/migrating-from-the-cordova-device-motion-plugin-ddd8176632ed">Migrating from the Cordova Device Motion Plugin</a> was originally published in <a href="https://medium.com/phonegap">PhoneGap</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating from the Cordova Device Orientation Plugin]]></title>
            <link>https://medium.com/phonegap/migrating-from-the-cordova-device-orientation-plugin-8442b869e6cc?source=rss-c3d742668a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/8442b869e6cc</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[w3c]]></category>
            <category><![CDATA[phonegap]]></category>
            <category><![CDATA[cordova]]></category>
            <dc:creator><![CDATA[Vishal Mishra]]></dc:creator>
            <pubDate>Wed, 09 Aug 2017 23:42:10 GMT</pubDate>
            <atom:updated>2017-11-08T00:23:28.492Z</atom:updated>
            <content:encoded><![CDATA[<p>Just like the <a href="https://github.com/apache/cordova-plugin-device-motion">Cordova Device Motion Plugin</a> , the <a href="https://github.com/apache/cordova-plugin-device-orientation">Cordova Device Orientation Plugin</a> will also see its sunset soon. This plugin provides access to the device’s compass which detects the direction or heading that the device is pointed, typically from the top of the device. The <a href="https://www.w3.org/TR/2016/CR-orientation-event-20160818/#devicemotion">W3C Device Motion and Orientation API</a> now defines a way to access the compass of the device and is supported across iOS, Android and Windows devices. Hence, this Cordova plugin is no longer needed.</p><h4>Migrating from the plugin to the W3C Device Motion API</h4><p>The access to the device compass in the Cordova plugin is provided by a global navigator.compass object which provides a method navigator.compass.watchHeading that allows the users to gather the magnetic heading of the compass. The magnetic heading of the compass indicates the heading in degrees from 0–359.99 at a single moment in time. An example to obtain these values is shown below:</p><pre>function onSuccess(heading) {<br>    var element = document.getElementById(&#39;heading&#39;);<br>    element.innerHTML = &#39;Heading: &#39; + heading.magneticHeading;<br>};<br><br>function onError(compassError) {<br>    alert(&#39;Compass error: &#39; + compassError.code);<br>};<br><br>var options = {<br>    frequency: 3000<br>}; // Update every 3 seconds<br><br>var watchID = navigator.compass.watchHeading(onSuccess, onError, options);</pre><p>However, in the <a href="https://www.w3.org/TR/2016/CR-orientation-event-20160818/#devicemotion">W3C Device Motion and Orientation API</a>, before we gather values from the device’s compass, we need to calibrate the compass by instructing the user to do so:</p><pre>window.addEventListener(&quot;compassneedscalibration&quot;,function(event) {<br>    // ask user to wave device in a figure-eight motion  <br>       event.preventDefault();<br>}, true);</pre><p>Once the compass has been calibrated, the deviceorientation listener can be obtained by:</p><pre>function processEvent(event) {<br>    // process the event object<br>},</pre><pre>window.addEventListener(&quot;deviceorientation&quot;,processEvent, true);</pre><p>Once the deviceorientation event has been registered, the <a href="https://www.w3.org/TR/2016/CR-orientation-event-20160818/#deviceorientation">alpha, beta and gamma values</a> for the device’s orientation can be obtained using the following sample code:</p><pre>console.log(Math.round(event.alpha));<br>console.log(Math.round(event.beta));<br>console.log(Math.round(event.gamma));</pre><p>The<em> </em>value of magnetic heading which we used to obtain from the watchHeading listener of the Cordova Device Orientation plugin can be gathered by using the value of (360 — event.alpha) .</p><p>In the Cordova Device Motion Plugin, the listener for the watchHeading property was removed by using the clearWatch method as shown below:</p><pre>// watchID created while adding the watchHeading listener<br>navigator.compass.clearWatch(watchID);</pre><p>However, according to the <a href="https://www.w3.org/TR/2016/CR-orientation-event-20160818/#devicemotion">W3C Device Motion and Orientation API</a> , the deviceorientation listener can be removed by:</p><pre>window.removeEventListener(&quot;deviceorientation&quot;,processEvent);</pre><p>Your feedback is graciously accepted and appreciated!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8442b869e6cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/phonegap/migrating-from-the-cordova-device-orientation-plugin-8442b869e6cc">Migrating from the Cordova Device Orientation Plugin</a> was originally published in <a href="https://medium.com/phonegap">PhoneGap</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PhoneGap Battery Status Plugin]]></title>
            <link>https://medium.com/phonegap/phonegap-battery-status-plugin-ea49548f3413?source=rss-c3d742668a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea49548f3413</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[phonegap]]></category>
            <dc:creator><![CDATA[Vishal Mishra]]></dc:creator>
            <pubDate>Fri, 05 May 2017 22:14:23 GMT</pubDate>
            <atom:updated>2017-05-05T22:14:23.598Z</atom:updated>
            <content:encoded><![CDATA[<p>The <a href="https://github.com/phonegap/phonegap-plugin-battery-status">PhoneGap Battery Status Plugin</a> was released recently. This plugin serves a threefold purpose:</p><ol><li>It returns the battery status for Android and iOS devices.</li><li>It conforms to the current <a href="https://www.w3.org/TR/battery-status/">W3C Battery Status API</a> .</li><li>It will be contributed to Apache Cordova once we have an implementation ready for Windows.</li></ol><p>The method <em>navigator.getBattery()</em> returns a promise with a BatteryManager object which has the following properties and event handlers:</p><ul><li><em>level</em>: The battery charge level ranging from 0–1. <em>(Number)</em></li><li><em>charging</em>: A boolean that indicates whether the device is plugged in. <em>(Boolean)</em></li><li><em>chargingTime</em>: The time remaining to fully charge the battery. <em>(Number)</em></li><li><em>dischargingTime</em>: The time remaining for the battery level to come down to 0. <em>(Number)</em></li><li><em>onchargingchange</em>: This event fires when the device is plugged in or unplugged.</li><li><em>onchargingtimechange</em>: This event fires when the time required to charge the device changes.</li><li><em>ondischargingtimechange</em>: This event fires when the time that the device will take to discharge changes.</li><li><em>onlevelchange</em>: A change in battery level fires this event.</li></ul><p>An example usage of the <em>onlevelchange</em> event handler is shown below :</p><pre>navigator.getBattery().then(<strong>function</strong>(battery) {<br>  console.log(battery.level);<br>  battery.onlevelchange = <strong>function</strong>() {<br>    console.log(<strong>this</strong>.level);<br>  };<br>});</pre><p>The <em>levelchange</em> event type can be added to the battery object using the addEventListener object as shown below:</p><pre>navigator.getBattery().then(<strong>function</strong>(battery) {<br>  battery.addEventListener(&#39;levelchange&#39;, <strong>function</strong>() {<br>    console.log(<strong>battery</strong>.level);<br>  });<br>});</pre><p><strong>How to Install</strong></p><p>The plugin can be installed by using the following command :</p><pre>phonegap plugin add phonegap-plugin-battery-status</pre><p><strong>Issues</strong></p><p>The <em>chargingTime</em> and the <em>dischargingTime</em> properties and the corresponding event handlers are, however, not supported on iOS.</p><p><strong>Contact Us</strong></p><p>Your feedback is graciously accepted and appreciated!<br><a href="https://github.com/phonegap/phonegap-plugin-battery-status">Please submit your pull requests and issues here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea49548f3413" width="1" height="1" alt=""><hr><p><a href="https://medium.com/phonegap/phonegap-battery-status-plugin-ea49548f3413">PhoneGap Battery Status Plugin</a> was originally published in <a href="https://medium.com/phonegap">PhoneGap</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cordova Screen Orientation Plugin]]></title>
            <link>https://medium.com/phonegap/cordova-screen-orientation-plugin-fabeba30a4c4?source=rss-c3d742668a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/fabeba30a4c4</guid>
            <category><![CDATA[phonegap]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[w3c]]></category>
            <category><![CDATA[plugins]]></category>
            <dc:creator><![CDATA[Vishal Mishra]]></dc:creator>
            <pubDate>Tue, 28 Mar 2017 00:35:31 GMT</pubDate>
            <atom:updated>2019-05-24T16:18:46.547Z</atom:updated>
            <content:encoded><![CDATA[<p>The new version(2.0.0) of the cordova screen orientation plugin was released recently. The purpose of the plugin is to set/lock the screen orientation in a common way for all the major platforms. This new version conforms with the specifications mentioned in the <a href="https://www.w3.org/TR/screen-orientation/">[W3C Screen Orientation API ]</a>, currently in open draft .</p><p>The plugin incorporates these major updates:</p><ol><li>Locking/unlocking the screen orientation.</li><li>Accessing the current screen orientation.</li><li>Addition of ‘onchange’ event handler to the screen.orientation object.</li><li>A Demo App.</li></ol><h4><strong>Locking/unlocking the screen orientation</strong></h4><p>The screen orientation can be locked to a particular orientation, say, for example, landscape, using :</p><pre>screen.orientation.lock(‘landscape’).then(function success() {</pre><pre>console.log(“Successfully locked the orientation”);</pre><pre>},function error(errMsg) {</pre><pre>console.log(“Error locking the orientation :: “ + errMsg);</pre><pre>});</pre><p>The code above sets the screen orientation device to any landscape mode</p><p>( landscape-primary or landscape-secondary) depending upon the rotation.</p><p>The screen.orientation.lock(OrientationLockType); method returns a promise.On successfully setting the orientation, it resolves a promise. If the screen is not locked successfully, the promise rejects with ‘NotSupportedError’ .</p><p>The screen orientation can be unlocked by using:</p><pre>screen.orientation.unlock();</pre><p>The code above makes the screen adapt to the default orientation of the device. The unlock method does not return a promise.</p><h4><strong>Accessing the current screen orientation</strong></h4><p>The current screen orientation can be accessed as :</p><pre>console.log(‘Orientation is’ + screen.orientation.type);</pre><h4><strong>Addition of ‘onchange’ attribute to the screen.orientation object</strong></h4><p>An example usage of the ‘onchange’ event handler:</p><pre>screen.orientation.onchange = function(){<br> console.log(screen.orientation.type);<br>};</pre><p>The ‘change’ event can also be added to the screen.orientation object :</p><pre>screen.orientation.addEventListener(‘change’, function(){<br> console.log(screen.orientation.type);<br>});</pre><h4><strong>The Demo Application</strong></h4><p>The demo application is included on the github repository. Once the plugin has been added to it, the demo application allows the user to test the orientation types with the screen.orientation.lock() method. The demo application is explained in detail in this video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FP4Ulb9SQllA%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DP4Ulb9SQllA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FP4Ulb9SQllA%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e33a230cd0460555efe640b671c8e0e9/href">https://medium.com/media/e33a230cd0460555efe640b671c8e0e9/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fabeba30a4c4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/phonegap/cordova-screen-orientation-plugin-fabeba30a4c4">Cordova Screen Orientation Plugin</a> was originally published in <a href="https://medium.com/phonegap">PhoneGap</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>