<?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 JackPu on Medium]]></title>
        <description><![CDATA[Stories by JackPu on Medium]]></description>
        <link>https://medium.com/@JackPu?source=rss-bbd1c67bba5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*AHYs1_c-_gpntuUWDKOmGQ.jpeg</url>
            <title>Stories by JackPu on Medium</title>
            <link>https://medium.com/@JackPu?source=rss-bbd1c67bba5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 18:37:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JackPu/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[The Challenges of OTT Development]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@JackPu/the-challenges-of-ott-development-069d2a689b34?source=rss-bbd1c67bba5c------2"><img src="https://cdn-images-1.medium.com/max/2600/1*BMSs3oQkK2judsp0OHCIUw.png" width="2752"></a></p><p class="medium-feed-snippet">I have been working on OTT (Over-The-Top) device development for some time now, and I plan to write down some of the experiences I&#x2019;ve&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@JackPu/the-challenges-of-ott-development-069d2a689b34?source=rss-bbd1c67bba5c------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@JackPu/the-challenges-of-ott-development-069d2a689b34?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/069d2a689b34</guid>
            <category><![CDATA[videos]]></category>
            <category><![CDATA[ott]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Fri, 21 Nov 2025 02:53:17 GMT</pubDate>
            <atom:updated>2025-11-25T09:04:33.378Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Use JavaScript to detect PSSH Box]]></title>
            <link>https://medium.com/@JackPu/use-javascript-to-detect-pssh-box-d690e211679f?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d690e211679f</guid>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[media]]></category>
            <category><![CDATA[drm]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Tue, 18 Mar 2025 08:05:19 GMT</pubDate>
            <atom:updated>2025-03-18T08:06:10.510Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yabjotwSRQUh64g0bMLZKg.jpeg" /></figure><p>AI is already very powerful now. If you have such a need(Use JavaScript to detect PSSH Box), it is very clear that you should use AI directly. This is the result given by Google <a href="https://gemini.google.com/app/2b5e2353185462ab">Gemini</a>:</p><blockquote><em>Detecting PSSH (Protection System Specific Header) in MP4 files using JavaScript is a complex task mainly because:</em></blockquote><blockquote><em>Binary Data: MP4 files are binary, not text-based. JavaScript in a browser environment restricts direct access to binary data at a low level.<br>File Structure: PSSH is embedded in the atomic structure of the MP4, requiring parsing to find it.<br>Browser Security: Browsers restrict direct file system access, limiting your ability to read arbitrary MP4 files directly.<br>However, you can achieve this through a combination of techniques, primarily involving the fetch API for retrieving files, ArrayBuffer for binary data handling, and custom parsing logic. Here’s a breakdown of the general approach:</em></blockquote><p><strong>Get the MP4 file:</strong></p><pre>async function getPSSH(url) {<br>  try {<br>    const response = await fetch(url);<br>    if (!response.ok) {<br>      throw new Error(`HTTP error! status: ${response.status}`);<br>    }<br>    const arrayBuffer = await response.arrayBuffer();<br>    return findPSSH(arrayBuffer);<br>  } catch (error) {<br>    console.error(&quot;Error fetching or parsing MP4:&quot;, error;<br>    return null;<br>  }<br>}</pre><p><strong>Parsing MP4 atomic structure:</strong></p><blockquote><em>This is the most challenging part. You need to implement a parser that understands the atomic structure of MP4. Here is a simplified example (you’ll probably need a more powerful parser for real-world scenarios):</em></blockquote><pre>function findPSSH(arrayBuffer) {<br>  const dataView = new DataView(arrayBuffer);<br>  let offset = 0;<br>   while (offset &lt; dataView.byteLength) {<br>    const size = dataView.getUint32(offset);<br>    const type = String.fromCharCode(<br>      dataView.getUint8(offset + 4),<br>      dataView.getUint8(offset + 5),<br>      dataView.getUint8(offset + 6),<br>      dataView.getUint8(offset + 7)<br>    );<br>    if (type === &quot;pssh&quot;) {<br>      const psshData = new Uint8Array(<br>      arrayBuffer.slice(offset + 8, offset + size)<br>      );<br><br>      return psshData;<br>    }<br>  offset += size;<br>  }<br>  return null; <br>}</pre><p><strong>Extracting PSSH data:</strong></p><blockquote>Once you have found the “pssh” atom, you can extract the data within it. The PSSH structure itself has its own format, and you may need to parse it further depending on your use case.</blockquote><pre>getPSSH(&quot;your_mp4_file.mp4&quot;).then((pssh) =&gt; {<br>  if (pssh) {<br>    console.log(&quot;PSSH found:&quot;, pssh);<br>    const hexPssh = Array.from(pssh).map(byte =&gt; byte.toString(16).padStart(2, &#39;0&#39;)).join(&#39;&#39;);<br>    console.log(&quot;PSSH hex:&quot;, hexPssh);<br>  } else {<br>    console.log(&quot;PSSH not found.&quot;);<br>  }<br> });</pre><blockquote><em>Important Notes:</em></blockquote><blockquote><em>Complexity: MP4 parsing is complex. Reliable implementations usually rely on specialized libraries.</em></blockquote><blockquote><em>Performance: Parsing large MP4 files in JavaScript can be very resource intensive.</em></blockquote><blockquote><em>Cross-origin requests: If your MP4 file is on a different domain, you need to handle CORS (Cross-Origin Resource Sharing) by setting the appropriate headers on your server.</em></blockquote><blockquote><em>Browser Restrictions: Browsers have security restrictions that may limit your ability to perform certain actions.</em></blockquote><blockquote><em>Alternative method:</em></blockquote><blockquote><em>For server-side processing, Node.js with a library like mp4box.js or FFMPEG will be more efficient.</em></blockquote><blockquote><em>For client applications that handle DRM, the Media Source Extensions (MSE) API and the Encrypted Media Extensions (EME) API are standard mechanisms that provide access to PSSH data in a more controlled manner.</em></blockquote><blockquote><em>EME and MSE: If you are working with DRM-protected content, the EME and MSE APIs are the correct way to handle pssh. EME will provide you with pssh information.<br>This information provides general direction. For production-level applications, it is strongly recommended to use dedicated libraries or server-side processing.</em></blockquote><p>In less than three minutes, the problem was solved, but there was a flaw, which I discovered during testing.</p><p>findPSSH There is nothing wrong with using a while loop to compare types, but the structure of an mp4 box is generally as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*TqwPPxcclB3K9U6t.png" /></figure><p>I found that it stopped after running to moov.</p><pre>const size = dataView.getUint32(offset);</pre><p>After we get the length of moov, we should theoretically continue to sniff the moov box, but we don’t, so we can try recursion.</p><pre>export function findPSSH(arrayBuffer, offset) {<br>  const dataView = new DataView(arrayBuffer);<br>  while (offset &lt; dataView.byteLength) {<br>    const size = dataView.getUint32(offset);<br>    const type = String.fromCharCode(<br>      dataView.getUint8(offset + 4),<br>      dataView.getUint8(offset + 5),<br>      dataView.getUint8(offset + 6),<br>      dataView.getUint8(offset + 7)<br>    );<br>    if (type === &quot;moov&quot;) {<br>      return findPSSH(arrayBuffer, offset + 8);<br>    }<br>    if (type === &quot;pssh&quot;) {<br>      // Found the PSSH atom<br>      const psshData = new Uint8Array(<br>        arrayBuffer.slice(offset + 8, offset + size)<br>      );<br>        //Here you have the raw pssh data.<br>      return psshData;<br>    }<br>    offset += size;<br>  }<br>  return null; // PSSH not found<br>}</pre><p>The final debugging result is quite good. So now the AI ​​quality is really very high, we only need to debug a little bit, and there is no need to waste too much time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d690e211679f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How VR Videos Work]]></title>
            <link>https://medium.com/@JackPu/how-vr-videos-work-5c33bdf9f6c1?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c33bdf9f6c1</guid>
            <category><![CDATA[quests]]></category>
            <category><![CDATA[vr]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[videos]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Sun, 30 Jul 2023 12:59:40 GMT</pubDate>
            <atom:updated>2023-07-30T13:01:12.380Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.jackpu.com/chen-jin-shi-duo-mei-ti-gong-zuo-yuan-li-jian-jie/">Chinese Version</a></p><p>Recently, I shared the experience and principles of immersive media with the group. Here is a brief sharing of what experience we want and how to achieve it if we are going to build the VR player in the headsets;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2rmAYfoBu09qEAVPh7NC3g.jpeg" /></figure><p>My sharing is mainly from four aspects:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p6q_KV6VfpWQyNKAcjvNgA.jpeg" /></figure><ul><li>A brief history of VR</li><li>VR video playback experience</li><li>Principles of VR Video Playback</li><li>Some current challenges</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NTwfNm4Y4pMn64GL6NQ9tQ.jpeg" /></figure><p>Stanley G. Weinbaum published a science fiction novel, “Pygmalion’s Glasses”, this novel shows everyone magical glasses, in which you can see everything, this is also the charm of imagination, no one can predict In the future, someone will realize such glasses;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rA9jk9-sO59CETdLfwPU5A.jpeg" /></figure><p>Morton Heilig invented the first VR device in human history; Although it looks like a leak, the display screen, impact, seat, fan, and functions are very rich, and now the 4Dx movie may also refer to this point; After a while, he wrote a patent, hoping to put all these in a box, and people wearing this box can realize many functions designed by him; such a patented prototype also leaves important guidelines for future generations to make head-mounted display equipment;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g1Ryzl2WK_bIK0spQ5OuGQ.jpeg" /></figure><p>In 1968, Sutherland and Bob Sproull invented the first head-mounted virtual reality device. It was a milestone product, and it completed the ability to update the picture following the movement of the head; but limited by hardware limitations, it needed additional support to drag live this device;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0-nnN8CYtVznjAyq4rdDtA.jpeg" /></figure><p>In the 1990s, many game companies entered the game and participated in the research and development of VR head-mounted display equipment, including well-known companies such as Sega Nintendo; revolution;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQFRjhn3mv8zjhh--aICkw.jpeg" /></figure><p>The time came to the era of mobile Internet, and Oculus, the breaker, appeared. It released its first head-mounted display device. What surprised people was that with the rise of smartphones, we have accumulated display screens, chips, and graphics rendering technologies. , and with the help of these foreshadowings, we have been able to complete a powerful head-mounted display device; with Google’s increase in VR, we have also accumulated in video content; VR has attracted a small climax; many domestic manufacturers have also tried;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-niYV_OKpFxXfeHPvuMVw.jpeg" /></figure><p>The Quest device released before the epidemic has ushered in a wave of upsurge with home office and home isolation; as of the latest statistics, Oculus has sold 20 million devices, and its store has also put a lot of games and applications on the shelves. This is the confidence that Facebook dares to transform vigorously; the emergence of the Oculus Quest all-in-one machine makes us look forward to the future of VR again;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tvGMQwUTTGUf4TIIrCFWyw.jpeg" /></figure><p>Based on the summary of Zhihu netizens, a technology is destined to be extraordinary from its birth to entering thousands of households; We can feel the advanced attention it brings, and we will also experience the loss of expectations; but with hardware, the software includes continuous improvement and investment of resources, and we can still expect it to have the opportunity to enter thousands of households in the future and become the core of the next-generation Internet software revolution;</p><h3>The Experience of Watching Videos in VR</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUW6ywYfOp-ypl-BV8kZAw.jpeg" /></figure><p>Many people do not have headsets at home, so I recorded some videos, and I can simply experience downloading and watching videos on the headset, and what are the differences;</p><p><a href="https://youtu.be/992LzB-IkSY">https://youtu.be/992LzB-IkSY</a></p><p>The first video uses the <a href="https://www.oculus.com/experiences/quest/2497738113633933/?locale=en_GB">bigscreen</a> software for a video playback experience; here we can see the immersive environment, watch 4K sources, watch 3D movies, etc.;</p><p><a href="https://youtu.be/rbByn-Wt-co">https://youtu.be/rbByn-Wt-co</a></p><p>The second video is the 360 ​​panoramic video experience that we will focus on today;</p><p><a href="https://youtu.be/J24jSpppnTM">https://youtu.be/J24jSpppnTM</a></p><p>The third video is to share the experience of watching the game. What is the difference between watching NBA games in the headset and in reality?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k79ARN-iSXZ9h4szYZ6j5w.jpeg" /></figure><p>From the above video, we can summarize the following points:</p><ul><li>We are actually watching in a “real” movie theater</li><li>We can see content from a lot of angles</li><li>We can experience 3D movies and 360 panoramic videos</li><li>We can use gesture recognition to control</li></ul><h3>Principle Analysis</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q_f_CeU6-EMGYKRPMTxJ0A.jpeg" /></figure><p>Next, we will briefly popularize the principle of the previous panoramic video playback;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oRtMJyummtlltJCcm1fRFQ.jpeg" /></figure><p>Like our traditional playback, our video player still consists of three parts</p><ul><li>Video PlayerView</li><li>UI</li><li>External container environment</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g4v4sR6uxL3tvo-5xqivPw.jpeg" /></figure><p>The environment here is different from our DIV. It requires our designers to provide high-quality and highly restored model files. This can be a theater, a living room, or an open-air environment. It depends entirely on the designer’s performance here;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r4YjtYHj7Osmt453plSXPw.jpeg" /></figure><p>In addition to the different environments, the video resources are also different;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m_yo_YYDKK-i_PhVXiK0Qw.jpeg" /></figure><p>Here we will support different video types:</p><ul><li>Monoscopic 360 Video monocular panorama (our skydiving video)</li><li>Stereoscopic 360 Video binocular stereoscopic panorama</li><li>180 Video 180 Panorama (Video of NBA games)</li><li>3D Top/Bottom Left/Right (the Avatar trailer above is left and right 3D)</li><li>2D</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t5VJnBA1dXFqxuFt31yduA.jpeg" /></figure><p>Many people don’t understand Monoscopic very well, you can read <a href="https://zhuanlan.zhihu.com/p/90738288">https://zhuanlan.zhihu.com/p/90738288</a> to mention it;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQZFn-J72ozyQYR9aOjfHQ.jpeg" /></figure><p>You can understand that if we want to see 360-degree content, we can use a camera to rotate 360 ​​degrees; in this way, we can see 360-degree content;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQ38gUFKXCx6teSopMvO4Q.jpeg" /></figure><p>Stereoscopic is also easier to understand; we humans have two eyes, but the pictures entered by the two eyes are inconsistent. The advantage of this is that we create a better space when the visual nerve is synthesized. Unfortunately, you can try to live with one eye , to see if you will have an illusion of distance, and the appearance of both ears is also conducive to our stereo positioning; so we use multiple cameras to simulate human eyes, and we can make such panoramic content;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQ38gUFKXCx6teSopMvO4Q.jpeg" /></figure><p>We have the content, but how to restore it in the head-mounted display; the first thing that comes to mind is the sphere, and everyone may be confused when looking at the above content; if you think of the globe and the world earth, you will understand it at once; in fact, equidistant Cylindrical projection is to project the intensive reading dimension on the sphere onto a rectangle according to a certain distance; therefore, we carry out a reverse principle. Although the concept of graphics is inconsistent with such an expression, we will not do a more detailed explanation of the texture here;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ylYbM9BGi65xuGJ-2sqIQ.jpeg" /></figure><p>The use of spherical maps will waste up and down resources for textures. People will ask when they are young, why the South Pole and North Pole look big on the flat map, but they are actually small; this texture method will waste pixel resources, so We can use another way;</p><p>Cube map, as the name suggests, we can restore it to a cube, for example, people can see all the content in the center of the cube; therefore, we need to process the original content, divide it into six sides, front, back, left, right, up and down, respectively Textures for six faces;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3EA_RnyqPya12Mh4QtNMVA.jpeg" /></figure><p>Programmers pursue the ultimate in performance and experience; the above resources still have a flaw, that is, the distribution of pixels on the surface is still uneven; therefore, Google came up with a more optimized way of Equi-Angular Cubemap Source (equal-angle Cubemap) ;</p><p>In this way, if you are pursuing high-quality rendering, you can choose the last solution, which is also recommended by Google;</p><p>The following video will show you the comparison from the original video to the player when it is played;</p><p><a href="https://youtu.be/j7d7hQv3hsU">https://youtu.be/j7d7hQv3hsU</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aos06qU72-hFC1WuWTKP2Q.jpeg" /></figure><p>Since I am mainly from the front end, I can use threee.js to realize such panoramic playback; the above content is also a very simple design, generally speaking, the principle is very simple, and the implementation is not complicated;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R6SlnBAp3Nb-JWhR7LAJLQ.jpeg" /></figure><p>Of course, if we want to deploy panorama in the production line, we still have a lot of streaming media; for example, if we want to implement ABR, we still need to do some things:</p><p>We need to provide the m3u8 / dash file that wraps the stereoscopic video</p><ul><li>Each face needs to have multiple tile resolutions</li><li>We need to combine eye-focused content to select high-definition and low-definition resolution</li><li>The video pulls for rendering</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KpIQrfN8dg4o6DglMu0-Tg.jpeg" /></figure><p>In general, when we play full video, we still face the following challenges, which are multifaceted:</p><ul><li>The problem of high bit rate requires more advanced codec technology (HEVC/VVC/LCEVC)</li><li>Avoid unnecessary rendering resource occupation</li><li>Network Latency and Rendering Latency</li><li>Panoramic video requires more investment and research from professional filmmakers or studios to explore how to shoot panoramic videos and provide blockbuster works</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-DRbhtVgUEgSMYGl2t4IA.jpeg" /></figure><p>Finally, some people are more concerned about what kind of equipment; currently Quest2 / Pico 4 are not bad; if you are patient, you can wait for Quest3; but I still hope that you think carefully about your purpose before buying:</p><ul><li>play games</li><li>watch video</li><li>Purely technical research or exploration</li></ul><p>If you are interested in the above directions, I still think you need to be cautious because it is really a device that is extremely easy to eat dust;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guCKm60rdQJsaUvHkroORg.jpeg" /></figure><p>After all, you can imagine how your head will feel after a long time wearing such a few hundred grams of equipment. So after you experience it, think calmly and see if it is really needed now.</p><p>Finally, I also throw a question to you;</p><p><strong>Do you think VR(XR) will be the next computer platform?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAq07Kdtvq82xp7OUfnpaQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c33bdf9f6c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WebXR Guide]]></title>
            <link>https://medium.com/@JackPu/webxr-guide-e126d125d44c?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e126d125d44c</guid>
            <category><![CDATA[vr]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[oculus]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 05:38:18 GMT</pubDate>
            <atom:updated>2023-07-07T05:38:18.832Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This is my recent presentation. And I will share it with some comments.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P5yUmFxg5cNaW1m3lVcpMA.png" /><figcaption>1/24</figcaption></figure><p>Today I am going to share very funny topics;</p><p><strong>WebXR</strong></p><p>You know, Meta and Apple invested a lot of resources in this field; Some people here don’t have headsets or never experience it.</p><p>But it doesn’t matter; Today I will just make a simple introduction about it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8YC5MFp_77_4qN8GE2Bkw.png" /><figcaption>2/24</figcaption></figure><p>Here are agendas</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Dc1YUPPhGMz0g9ut9pHUg.png" /><figcaption>3/24</figcaption></figure><p>In the 1940s, the first computer was born in the world. At that time, the computer was still huge, and the interface looks so old style, and we can only get specific information from the different colors of lights;</p><p>A few years later, major companies(like IBM) entered the personal computer market;</p><p>That’s the computer’s appearance we are seen now. we use the mouse and keyboard and a big display.</p><p>In the new century, we have an iPad with a touch screen, which is one of the great inventions in human history; Von Neumann model, the input and output are perfectly combined on one display On the screen; it brings us a lot of innovative interactions;</p><p>In the last ten years, humans are still looking for the next generation of computers; maybe headsets will be one.</p><p><strong>Why?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rmrhsNmXfi5AS5cUIOG7fw.png" /><figcaption>4/24</figcaption></figure><p>Let’s talk about “XR”</p><p>Some people are willing to use X to represent anything; Because we know there are VR, AR;</p><p>And also with the new generation headsets, we created the MR(mixed-reality); Via The Video See-Through technology, we cannot only see the display graph, but we can also see the outside world graph from the camera located in the headset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3fbK0X2l3eJp0iVLRJ07dA.png" /><figcaption>5/24</figcaption></figure><p>The biggest difference from XR; It gives us is the immersive experience;</p><p>The first part: we could experience the visual 3d graph and spatial audio; That’s one part of `reality`</p><p>The second part: Our interaction is not simply a button, but will dynamically combine the position of our physical space and the position of the device, so it will respond according to our actions;</p><p>After talking about XR, maybe you get to know what webXR is by its name;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L02xmakhcQYid832tzBWYg.png" /><figcaption>6/24</figcaption></figure><p>Then let’s talk about WebXR;</p><p>WebXR means us to develop web applications in the browser of XR OS;</p><p><strong>Introduction to the WebXR API</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLOLFZIe0q14i0s4Ohz0QQ.png" /><figcaption>7/24</figcaption></figure><p>The first thing we do with any new API is to determine its compatibility; we can do this by</p><pre>if (&quot;xr&quot; in window.navigator) {<br>/* WebXR can be used! */<br>} else {<br>/* WebXR isn&#39;t available */<br>}</pre><p>After judging, we just need to start;</p><p>among them, XRSession is a very important concept;</p><p>In the session, we can access some basic WebXR APi and change some common properties;</p><p>we can requestSessionenter our VR mode;</p><pre>navigator.xr.requestSession(&#39;immersive-vr&#39;).then(onSessionStarted)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N5bk_jda4E4c4uExrqJeWg.png" /><figcaption>8/24</figcaption></figure><p>There are two modes in XRSession;</p><p>inline can be in normal mode, that is, our pages will be displayed according to the execution method of the browser. For example, the Weibo we browse normally can be displayed normally on Zhihu</p><p>immersive-vr is our expected VR mode, we will enter a three-dimensional scene, it depends on how we realize;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXx3KN20pgSBfzQQtkKV3w.png" /><figcaption>9/24</figcaption></figure><p>In XRSession, we can implement some operations on WebXR API, such as:</p><p>It helps us to detect it in AR or VR mode (environmentBlendMode)</p><p><strong>renderState</strong>: describing how the user’s environment which should be rendered</p><p><strong>inputSources</strong>: I will talk about it later</p><p><strong>requestAnimationFrame: </strong>schedules a callback to be executed the next time</p><p>Next is what we need to focus on WebGL;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jouX_aA-0XoaudC5aQrQlg.png" /><figcaption>10/24</figcaption></figure><p>the WebXR API itself does not include a 3D graphics API, it must be used in conjunction with the WebGL API (or the more modern WebGPU API);</p><p>therefore, if we want to in-depth application development, WebGL learning is definitely inevitable;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l2oGhlgFIUd3m7nMl093tg.png" /><figcaption>11/24</figcaption></figure><p>XRSpace In WebXR;</p><p>a “space (XRSpace)” represents a set of 3D coordinate systems in virtual space, and its origin corresponds to a position in the physical real world, so “space” can serve as a link between digital virtual space and physical reality The role of spatial association; with it, we can better handle our interactions; both from the controller and the headset itself;</p><p>Let me make an example;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q6T_FK77nC6KCrhF08Ks4Q.png" /><figcaption>12/24</figcaption></figure><p>When we implement web chess, we can control chess pieces according to mouse clicks, mouseover, and other events;</p><p>if we want to implement a three-dimensional chessboard placed in front of us, we want to realize chess moves, what should the interactive information be like?</p><p>The next step is also very important; how do we handle interaction;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lqvPUx3_JZcgnme2G6Ho7Q.png" /><figcaption>13/24</figcaption></figure><p>We know the Von Neumann architecture;</p><p>VR also has many sources of interaction, for example, we often have two controllers; before the first time, the headset is also one of the interactive devices we need to track; With increasing precision, our hands will also become the objects we interact with;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GylS7k68-jVHCvZ00yPQ_Q.png" /><figcaption>14/24</figcaption></figure><p>This is Oculus quest pro controller. There is some press button and a joystick, And also there is a touch area; It could be very complex;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WU-Wc2-cmh_FGiiXUynXZA.png" /><figcaption>15/24</figcaption></figure><p>Through the above figure, we can simply compare how we realize the binding of events;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dOTvYuV59Ub_fkJbmAFaXg.png" /><figcaption>16/24</figcaption></figure><p>In addition to the APIs introduced above, you can also learn about the following if you are interested</p><p><strong>XRFrame</strong>: access to the information needed in order to render a single frame</p><p><strong>XRPose</strong>: a position and orientation in the 3D space,</p><p><strong>XRViewport</strong>: it provides properties used to describe the size and position of the current viewport</p><p><strong>How do we start it?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9a6tXvjlzMHS0VZojAgjQ.png" /><figcaption>17/24</figcaption></figure><p>How do we develop the basic API introduced earlier; I have some small tips to share</p><p>1 Web project initialization (PWA is better); because it is a Web project, we can use our favorite technical scaffolding or engineering, what Webpack/TS/Eslnt ​​can be freely matched; if you want to publish the application to the Quest store, it is best Use some auxiliary tools of PWA; I wrote an article about Oculus and PWA before, you can take a look;</p><p>2 WebGL is the core, so we’d better choose a suitable WebGL framework (Three.js, Babylon.js), writing native code is really cumbersome;</p><p>3 Initialize WebXR and process XRFrame (you can also choose the WebXR framework); this is what we all need to do, with the help of documentation, refer to WebXR Sample to help you understand them;</p><p>4 Testing and real machine debugging; in any case, it must be tested on a real machine;</p><p>I will show you a video demo;</p><p><a href="https://drive.google.com/file/d/1Ib_ztIKZekv48eVPICYbPIE44cwPgBD_/view?resourcekey">https://drive.google.com/file/d/1Ib_ztIKZekv48eVPICYbPIE44cwPgBD_/view?resourcekey</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U3MJT_gMs23e1rg0tCjdRg.png" /><figcaption>19/24</figcaption></figure><p>We usually develop, we can use <em>webxr-api-emulator</em> to do some interactive processing;（simulation）</p><p>if we are debugging on the real machine;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFAjL6JnN7VAxzN9eMxahA.png" /><figcaption>20/24</figcaption></figure><p>We can use adb reversethe command to perform localhost proxy; of course, other proxy network tools are also available; because the API of WebXR can only localhost work under HTTPS;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5608d9kzxDOjjk_7iBeHVg.png" /><figcaption>21/24</figcaption></figure><p>After the development is complete, you can of course publish your own application, don’t forget to package PWA and APK packages;</p><p>Some useful tools:</p><ul><li>@bubblewrap/cli</li><li>Oculus Platform Utility</li><li>PWA on Oculus Quest2</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LRpOsCTnH8bJgV1lDeugxA.png" /><figcaption>22/24</figcaption></figure><p>Here I also briefly compare the similarities and differences between traditional Web and WebXR development; mainly</p><p>WebXR is more graphically related to development</p><p>We use many model files (bx,gLTE,obj)</p><p>It will be more complicated to handle the interaction</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vpo0tBD8D-y_AMIJ4MUOMw.png" /><figcaption>23/24</figcaption></figure><p>Although the development of WebXR is very difficult, due to the natural cross-platform compatibility of the Web, as well as the out-of-the-box feature without installation, I believe that there must be a world of its own in the future;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Pg25cRKkdlmv_hntiLbMw.png" /></figure><p>Thanks. I just make a brief share about WebXR; There is one tip for you.The most of APIs are under-experimental. And We cannot guarantee that Oculus or App will support them well. So if you are interested in it; maybe you could explore more by yourself. Because three are so less helpful documents. Anyway, we can know what our web developers can do if the XR moment is coming.</p><p><a href="https://www.jackpu.com/webxr-guide-fen-xiang/">[Chinses Version]</a></p><p><strong>Read More:</strong></p><ul><li><a href="https://zhuanlan.zhihu.com/p/622957093">https://zhuanlan.zhihu.com/p/622957093</a></li><li><a href="https://web.dev/pwas-on-oculus-2/">https://web.dev/pwas-on-oculus-2/</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API">https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API</a></li><li><a href="https://immersive-web.github.io/webxr-samples/">https://immersive-web.github.io/webxr-samples/</a></li><li><a href="https://developer.oculus.com/documentation/web/pwa-gs/">https://developer.oculus.com/documentation/web/pwa-gs/</a></li><li><a href="https://medium.com/@lazerwalker/how-to-easily-test-your-webvr-and-webxr-projects-locally-on-your-oculus-quest-eec26a03b7ee">https://medium.com/@lazerwalker/how-to-easily-test-your-webvr-and-webxr-projects-locally-on-your-oculus-quest-eec26a03b7ee</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e126d125d44c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Observe Page Scroll in Swift 4]]></title>
            <link>https://medium.com/@JackPu/observe-page-scroll-in-swift-4-d53dd402d606?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d53dd402d606</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[observe]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Thu, 21 May 2020 02:15:40 GMT</pubDate>
            <atom:updated>2020-05-21T02:15:40.863Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zMcMzYT6MTjDJrG2XmLpcA.jpeg" /></figure><p>Swift (&lt;4) provideaddObserver API to watch some property value change，and the new edition swift provide observe</p><pre>observer = test.observe(\.field, options: [.new, .initial]) { (object, change) in<br>    print(change)<br>}</pre><p>And you must mark a variable or class private member result of observing ，or it doesn’t work.</p><p>We often want to check View scroll via <a href="https://developer.apple.com/documentation/uikit/uiscrollviewdelegate">UIScrollViewDelegate</a></p><pre>extension UIScrollViewDelegate{<br>    func scrollViewDidScroll(scrollView: UIScrollView){<br>        //do something<br>    }<br>}</pre><p>But if we want to keep components more independent we recommend Observe API.</p><pre>class ComponetView: UIVIew {<br>	private var observation: NSKeyValueObservation?<br>	init(targetView: UIView) {<br>		observation = targetView.observe(\.contentOffset, options: [.new]) { [weak self] scrollView, change in<br>            // handle data contentOffset<br>        }<br>	}<br>}</pre><p>And if your device&#39;s system (iOS &lt;= 10.x) may occur some crash and you must force to remove the observe view <a href="https://oldoldb.com/2019/02/16/KVO-bug/">https://oldoldb.com/2019/02/16/KVO-bug/</a></p><h3>Read More</h3><ul><li><a href="https://juejin.im/post/5a6ed035518825734108308d">https://juejin.im/post/5a6ed035518825734108308d</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d53dd402d606" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue-core-video-player support HLS format now]]></title>
            <link>https://medium.com/@JackPu/vue-core-video-player-support-hls-format-now-1d24b5c639da?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d24b5c639da</guid>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[hls]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Tue, 05 May 2020 04:58:22 GMT</pubDate>
            <atom:updated>2020-05-05T04:58:22.674Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AA7ubKnImF9zdkf67Hwckg.jpeg" /></figure><p>As is known to us. <a href="https://developer.apple.com/streaming/">HLS</a> is an important video format for all big video service platforms for Apple, Netflix, and Tencent Video Entertainment. HLS is a media streaming protocol for delivering visual and audio media to viewers over the internet.</p><p>HLS protocol chops up MP4 video content into short (10-second) chunks with the .ts file extension (MPEG2 Transport Stream). Next, an HTTP server stores those streams, and HTTP delivers these short clips to viewers on their devices. (HLS will play video encoded with the H.264 or HEVC/H.265 codecs.) The HTTP server also creates a .M3U8 playlist file (e.g. manifest file) that serves as an index for the video chunks. That way, even if you choose to broadcast live using only a single quality option, the file will still exist.</p><h3>How to Use</h3><p><a href="https://github.com/core-player/playcore-hls">@core-player/playcore-hls</a> is a decoding service for <a href="https://github.com/core-player/vue-core-video-player">vue-core-video-player</a>. And you can easily import it and support HLS decoding.</p><pre>$ npm install vue-core-video-player --save<br>$ npm install @core-player/playcore-hls --save</pre><p>Then edit your vue file.</p><pre>&lt;template&gt;<br>  &lt;div id=&quot;app&quot;&gt;<br>    &lt;div class=&quot;player-container&quot;&gt;<br>      &lt;vue-core-video-player :core=&quot;HLSCore&quot; src=&quot;your_file.m3u8&quot;&gt;&lt;/vue-core-video-player&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>import VueCoreVideoPlayer from &#39;vue-core-video-player&#39;<br>import HLSCore from &#39;@core-player/playcore-hls</pre><pre>Vue.use(VueCoreVideoPlayer)</pre><pre>export default {<br>  name: &#39;App&#39;,<br>  data () {<br>    return {<br>      HLSCore<br>    }<br>  }<br>}</pre><pre>&lt;/script&gt;</pre><p>The plugin is powered by the famous framework <a href="https://github.com/video-dev/hls.js/">hls.js</a>. And you can import your own hls.js CDN source via script in your HTML file.</p><pre>... <br>&lt;<strong>div</strong> id=&quot;app&quot;&gt;&lt;/<strong>div</strong>&gt;</pre><pre>&lt;<strong>script</strong> src=&quot;your_cdn_hls.min.js&quot;&gt;&lt;/<strong>script</strong>&gt;</pre><pre>&lt;<strong>scipt</strong> src=&quot;your_vue_bundle.main.js&quot;&gt;&lt;/<strong>script</strong>&gt;<br>...</pre><p><a href="https://github.com/core-player/playcore-hls/tree/master/example">Demo</a></p><h3>Read More</h3><ul><li><a href="https://www.dacast.com/blog/hls-streaming-protocol/">What is HLS streaming and when should you use it</a></li><li><a href="https://github.com/video-dev/hls.js/">hls.js</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d24b5c639da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to check browser crash via JavaScript]]></title>
            <link>https://medium.com/@JackPu/how-to-check-browser-crash-via-javascript-fa7d5af5e80b?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa7d5af5e80b</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[service-worker]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Mon, 20 Apr 2020 03:57:28 GMT</pubDate>
            <atom:updated>2020-04-20T03:57:28.831Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NlJZeo3b-MTY3NwkDQKZjw.jpeg" /></figure><p>One day, the PM vomited in the group and opened his own website. The browser crashed. Then some operations followed the comments, saying that one day also encountered this situation. At this time, HR also jumped out and said that the interview candidate also encountered this situation. It seems that at this time, no matter what our own computer is, this problem must be concluded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7dmr4BGTmnAFJOwN.png" /><figcaption>Chrome Crash UI</figcaption></figure><h3>Why it happens</h3><p>In fact, when you are developing daily, you will occasionally encounter Crash problems, but most of the reasons are the problems of our code logic, so the rate of reproduction is very high, and we are also easy to find out the reason.</p><p>In fact, Chrome’s crash is undoubtedly judged from two dimensions. For example, if there is a code execution that consumes CPU calculation and memory occupation, Chrome uses a garbage collection mechanism to eliminate objects that are not referenced. If our code is not written, it is easy to cause Increasing the number of objects that cannot be destroyed indefinitely can easily cause very high memory usage. Or maybe we are in an infinite loop on the DOM operation of the page and continue to perform DOM operations. This time, the entire render process is stuck.</p><p>The second is related to the software conflict or environment of the user’s system or the computer itself, which may require customer service to communicate with the user.</p><p>Of course, I just mentioned the possible reasons. If we can confirm that most people have cases of recurrence, and they are distributed in different operating systems and Chrome versions, we will temporarily refer to it as a certain recurrence under certain conditions. problem.</p><h3>Crash Data Collector</h3><p>Since this kind of problem is more distributed in the user’s browser, we need key information to ensure that we can monitor the user’s Crash.</p><p>The most useful way is <a href="https://zhuanlan.zhihu.com/p/40273861">Using Service Worker to ping the main thread</a>。</p><p>The general principle is that the JS Main Thread will send a heartbeat message to the Service Worker, telling it, “I am still working”; then suddenly, the Service Worker finds that no one has sent him a message, and the page has not notified me. It is turned off, then there is a high probability that the page has crashed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-UyerQTz5zZmWLaC.png" /></figure><p>As for why Service Worker can implement these monitoring, if you are interested, you can read <a href="https://www.jackpu.com/is-service-worker-in-sandbox/">“Is Service Worker in Sandbox”</a> introduces the architecture of the Service Worker, you can understand why Service Worker can handle the collapse of the implementation of the buried point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ijxd17qRzCTvyX8z.jpg" /></figure><h3>Code Design</h3><p>Since our buried point library is extracted separately, we will design it as a plug-in form for easy introduction and configuration.<br>We create a new sw-start.js, which is the code that was introduced when you needed to inject the Service Worker.</p><pre><strong>const</strong> CHECK_CRASH_INTERVAL = 10000;<br><strong>const</strong> CRASH_THRESHOLD = 15000;</pre><pre>// your log send service<br><strong>function</strong> <strong>_sendlog</strong>(data) {<br>  <strong>const</strong> url = &#39;xxx&#39;;<br>  fetch(url, data);<br>}</pre><pre><strong>function</strong> <strong>_equalObjectValue</strong>(a, b) {<br>  <strong>return</strong> JSON.stringify(a) === JSON.stringify(b);<br>}</pre><pre><strong>function</strong> <strong>initLogSWCrashWatch</strong>() {<br>  <strong>let</strong> pages = {};<br>  <strong>let</strong> timer;<br>  <strong>let</strong> sendData = {};<br>  <strong>function</strong> <strong>_checkCrash</strong>() {<br>    <strong>const</strong> now = Date.now();<br>    Object.keys(pages).forEach((id) =&gt; {<br>      <strong>const</strong> page = pages[id];<br>      // check time throddle<br>      <strong>if</strong> ((now - page.t) &gt; CRASH_THRESHOLD) {<br>        <strong>if</strong> (!_equalObjectValue(sendData, pages[id].data)) {<br>          _sendlog(pages[id].data);<br>          sendData = pages[id].data;<br>        }<br>        <strong>delete</strong> pages[id];<br>      }<br>    });<br>    <strong>if</strong> (Object.keys(pages).length === 0) {<br>      clearInterval(timer);<br>      timer = null;<br>    }<br>  }<br>  // check message<br>  self.addEventListener(&#39;message&#39;, (e) =&gt; {<br>    <strong>const</strong> data = e.data;<br>    <strong>if</strong> (data.type === &#39;heartbeat&#39;) {<br>      pages[data.id] = {<br>        t: Date.now(),<br>        data: data.data,<br>      };<br>      <strong>if</strong> (!timer) {<br>        timer = setInterval(() =&gt; {<br>          _checkCrash();<br>        }, CHECK_CRASH_INTERVAL);<br>      }<br>    } <strong>else</strong> <strong>if</strong> (data.type === &#39;unload&#39;) {<br>      <strong>delete</strong> pages[data.id];<br>    } <strong>else</strong> <strong>if</strong> (data.type === &#39;start&#39;) {<br>      pages = {};<br>    }<br>  });<br>}</pre><pre>initLogSWCrashWatch();</pre><p>After the completion, you need to import the code into the sw.js file at the entry file when PWA registration:</p><pre>importScripts(&#39;https://your_cdn.com/_对应版本号_/sw-start.js&#39;);<br>...</pre><p>We introduce library initialization and message sending in the front-end JS:</p><pre><strong>const</strong> HEART_INTERVAL = 10000;</pre><pre><strong>const</strong> DEFAULT_OPTIONS = {<br>  collectData() {<br>    <strong>return</strong> {};<br>  },<br>};</pre><pre><strong>class</strong> <strong>SWService</strong> {<br>  <strong>constructor</strong>(options = {}) {<br>    <strong>if</strong> (!window.logCrashActions) {<br>      window.logCrashActions = [];<br>    }<br>    <strong>this</strong>.options = Object.assign(DEFAULT_OPTIONS, options);<br>    <strong>if</strong> (<strong>this</strong>._checkServiceWorker()) {<br>      <strong>this</strong>.init();<br>      <strong>this</strong>.recordAction();<br>    }<br>  }</pre><pre>  _checkServiceWorker() {<br>    <strong>return</strong> navigator.serviceWorker &amp;&amp; navigator.serviceWorker.controller;<br>  }</pre><pre>  init() {<br>    <strong>const</strong> sessionId = util.getUUID();<br>    <strong>const</strong> self = <strong>this</strong>;<br>    <strong>const</strong> heartbeat = <strong>function</strong> () {<br>	 // collectData 为传入自定义函数用于包装埋点数据，比如 url, UA 等<br>      <strong>const</strong> data = self.options.collectData({<br>        lastAction: window.libCollectorCrashActions,<br>      });<br>      navigator.serviceWorker.controller.postMessage({<br>        type: &#39;heartbeat&#39;,<br>        id: sessionId,<br>        data,<br>      });<br>    };<br>    document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt; {<br>      navigator.serviceWorker.controller.postMessage({<br>        type: &#39;start&#39;,<br>        id: sessionId,<br>      });<br>    });<br>    window.addEventListener(&#39;beforeunload&#39;, () =&gt; {<br>      navigator.serviceWorker.controller.postMessage({<br>        type: &#39;unload&#39;,<br>        id: sessionId,<br>      });<br>      clearInterval(heartbeat);<br>    });<br>    setInterval(heartbeat, HEART_INTERVAL);<br>    heartbeat();<br>  }</pre><pre>  recordAction() {<br>    // delegate.bind(document, &#39;[data-crash-action]&#39;, &#39;click&#39;, (e) =&gt; {<br>    //   lastAction = e.dataset.crashAction;<br>    // });<br>  }<br>}</pre><pre><strong>export</strong> <strong>default</strong> SWService;</pre><p>In this way, you can control the instantiation of itself through your JS.<br>Separate it separately to facilitate the introduction of other developments. After all, Crash monitoring is not necessarily used in most applications. For example, many internal platforms do not have high-performance requirements, but they do not have to be written into regular functions.</p><h3>Read More</h3><ul><li><a href="https://www.jackpu.com/is-service-worker-in-sandbox/">Is Service Worker in Sandbox</a></li><li><a href="https://zhuanlan.zhihu.com/p/40273861">如何监控网页崩溃？</a></li><li><a href="https://forum.unity.com/threads/webgl-never-releasing-memory.520766/">Webgl never releasing memory</a></li><li><a href="https://stackoverflow.com/questions/23598471/how-do-i-clean-up-and-unload-a-webgl-canvas-context-from-gpu-after-use">how-do-i-clean-up-and-unload-a-webgl-canvas-context-from-gpu-after-use</a></li><li><a href="https://blogs.unity3d.com/2016/09/20/understanding-memory-in-unity-webgl/?_ga=2.95165081.461720074.1586093060-1337502360.1586093060">Understanding Memory in Unity WebGL</a></li><li><a href="https://www.khronos.org/assets/uploads/developers/library/2010_siggraph_bof_webgl/WebGL-BOF-2-WebGL-in-Chrome_SIGGRAPH-Jul29.pdf">WebGL in Chrome</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa7d5af5e80b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Vue-core-video-player to create a video player]]></title>
            <link>https://medium.com/@JackPu/getting-started-with-vue-core-video-player-to-create-a-video-player-a60bd277af5?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a60bd277af5</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[video-player]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Fri, 13 Mar 2020 11:22:12 GMT</pubDate>
            <atom:updated>2020-03-13T11:22:12.004Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z3ufhUERShVMGlSN07KtPg.jpeg" /></figure><p>I have focused on the video player in the last few years. With the growth of video content and bandwidth, so many websites using video to give users more information. So I hope this vue.js plugin helps you solve it.</p><p><a href="https://github.com/core-player/vue-core-video-player">vue-core-video-player</a> is a lightweight video player for <a href="https://github.com/vuejs/vue">Vue.js</a>. It is easy to get started. You’ll write less code to create a stronger video player. And it is friendly for server-side rendering, so it could be easy for spiders or other bots to show your video source.</p><h3>Get Started</h3><pre>npm install vue-core-video-player --save</pre><p>You can also use yarn：</p><pre>yarn add vue-core-video-player --save</pre><p>Then edit your main.js to import the module.</p><pre>import VueCoreVideoPlayer from &#39;vue-core-video-player&#39;</pre><pre>//...</pre><pre>Vue.use(VueCoreVideoPlayer)</pre><p>Thirdly, using the component in your player container.</p><pre>&lt;div id=&quot;app&quot;&gt;<br>  &lt;div class=&quot;player-container&quot;&gt;<br>    &lt;vue-core-video-player src=&quot;./your_video_source.mp4&quot;&gt;&lt;/vue-core-video-player&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>The final rendering preview below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXJ-Jvf9HhZqcQPHCbKxAA.png" /><figcaption>demo screenshot</figcaption></figure><p><a href="http://events.jackpu.com/vue-core-video-player-examples/">View Demo Online</a></p><h3>Basic Configuration</h3><h4>The video source</h4><p>Use src property to set the video source of your player. It must be the only three types below.</p><ul><li>String; It can be a relative path of your video file or some CDN URL.</li></ul><pre>&lt;vue-core-video-player src=&quot;https://media.vued.vanthink.cn/sparkle_your_name_am720p.mp4&quot;&gt;&lt;/vue-core-video-player&gt;</pre><ul><li>Array; It means you set the different resolution of the same video source; Our default resolution is 720p; And you must set two keys (resolution, src) of your array item.</li></ul><pre>const videoSource = [</pre><pre>{</pre><pre>src: &#39;https://media.vued.vanthink.cn/sparkle_your_name_am360p.mp4&#39;,</pre><pre>resolution: &#39;360p&#39;,</pre><pre>}, {</pre><pre>src: &#39;https://media.vued.vanthink.cn/sparkle_your_name_am720p.mp4&#39;,</pre><pre>resolution: &#39;720p&#39;,</pre><pre>}, {</pre><pre>src: &#39;https://media.vued.vanthink.cn/y2mate.com%20-%20sparkle_your_name_amv_K_7To_y9IAM_1080p.mp4&#39;,</pre><pre>resolution: &#39;1080p&#39;</pre><pre>}]</pre><p>If you want to play different file types in a different browser. You can add type property in an array;</p><pre>const videoSource = [</pre><pre>{</pre><pre>  src: &#39;https://media.vued.vanthink.cn/sparkle_your_name_am720p.webm&#39;,</pre><pre>  type: &#39;video/webm&#39;,</pre><pre>}, {</pre><pre>  src: &#39;https://media.vued.vanthink.cn/sparkle_your_name_am720p.mp4&#39;,</pre><pre>  type: &#39;video/mp4&#39;,</pre><pre>}]</pre><p><a href="https://caniuse.com/#search=video%20format">caniuse-video-format</a> show which browser supports the specified video file.</p><h4>Controls</h4><p>controls is set for the player bottom dashboard.</p><ul><li>String; ‘fixed’ indicates the bottom dashboard is still visible to users. ‘auto’ indicates the bottom dashboard will hide when there is no interaction between user and player.</li><li>Boolean;false indicates that the player will hide the bottom dashboard. true indicates that player will show the bottom dashboard and work like the &#39;auto&#39; value above;</li></ul><h4>Autoplay</h4><p>If you set autoplay, the player will try to play video. The different browser has different policies to handle autoplay action. If the player failed, it will show the play button for the user to touch.</p><h4>Video Playback control</h4><p>And it keeps the same attributes of <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video">HTML Video</a>.</p><ul><li>volume: the volume of video (0-1)</li><li>cover: it will show the cover of the video; If you set, the player autoplay successfully, the cover property will not work.</li><li>logo: it will show your logo of the player</li></ul><p>And you could read <a href="https://core-player.github.io/vue-core-video-player/configuration.html">The Official Document </a>to learn more about it.</p><h3>The Future</h3><p>In fact, web media player face with so many situations:</p><ul><li>different video format</li><li>live streaming</li><li>360 video</li><li><a href="https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding">hevc</a>/<a href="https://zh.wikipedia.org/zh-hans/AOMedia_Video_1">av1</a></li><li>mobile compatibility in different browsers</li></ul><p>So I am trying to provide the <a href="https://github.com/core-player/vue-core-video-player/blob/master/src/core/base.js">playback core</a> for developers to extend the basic class. Then UI elements can subscribe to data from <a href="https://github.com/core-player/vue-core-video-player/blob/master/src/constants/EVENTS.js">events</a>.</p><p>I hope everyone interested in the project can open a <a href="https://github.com/core-player/vue-core-video-player/pulls">PR</a> or discuss <a href="https://github.com/core-player/vue-core-video-player/issues">issues</a> 💐 .</p><p>Github: <a href="https://github.com/core-player/vue-core-video-player">https://github.com/core-player/vue-core-video-player</a></p><p>Docs: <a href="https://core-player.github.io/vue-core-video-player/">https://core-player.github.io/vue-core-video-player/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a60bd277af5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Summary of Video Quality Metrics]]></title>
            <link>https://medium.com/@JackPu/the-summary-of-video-quality-metrics-5b4964d79876?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b4964d79876</guid>
            <category><![CDATA[videos]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[streaming]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Wed, 11 Dec 2019 04:18:38 GMT</pubDate>
            <atom:updated>2019-12-11T04:18:38.906Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_f5gQKRH6hAd9HqwYxv9g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b4964d79876" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to play AV1 Video on Web]]></title>
            <link>https://medium.com/@JackPu/how-to-play-av1-video-on-web-779ed6faef59?source=rss-bbd1c67bba5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/779ed6faef59</guid>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[videos]]></category>
            <category><![CDATA[av1]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[JackPu]]></dc:creator>
            <pubDate>Tue, 10 Dec 2019 08:54:41 GMT</pubDate>
            <atom:updated>2019-12-10T08:54:41.914Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h0WA-f42PoXYLxvbkht77g.jpeg" /></figure><p>[<a href="https://en.wikipedia.org/wiki/AV1">AV1</a>] is the most advanced video codec in 2019 developed by <a href="https://en.wikipedia.org/wiki/Alliance_for_Open_Media">Alliance for Open Media</a> (AOMedia). The Alliance’s goal is to combine its members’ technology and expertise to develop a video format that is royalty-free, has higher compression efficiency and is more suitable for use in browsers and on the web. And AV1 is capable of generating files that are up to 30–50% smaller than H.264/VP8 and up to 30% smaller than HEVC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/0*oLrRb_gvD_SauniT.png" /><figcaption>Via: <a href="https://evilmartians.com/chronicles/better-web-video-with-av1-codec">https://evilmartians.com/chronicles/better-web-video-with-av1-codec</a></figcaption></figure><p>It is supported from Chrome 69. And the recent status is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jVG6fSBCy4IdYoah.png" /><figcaption><a href="https://caniuse.com/#search=AV1">https://caniuse.com/#search=AV1</a></figcaption></figure><p>So we should still use some normal video formats to keep the experience that can not be interrupted by browsers.</p><pre>&lt;video controls &gt;</pre><pre>  &lt;source src=&quot;xxx.hevc.mp4&quot; type=&quot;video/mp4; codecs=hevc,mp4a.40.2&quot; /&gt;</pre><pre>  &lt;source src=&quot;xxx.av1.mp4&quot; type=&quot;video/mp4; codecs=av01.0.05M.08,opus&quot; /&gt;</pre><pre>  &lt;source src=&quot;xxx.h264.mp4&quot; type=&quot;video/mp4; codecs=avc1.4D401E,mp4a.40.2&quot; /&gt;</pre><pre>&lt;/video&gt;</pre><p>And we can use <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType">canPlayType</a> to detect if the browser could play the video codec.</p><pre>const videoEle = document.querySelector(&#39;video&#39;);</pre><pre>if (videoEle.canPlayType(&#39;video/mp4; codecs=av01.0.05M.08,opus&#39;)) {</pre><pre>  // play av1</pre><pre>} else {</pre><pre>  // play others</pre><pre>}</pre><p>If you want to play AV1 on the browsers that are not going to support the codec, you may try <a href="https://github.com/BrianJFeldman/ffmpeg.js.wasm">WebAssembly + FFmpeg</a> . It’s hard for developers to control the frame and audio. Anyway, it did solve the problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=779ed6faef59" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>