<?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 Romain Sylvian on Medium]]></title>
        <description><![CDATA[Stories by Romain Sylvian on Medium]]></description>
        <link>https://medium.com/@rsylvian?source=rss-7cb07eed9a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zrxStO9V5TVp8Uo2eLjSdA.jpeg</url>
            <title>Stories by Romain Sylvian on Medium</title>
            <link>https://medium.com/@rsylvian?source=rss-7cb07eed9a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:56:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rsylvian/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[WebRTC peer-to-peer data, video, and audio calls with Peer.JS]]></title>
            <link>https://medium.com/@rsylvian/webrtc-peer-to-peer-data-video-and-audio-calls-with-peer-js-24f79a09f67d?source=rss-7cb07eed9a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/24f79a09f67d</guid>
            <category><![CDATA[webrtc]]></category>
            <category><![CDATA[skype]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[peer-to-peer]]></category>
            <dc:creator><![CDATA[Romain Sylvian]]></dc:creator>
            <pubDate>Tue, 09 Feb 2016 10:08:22 GMT</pubDate>
            <atom:updated>2017-06-13T04:22:38.736Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*DZlvKw2Q8NlF49PILTzo1Q.jpeg" /><figcaption>Screenshot of Skype software. Copyright by Skype Limited/Microsoft.</figcaption></figure><h3>What is exactly WebRTC?</h3><p>WebRTC is an initiative that started in May 2011. As in July 2015, much progress has been made since it’s now supported on Google Chrome, Mozilla Firefox, Opera and the Android, iOS operating systems.</p><p>It aims at establishing real-time communication inside of a browser. With this technology you can exchange plain data, video data &amp; audio data with the Peer-to-peer (P2P) decentralized communication model. One of the most popular example is probably the website <a href="http://appear.in/">appear.in</a> that replicates Skype software features into your browser.</p><h3><strong>What about Peer.JS?</strong></h3><p><a href="http://peerjs.com/">Peer.js</a> wraps WebRTC technology and allows the establishment of peer connections between two clients based on unique IDs. In order to have a working system, Peer.JS needs a server called <a href="https://github.com/peers/peerjs-server">PeerServer</a> that you can either host yourself or use one of the <strong>free</strong> cloud instance provided by <a href="http://peerjs.com/">peerjs.com</a>. As you might understand, the PeerServer is only needed to <a href="http://blog.vline.com/post/63765098884/webrtc-if-its-p2p-why-do-i-need-a-server">connect the peers</a>, any communication that occurs after happens directly between the peers.</p><h3><strong>Learning by example</strong></h3><p>Learning with a concrete example is always easier! So that’s why in this post, I’ll show you how to recreate, using peer.JS, your own “clone” of a limited version of Skype.</p><p>The very first step is to add the PeerJS client library to your webpage :</p><pre>&lt;script src=&quot;http://cdn.peerjs.com/0.3/peer.min.js&quot;&gt;&lt;/script&gt;</pre><p>Then you need to <a href="http://peerjs.com/peerserver">Sign up for a PeerServer cloud API key</a>. As I said earlier, PeerJS uses PeerServer for session metadata and establish connection between peers.</p><p>This is how you can define a peer:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4cb9b153c48b0d7f0b5f52bdf4db03f2/href">https://medium.com/media/4cb9b153c48b0d7f0b5f52bdf4db03f2/href</a></iframe><p>In order to connect, a peer needs to know the id of the other peer. This library is not gonna help you for this, so you’re in charge of communicating the peer IDs between users of your site (by URL or database for example).</p><p>Let’s create a friend for our first peer!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19422ccab6597faeff6ab00b49b19864/href">https://medium.com/media/19422ccab6597faeff6ab00b49b19864/href</a></iframe><p>In the following code we gonna make the first peer call the second peer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f9b3d890790af5b2877778c5e0d530e/href">https://medium.com/media/5f9b3d890790af5b2877778c5e0d530e/href</a></iframe><h3>Media Stream?</h3><p>As you can notice in the code above, we are using a variable called <em>mediaStream. </em>This is the last piece of the project we need to get done in order to have a functional prototype (yes already!).</p><p>When calling or answering a call, a Media Stream should be provided. It represents the local video &amp; audio stream that can be obtained via the browser. When answering a call, the MediaStream is optional and will result as a one-way call.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/798c9883d77a77f22f5e32c3470e211e/href">https://medium.com/media/798c9883d77a77f22f5e32c3470e211e/href</a></iframe><p>You now have <strong><em>window.localStream </em></strong>that is your mediaStream.<strong><em> </em></strong>You can simply display your own stream in an HTML canvas:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0720fc8d184a6d8657a05a983f67a5fb/href">https://medium.com/media/0720fc8d184a6d8657a05a983f67a5fb/href</a></iframe><p>and provide window.localStream as the parameter for call() and answer() functions.</p><p>To display your partner’s stream (the stream you are receiving over p2p) :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfed4976c75e5a716b2d324721f0913d/href">https://medium.com/media/cfed4976c75e5a716b2d324721f0913d/href</a></iframe><h3>Conclusion</h3><p>If you followed the instructions correctly you should be able to establish a video and audio call between peer one and peer two … congratulations you made you own Skype “clone” !</p><p>I strongly encourage you to read the amazing Peer.JS <a href="http://peerjs.com/docs">documentation</a> that will give you a complete overview of the technology. If you want to learn more about Skype “cloning”, you can also take a look at my personal open-source project, <a href="https://github.com/MyBoon/oro-chat">oro-chat</a>, that will show you more tips and tricks. You can also try it by following these <a href="https://github.com/MyBoon/oro-chat#local-example">instructions</a>.</p><p>Have fun with WebRTC &amp; peer.JS!</p><p><strong><em>Sources:</em></strong></p><ul><li>[1] <a href="http://blog.vline.com/post/63765098884/webrtc-if-its-p2p-why-do-i-need-a-server">WebRTC: If it’s P2P, why do I need a server?</a></li><li>[2] <a href="http://peerjs.com/docs/#start">Peer.JS official documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24f79a09f67d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to turn every website into a RESTful API]]></title>
            <link>https://medium.com/@rsylvian/how-to-turn-every-website-into-a-restful-api-9180a9bab43f?source=rss-7cb07eed9a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9180a9bab43f</guid>
            <category><![CDATA[website]]></category>
            <category><![CDATA[scraping]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Romain Sylvian]]></dc:creator>
            <pubDate>Tue, 09 Feb 2016 09:04:14 GMT</pubDate>
            <atom:updated>2016-02-09T09:04:59.435Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to turn any website into a RESTful API</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWar1fLgJPt-a_KYyOzP5w.jpeg" /><figcaption>Credits: istockphoto.com</figcaption></figure><h3>What is a RESTful API?</h3><p>In case you are not familiar with what is a RESTful API, I suggest you to take a look at this <a href="https://www.youtube.com/channel/UCV4-mrR8UZh6AsWZbmW5uhQ">WebConcepts</a> youtube video.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7YcW25PHnAA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7YcW25PHnAA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7YcW25PHnAA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/798968e761ccc490357b3cc4338fc2dd/href">https://medium.com/media/798968e761ccc490357b3cc4338fc2dd/href</a></iframe><h3>Why would I need to turn a website into an API?</h3><p>Even though most of the services we are using (Facebook, Twitter, Youtube …) already have APIs, it might happen that some doesn’t provide an easy way to access their data. As a developer, it might be useful, from time to time to be able to access this data in a RESTful way.</p><p>What you’ll find below, is a common practice called <em>scraping. </em>Scraping <strong>public data </strong>is not illegal but you should make sure that you are permitted to scrape the content before scraping. A thorough evaluation of the legal issues involved can be seen <a href="http://www.bna.com/legal-issues-raised-by-the-use-of-web-crawling-and-scraping-tools-for-analytics-purposes">here</a>.</p><h3>Prerequisites</h3><p>In the following explanations, we’ll use <a href="https://nodejs.org/">Node.JS</a> &amp; <a href="http://expressjs.com/">Express</a> as the technology stack. If you don’t know anything about those technologies, you should still be able to understand and adapt the provided code.</p><p>After making sure that node.js &amp; npm are installed on your environment, you’ll have to install these three dependencies:</p><pre>$ npm install express<br>$ npm install x-ray<br>$ npm install q</pre><h3>Our <a href="https://www.kickstarter.com/">Kickstarter</a> API</h3><p>Let’s train ourself by writing a <strong>personal </strong>Kickstarter API by only using <em>scraping techniques. </em>In this article we’ll focus on only two features:</p><ul><li><strong>GET /projects</strong> -&gt; will return an array of popular Kickstarter projects</li><li><strong>GET /projects/:type </strong>-&gt; will return an array of Kickstarter projects sorted by type (<a href="https://www.kickstarter.com/discover/advanced?sort=newest">newest</a>, <a href="https://www.kickstarter.com/discover/advanced?sort=magic">magic</a>, <a href="https://www.kickstarter.com/discover/advanced?sort=popularity">popularity</a> …)</li></ul><h3>Part 1: Express.JS</h3><p>This is over simplifying it, but <a href="https://en.wikipedia.org/wiki/Express.js">Express.js</a> is to <a href="http://en.wikipedia.org/wiki/Node.js">Node.js</a> what <a href="http://en.wikipedia.org/wiki/Ruby_on_Rails">Ruby on Rails</a> is to <a href="http://en.wikipedia.org/wiki/Ruby_%28programming_language%29">Ruby</a>. It’s a light-weight web application framework to help organize your web application architecture on the server side. It’s commonly used to build RESTful API in Node.js.</p><p>Here is our <em>index.js</em> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b964162d09ce1fa86ea526dee3be646c/href">https://medium.com/media/b964162d09ce1fa86ea526dee3be646c/href</a></iframe><p>That’s pretty much it for the Express part. Nothing crazy if you already know how to use this framework.</p><h3>Part 2: Scraping</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*u9vL_JC4aViGKKq34sI4Xg.png" /></figure><p>To perform the scraping part of our project, we are going to use the <a href="https://github.com/lapwinglabs/x-ray">x-ray</a> node module. This module depends on the <a href="https://github.com/cheeriojs/cheerio">cheerio</a> module but also includes some methods to automate common scraping tasks. One of my favorite feature is probably if you need to scrape dynamic pages … with the <a href="https://github.com/lapwinglabs/x-ray-phantom">x-ray’s PhantomJS driver</a> it’s as easy as a pie!</p><p>Let’s define our <em>scraping.js</em> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1c7459e52a49ed85d743188d08c0174/href">https://medium.com/media/e1c7459e52a49ed85d743188d08c0174/href</a></iframe><p>Here is how we are using Xray() :</p><ul><li>The first parameter is the url you want to scrape. In our case, <strong>http://www.kickstarter.com/discover/advanced?sort=</strong> + the type provided (popularity will be the default if null).</li><li>The second parameter is a jQuery-like selector. It has to select an HTML node that each of your item has. In our case, all the items have a <em>project</em> css class:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*8AnUW03jq-RfS2aVvS1Ejw.png" /><figcaption>All the items have a ‘project” css class.</figcaption></figure><ul><li>Finally the third parameter is a <a href="https://github.com/lapwinglabs/x-ray/blob/master/examples/collection-of-collections.js">collection of collections</a>. Again, each field is a jQuery-like string that is also able to select on attributes. The syntax for selecting on attributes is <strong>selector@attribute</strong>. If you do not supply an attribute, the default is selecting the <em>innerText</em>.</li></ul><p>In the Xray() callback, some data cleanup are performed in order to extract the id:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*1Vmfs9pl0V8kyoURkLFhaw.png" /></figure><p>The promise is then resolved with the whole object containing all the data.<br>If you followed all the steps correctly, you might be able to run your API locally by typing:</p><pre>$ node index.js</pre><p>Navigating to <a href="http://localhost:3000/projects"><strong>http://localhost:3000/projects</strong></a> will give you data that will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*SgsAtthWEBuhvCUSIydK0A.png" /><figcaption><a href="https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc">https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc</a></figcaption></figure><p>Looks like it’s working!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*HHh-ifJk8EVnloOf-ALNZw.png" /></figure><h3>Conclusion</h3><p>That’s it! You successfully learned how to turn any website into an API. A lot of more work is necessary if you want to turn the whole kickstarter website into a RESTful API and getting the projects is only the first step!</p><p>If you are interested to learn more about scraping techniques with node, I recommend you to take a look at the x-ray official <a href="https://github.com/lapwinglabs/x-ray">documentation</a>. You’ll be able to learn more about concurrency, throttles, delays, timeouts and limits to help you scrape any page responsibly. If you want to check the code we wrote during this article, it is available on Gist <a href="https://gist.github.com/MyBoon/ea4f8976d2383593e368">here</a> and <a href="https://gist.github.com/MyBoon/c260bcce121f1a5954a7">here</a>.</p><p>Sources:</p><ul><li>[1] <a href="http://www.quora.com/What-is-the-legality-of-web-scraping">http://www.quora.com/What-is-the-legality-of-web-scraping</a></li><li>[2] <a href="http://stackoverflow.com/questions/12616153/what-is-express-js">http://stackoverflow.com/questions/12616153/what-is-express-js</a></li><li>[3] <a href="https://github.com/lapwinglabs/x-ray">https://github.com/lapwinglabs/x-ray</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9180a9bab43f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>