<?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 Daniel Almeida on Medium]]></title>
        <description><![CDATA[Stories by Daniel Almeida on Medium]]></description>
        <link>https://medium.com/@daniel_62811?source=rss-fe4bd274611b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*arZXto2bPOT1s3KzyRb2OQ.jpeg</url>
            <title>Stories by Daniel Almeida on Medium</title>
            <link>https://medium.com/@daniel_62811?source=rss-fe4bd274611b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 03:14:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@daniel_62811/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[How to Protect Amazon S3 Media Links with Elixir and Arc]]></title>
            <link>https://medium.com/@daniel_62811/how-to-protect-amazon-s3-media-links-with-elixir-and-arc-f040c9d3da80?source=rss-fe4bd274611b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f040c9d3da80</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Daniel Almeida]]></dc:creator>
            <pubDate>Fri, 08 May 2020 12:15:14 GMT</pubDate>
            <atom:updated>2020-05-08T12:15:14.175Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AfM1UzQsQeXORxB9wOqwgQ.png" /></figure><p>A good way to add an extra layer of security when sharing files stored somewhere in the cloud is by using a <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-urls.html">signed url</a>. This means that the url will have an expiration time attached and it should not be easily guessable by someone who wants to access the server’s hosted resources.</p><p>Usually, there’s an algorithm that generates a unique token to be used as a parameter at the url string.</p><p>With this article, I will describe how the signing can be achieved in Elixir with the <a href="https://github.com/stavro/arc">Arc</a> library, an <a href="https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html">Amazon S3 bucket</a>, and an <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html">EC2 machine</a>.</p><h3>Setting up the Infrastructure 🛠</h3><h4><a href="https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html">Amazon S3 bucket</a></h4><p>The bucket should be configured using the <em>Block all public access </em>option to ensure the bucket is isolated and no-one can access it from the outside 🔒</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*0stgkUCBonV0m2T97wKGmg.png" /><figcaption>Block all public access — <strong>on</strong></figcaption></figure><h4><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html">Amazon EC2 instance</a></h4><p>Since our S3 bucket is not accessible from an EC2 instance we need to create an IAM Role with an IAM Policy attached that grants the EC2 instance access to the S3 bucket and perform, for example, a GET operation on some resource.</p><ol><li><strong>Policy</strong></li></ol><p>Go to the IAM service and create a new policy using the JSON editor mode, then use the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12ffaf265d9e9b6ac2ce65b0d95d48eb/href">https://medium.com/media/12ffaf265d9e9b6ac2ce65b0d95d48eb/href</a></iframe><p>This policy allows the GET, PUT and DELETE action on all objects under the <a href="https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html">Amazon Resource Name (ARN)</a> listed on the “Resource” array. Note that you can copy the ARN identifier from the S3 buckets list. You just need to select the bucket and then press the <em>Copy ARN</em> button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZeipLaAgnfMqLi4FTRrLIg.png" /><figcaption>S3 Bucket — Copy ARN</figcaption></figure><p>2.<strong> IAM Role</strong></p><p>Go to the Roles section and press the <em>Create role</em> button. Then select AWS Services and the EC2 use case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*TuIxdPBfCc5Q6ncJKhlr2w.png" /><figcaption>IAM Role — EC2 use case</figcaption></figure><p>Hit next and then search for the Policy created above and attach it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*24BsZ-UplYmPNaoYXkXVVQ.png" /><figcaption>Attach Policy</figcaption></figure><p>Create the role and name it something meaningful to be used next.</p><p>3. <strong>Attach the Role to the EC2 instance</strong></p><p>Go to the EC2 Service page and select the EC2 instance that should have access to the S3 bucket, then press <em>Actions</em> and <em>Attach/Replace IAM Role:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*C_GuLUrJEeR62cxY4pi5rw.png" /><figcaption>Attach Role</figcaption></figure><p>Then you just need to select the created role and attach it to the EC2 instance.</p><h3>Elixir code ✍️</h3><p><a href="https://github.com/stavro/arc">Arc</a> is a very useful library, it handles the file storage from/to an S3 bucket using the <a href="https://github.com/ex-aws/ex_aws_s3">ex_aws_s3</a> library.</p><p>Unfortunately, this library doesn’t have any release since 2018, but it&#39;s widely used, and for sure serves its purpose. To use Arc in your project you just need to set up the dependencies and configs as explained in its <a href="https://github.com/stavro/arc/blob/master/README.md">README.md</a>.</p><p>Then you just need to store some files using the <a href="https://github.com/stavro/arc/blob/master/README.md#storage-of-files"><em>store</em></a> function or the arc_ecto <a href="https://github.com/stavro/arc_ecto"><em>cast_attachments</em></a> as described on GitHub.</p><p>After your file is safe and secure on your private S3 bucket you can retrieve it with a <strong>signed</strong> link:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71555ba5797bed601b5ba5a489011806/href">https://medium.com/media/71555ba5797bed601b5ba5a489011806/href</a></iframe><p>You can specify an expiration time to the url using the <em>expires_in </em>parameter, the default value for the expiration time on <a href="https://github.com/stavro/arc">Arc</a> is 5 minutes, the maximum allowed by the <a href="https://github.com/ex-aws/ex_aws_s3">ex_aws_s3</a> is 7 days.</p><p>The recommendation is for this expiration time to be as low as possible, to reduce the chance that some external user catches the url and access the private resource.</p><h3>Final Thoughts 🤔</h3><p>With this simple solution, we ensure that the S3 buckets are more secure. This doesn’t mean that the files are behind some bullet proof wall but surely means that getting into them is more difficult.</p><h3>Thank you for reading!</h3><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialized in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f040c9d3da80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Distributing Custom B2B iOS Apps privately]]></title>
            <link>https://medium.com/@daniel_62811/distributing-custom-b2b-ios-apps-privately-6520cee3dcb0?source=rss-fe4bd274611b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6520cee3dcb0</guid>
            <category><![CDATA[b2b]]></category>
            <category><![CDATA[app-store]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[distribution]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Daniel Almeida]]></dc:creator>
            <pubDate>Wed, 17 Jul 2019 09:31:27 GMT</pubDate>
            <atom:updated>2019-07-17T09:31:27.342Z</atom:updated>
            <content:encoded><![CDATA[<h3>Distributing Custom B2B iOS Apps Privately</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9AMz8fn43ogb553qGXxEOQ.png" /></figure><p>Recently one of our clients came up with the requirement of delivering their iOS apps only to a specific organization without making it public and allowing the end users to install the apps on their private phones. We’ve started researching on how to make the apps available.</p><p>The <a href="https://developer.apple.com/programs/enterprise/">Enterprise Program</a> seemed to be the best solution. Taking a look on <em>Enterprise Program</em> descriptions, Apple specifically says:</p><blockquote>Distribute proprietary, in-house iOS, watchOS, and tvOS apps within your organization. Securely host and deploy apps to your employees’ devices.</blockquote><p>In this case the client’s organization must distribute to a third organization, and this is not allowed by the Apple Enterprise Program guidelines/rules.</p><p>We contacted Apple to get some clarifications on how to distribute the app and their answer was: <a href="https://developer.apple.com/business/custom-apps/"><em>Custom Apps</em></a>. They also advised that the app must be installed only on devices belonging to users from the <em>Business Account</em> organization.</p><p>The Custom Apps <a href="https://developer.apple.com/business/custom-apps/">home page</a> is pretty explicit on what’s the purpose of this service:</p><blockquote>Businesses that you identify in App Store Connect will see your app and be able to purchase it in the Apps and Books section of Apple Business Manager. You can offer custom apps for free or at any price tier you choose. Identify the businesses who can download your app and set a release date in App Store Connect. They will be able to find your app on Apple Business Manager once it’s published.</blockquote><p>We decided to test this way of delivering iOS apps, but all the information regarding this is a bit confusing and disperse along the internet. After a successful delivery we decided to explain all the process in the following tutorial.</p><h3>1. Set up Apple Business Manager account (target organization)</h3><p>In order to distribute the app to the end users organization, the organization itself needs an account on <a href="https://business.apple.com/">Apple Business Manager</a>. To enroll an organization Apple requires the D-U-N-S number, after the form is submitted Apple will approve the application. Some useful links with help can be found <a href="https://developer.apple.com/support/D-U-N-S/">here</a> and <a href="https://www.apple.com/business/site/docs/Apple_Business_Manager_Getting_Started_Guide.pdf">here</a>.</p><pre>The DEP Customer ID from the end users organization must be saved for the next steps, the number is behind the red square on the next image:</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoDVTET2V4yIryb0EB965w.png" /><figcaption>Apple Business Account: Settings</figcaption></figure><p>Also enable <em>Custom Apps</em> by pressing the enable button under the DEP ID number.</p><h3>2. Upload the app to App Store Connect (developer)</h3><p>You need the app ready to App Store Connect. Create the certificates needed and the app entry. Then upload it. <a href="https://help.apple.com/xcode/mac/current/#/dev067853c94">Here’s</a> some help on how to do that.</p><p><strong>Important</strong>: Do not submit your app to review yet!</p><h3>3. Set private distribution (developer)</h3><ul><li>On App Store Connect select the <strong>app</strong></li><li>Go to <strong><em>Pricing and Availability </em></strong>section</li><li>Choose the <strong><em>Available privately as a custom app for business </em></strong>under<strong><em> Distribution for Business and Education</em></strong></li><li>Select <strong>DEP ID</strong> type, add the <strong>ID</strong> saved on <strong>1.</strong> and the Organization Name. This step gives app access to a specified organization</li><li>Set the desired price as it is mandatory</li><li>Save the changes</li></ul><h3>4. Submit to review (developer)</h3><p>Yes, the app needs to be reviewed before it can be available to the end user’s organization. Usually, from our experience, this reviews are quicker than the public ones. 🙏</p><h3>5. Purchase the app (target organization)</h3><p>Access <a href="https://business.apple.com/">business.apple.com</a> and go to <em>Custom Apps Content</em>, then the shared app must appear. Note that once it is published from the <em>App Store Connect </em>the app usually take some time to be available at <em>Custom Apps</em>.</p><p>Then, you can either purchase <strong>Managed License Types</strong> or <strong>Redemption Codes.</strong></p><ul><li><strong>Managed Licenses</strong> can be used in an MDM platform to distribute the app to the organization devices.</li><li><strong>Redemption Codes </strong>are codes that can be redeemed by the end users within the App Store app itself.</li></ul><p>To solve our initial problem we choose the Redemption Codes option, here’s how it can be done:</p><ul><li>Go to <strong>Custom Apps</strong> section and select the desired app</li><li>Then, buy a license of type <strong>Redemption Codes.</strong> Note that each code can only be used once, you will need one for each user of the app.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZlqQdjyF_tTNritjBoZo-g.png" /><figcaption>Apple Business Account: Purchase licenses</figcaption></figure><ul><li>After you purchase the <strong>Redemption Code</strong> press the <strong>Download </strong>button to download a <strong>.xls</strong> with the codes and direct links to install the app from the App Store.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mW2z-ciWem7tErnQIFq69w.png" /><figcaption>Apple Business Account: Redemption Codes</figcaption></figure><ul><li>You can either open the links on an iPhone or redeem the codes from the App Store app itself, using the option <em>Redeem Gift Card or Code. </em>Then the app is installed and it will be always available on Purchased items.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*eLwDG1lRoZWkSTT9t3Ke2g.png" /><figcaption>App Store on iPhone: Redeem Code</figcaption></figure><h3>Final thoughts</h3><p>This definitely serves as a solution to our initial problem, but we think there are a few things that can be improved on Custom Apps:</p><ul><li>The usability of the website. It can become frustrating to interact after a little while;</li><li>Account sessions handling. When a user is logged in on App Store Connect and Business at the same time the session is lost;</li><li>Create a view for the list of codes instead of using only the .xls to show the codes/links.</li></ul><h4>Thank you for reading!</h4><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialised in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6520cee3dcb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing Phoenix Channels on a Mac App]]></title>
            <link>https://medium.com/@daniel_62811/testing-phoenix-channels-on-a-mac-app-abd393c4c6e?source=rss-fe4bd274611b------2</link>
            <guid isPermaLink="false">https://medium.com/p/abd393c4c6e</guid>
            <category><![CDATA[phoenix]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mac-apps]]></category>
            <category><![CDATA[websocket]]></category>
            <dc:creator><![CDATA[Daniel Almeida]]></dc:creator>
            <pubDate>Fri, 13 Apr 2018 16:54:47 GMT</pubDate>
            <atom:updated>2018-04-13T16:54:47.342Z</atom:updated>
            <content:encoded><![CDATA[<p>In one of our current projects here at <a href="http://www.coletiv.com/">Coletiv</a> we had the need to continuously keep the data synced between multiple mobile devices. The first solution that came to our minds to keep the state up to date was to poll the server each minute allied with push notifications.</p><p>Clearly this wasn’t the best solution in terms of performance and reliability. Since our Backend was made using <a href="http://phoenixframework.org/">Phoenix</a>, the initial naive solution naturally evolved to use <a href="https://hexdocs.pm/phoenix/channels.html">Phoenix Channels</a>.</p><p>In this article we will describe our experience implementing a proof of concept to test Phoenix Channels using the game <a href="https://www.youtube.com/watch?v=B6XpBDg1Oz4">Slime Soccer</a>. This is a simple game for two players where each one controls a slime and the objective is to score a goal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*4aMvKN5oFDrWGG_e9tFiRA.png" /><figcaption>Screenshot of the final version of our proof of concept</figcaption></figure><h3>Overview</h3><p>The proof of concept was implemented in Swift as a Mac app, but it could be easily implemented in any other language or platform of your choice.</p><p>The idea is to have two instances of the game running on different computers, each one will connect to a Phoenix server through Phoenix Channels. The server is responsible for managing the game score and handle the communications between the two players.</p><h3>Phoenix Channel Client</h3><p>There are a few Swift open source projects to help with the channel communications:</p><ul><li><a href="https://github.com/almassapargali/PhoenixWebSocket">PhoenixWebSocket</a></li><li><a href="https://github.com/sjrmanning/Birdsong">Birdsong</a></li><li><a href="https://github.com/davidstump/SwiftPhoenixClient">Swift Phoenix Client</a></li></ul><p>We decided to use Birdsong simply because we think that at the moment it was the project that best fits our needs. It has a clean and simple code style, performs a periodic ping to the server and allows some customisations like handling the disconnect actions.</p><h3>Implementation</h3><p>If you want to follow along you can find the server source code <a href="https://github.com/coletiv/slimesoccer-phoenix">here</a> and the client one <a href="https://github.com/coletiv/slimesoccer-ios/tree/master">here</a>.</p><p>The following diagram depicts the general communication flow between the Mac clients and the server during a game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*LsLz1uV56z55wjX7wLY03A.png" /><figcaption>Flow Diagram</figcaption></figure><h3>Establishing the connection</h3><h4>Server</h4><p>To define a new channel in Phoenix we simply add this line to <a href="https://github.com/coletiv/slimesoccer-phoenix/blob/master/lib/super_slime_game_web/channels/user_socket.ex">UserSocket.ex</a>:</p><pre>channel (“game: *”, SuperSlimeGameWeb.GameChannel)</pre><p>Our connect function is quite simple because we chose to ignore the authentication steps since it would imply additional development and that was not our goal with this test, but if you need authentication this would be a possible place to had your checks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a809e8b59f1ee9eb886d606ba0231be/href">https://medium.com/media/5a809e8b59f1ee9eb886d606ba0231be/href</a></iframe><h4>Client</h4><p>In the connect method we define both <em>onConnect</em> and <em>onDisconnect</em> handlers. These closures will be called after the socket is connected/disconnected. In our test we will join the channel immediately after the socket is connected. When the socket is disconnected a reconnect will be performed after a short delay.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb8b3485a51bf4decc62a3c413df0fb4/href">https://medium.com/media/eb8b3485a51bf4decc62a3c413df0fb4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c1ae3f37af2a831a6f446081d472682/href">https://medium.com/media/0c1ae3f37af2a831a6f446081d472682/href</a></iframe><h3>Joining a game</h3><h4>Server</h4><p>The main part of the application is the join function where players join a game. The channel nomenclature and the payload structure are defined as follows:</p><p>Channel nomenclature</p><pre>“game:” &lt;&gt; code</pre><p>Payload structure</p><pre>%{“email” =&gt; email} </pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69d46855263730ebdb5be6dc5f0fa6f2/href">https://medium.com/media/69d46855263730ebdb5be6dc5f0fa6f2/href</a></iframe><p>The game code <em>game:[a_code]</em> is used to check if the game already exists in the <em>GameState</em> agent process that was created to manage games. If the game already exists we will add the new player passed in the payload structure, otherwise a new game is created and a new player is added.</p><p>The <em>GameState</em> agent is used to save the games and match players, it is started alongside the server as a supervised child process.</p><p>To start the agent add the worker to the <a href="https://github.com/coletiv/slimesoccer-phoenix/blob/master/lib/super_slime_game/application.ex">Application.ex</a> like this:</p><pre>worker(SuperSlimeGame.GameState, [])</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9f8ba4565cb673badf5d11a12d87a36/href">https://medium.com/media/f9f8ba4565cb673badf5d11a12d87a36/href</a></iframe><h4>Client</h4><p>Within the join method we define the channel event listeners. These listeners will be executed if a specific action is returned from the channel (i.e. player moved). It is important to verify the state of the socket to ensure that the persistence of the connection is maintained.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9098c4dd6aa5793e9cc0f9276a312ac3/href">https://medium.com/media/9098c4dd6aa5793e9cc0f9276a312ac3/href</a></iframe><h3>Player Actions</h3><h4>Server</h4><p>When the <em>playerAction</em> command is received, the server will broadcast it to all players that joined the channel.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7810d420f1bdd7f1d340f15ef177864/href">https://medium.com/media/b7810d420f1bdd7f1d340f15ef177864/href</a></iframe><h4>Client</h4><p>Each time the scene is updated, a message is sent to the channel with the local player coordinates and actions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/068e81ce66db64e0907895455a5f1516/href">https://medium.com/media/068e81ce66db64e0907895455a5f1516/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3c4db50527c56a420b7de97654596ac/href">https://medium.com/media/d3c4db50527c56a420b7de97654596ac/href</a></iframe><h3>Concerns and Future work</h3><h4>Authentication method — join vs connect</h4><p>In this example we didn’t add any security within the channel connection, but this is a MUST have in a real world context.</p><p>In other projects developed by <a href="http://www.coletiv.com/">Coletiv</a>, we need to authenticate the user to allow it to access their resources. This is usually accomplished by using <a href="https://gist.github.com/nikneroz/ba698a120bc037801f45328855cbdca8">Guardian + ueberauth + JWT + Comeonin</a>. Our concern here is to either send the JWT token in the <em>connect</em> or <em>join</em> functions.</p><p>We’ve decided to use it within the <em>connect </em>function because without a valid token no one has access to the endpoint. Otherwise, if the token is passed in the <em>join</em> function, everyone will perform a successful connection, making the endpoint public.</p><h4>Improve game communication/synchronisation</h4><p>In this game both players have the responsibility to draw the player positions and simulate the game physics. Obviously this is not the best way to accomplish the movement synchronizations, perhaps a master-slave strategy could be a better solution.</p><h4>Ensure the use of HTTPS/WSS</h4><p>The server MUST accept incoming secure connections using WSS protocol. By default, most servers don’t accept this.</p><pre># Configures the endpoint<br>config :myapp, MyApp.Web.Endpoint,<br>url: [host: &quot;localhost&quot;],<br>check_origin: [&quot;//dev.example.com&quot;, &quot;//www.example.com&quot;],<br>secret_key_base: &quot;SECRET_KEY&quot;, <br>render_errors: [view: MyApp.ErrorView, accepts: ~w(json)], <br>pubsub: [name: MyApp.PubSub, adapter: Phoenix.PubSub.PG2]</pre><h4>Connection persistence</h4><p>On client side its very important to maintain the socket connection alive, which led to more code complexity. We’ve tried to achieve this by implementing the <em>reconnect()</em> function when the connection is lost, but this is not enough if we need to rejoin the channel and/or use authentication.</p><h3>Conclusion</h3><p>During this experience with Phoenix Channels we’ve noticed that the message exchange process is reliable and fast. This simple game, that was not optimized in terms of communication, has a satisfactory performance.</p><p>We think that Phoenix Channels serve our purpose of maintaining the state synchronized between multiple clients.</p><p>We are implementing a similar solution in one of our current projects and we hope to write soon about our real world experience with Phoenix Channels.</p><h3>Sample Code</h3><p>You can find the server source code <a href="https://github.com/coletiv/slimesoccer-phoenix">here</a> and client one <a href="https://github.com/coletiv/slimesoccer-ios/tree/master">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abd393c4c6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>