02 Mar 2014
This is not an intro post about Firebase so I hope that you are familiar with Firebase operations and how Firebase generally works.
Our problem domain
Our problem at hand was to send a file from one user to another user. More clearly stating - send data from user 1 to user 2 without having a custom backend server.
Proposed solution is to build a handshake mechanism on Firebase without using a custom backend. Below is the architecture diagram of the solution.
Flow of requests
Request A :- The client 1 will add a request to Firebase stating that a file is there to be shared to client 2. In Firebase how this is represented is by having a notification collection per user.
An interesting point to note on Firebase is that we don’t have arrays- Arrays are reflected with id’s.
The key point here is that Client 1 is writing this to Client 2’s notification list. Client 1 has write permission to Client 2 ’s notification collection but doesn’t have read permission. Client 1 setup the values of
false by default and
Request B :- Client 2 is listening to his notification collection on childadded and childchanged events. Child Added will be fired since Client 1 has added a notification to Client B’s collection.
Request C :- Client 2 will write a notification to Client 1’s notification collection with the same notification changing the
recipient_notification with notification id of the initial notification.
Request D :- Client 1 is also listening to childadded and childchanged events on his notification collection. A child_added event will be triggered and client A will upload the file to files collection of client 1.
Request E :- Client 1 will select client 2’s notification by using
recipient_notification and change the
true as well.
There is a possible security hole here.
Request F :- Since client 2 is listening to his collection his childchanged event get fired when client 1 changes the `fileready
totrue`. Client 2 will then download the file from client 1’s file collection.
Firebase proves to be a valuable service to perform realtime operations and file transfer using handshake protocol is successful due to this. My next adventure would be to use WebRTC to power up the handshake.
Till next time mate,
Dulitha at 14:06