building the mobile app for couchbase connect: couchbase connect 2014

Download Building the Mobile App for Couchbase Connect: Couchbase Connect 2014

If you can't read please download the document

Upload: couchbase

Post on 26-Jun-2015

445 views

Category:

Career


10 download

DESCRIPTION

Speakers: Ben Hendersen, Bryan Hunter, Firefly Mobile What is involved in building a production, cross-platform mobile app using Couchbase-Lite? Firefly Logic is custom software firm with expertise in Xamarin (for mobile) and Erlang (for back-end work). This session will be a "travel log" of our experience learning Couchbase-Lite and building the conference mobile app for Couchbase Connect 2014. Our firm had built white-label conference apps in the past, but this project was very different. Learn what was most interesting, what we learned, and how we plan to leverage Couchbase going forward.

TRANSCRIPT

  • 1. presented byBryan Hunter &Ben HendersonFirefly LogicNashville, TNTwitter@bryan_hunter@ben_henderson@fireflylogic#CBConnectBuilding theMobile Appfor CouchbaseConnect

2. Some Background 3. Ooo Oooo! Great idea. 4. lets write a conference app! 5. Sample App versus Conference App 6. Loved! Loved! Loved!the conference app! 7. Tour of the App 8. Homeschedulesessionapp-config 9. Menucontact(mine) 10. Menucontact(mine) 11. My Agendaschedulesessionagenda 12. Full Scheduleschedulesessionagenda 13. Filter 14. Full Scheduleschedulesessionagenda 15. Choose aSessionsessionspeakeragenda 16. Rate Sessionsession-rating 17. ConferenceSurveyconference-survey 18. Contactscontactcontact-exchange 19. Contactcontact 20. Scavenger Huntscavenger-hunt-itemscavenger-hunt-capture 21. Scavenger Huntscavenger-hunt-itemscavenger-hunt-capture 22. Profilecontact(mine) 23. The Documents(our aggregate roots)read from couchschedulesessionspeakerscavenger-hunt-itemapp-configcontact (not me)write to couchagendascavenger-hunt-capturesession-ratingsurvey-resultcontact (my profile)contact-exchangelocal-onlymy-local-config 24. Sync Gateway 25. Sync GatewayChannels UsersDocumentsSyncFunction 26. So, how arepublic documentsimplemented? Must flow down to everyone Must have restricted edit permissions 27. Sample Sync Gateway User{"name": "bab6dde3-cbc4-4c5a-9bfb-f92222f369d5","admin_channels": {"public": 26},"all_channels": {"contact-bab6dde3-cbc4-4c5a-9bfb-f92222f369d5": 27,"contact-f755ca37-c2db-48d8-9416-c57d8b26398d": 30,"public": 26},"sequence": 26,"passwordhash_bcrypt": JDlJOW9sdE5NRk96eE ...","rolesSince": {}} 28. Sync Function - Assign Channelsif (doc.type == "session" ||doc.type == "speaker" ||doc.type == "schedule" ||doc.type == "appconfig" ||doc.type == "scavengerhuntitem" ) {// everyone can sync these documentschannel("public")} 29. Session Document{"_sync": {"rev": "1-1E7EA0C2F535A6883E3A251744352CBD","sequence": 86,"history": { "revs": ["1-1E7EA0C2F535A6883E3A251744352CBD"],"parents": [ -1], "bodies": [ "" ],"channels": [["public"]]},"channels": {"public": null},"time_saved": "2014-10-07T05:00:19.867836992-05:00"},"session": { "Abstract": "What is involved in ...", "Id": "session-1011","Location": "TBA","SpeakerIds": ["speaker-bryan-hunter" ],"Time":"2014-10-06T15:20:00","Title": "Building the Mobile App for CouchbaseConnect", "Track": "Mobile" },"type": "session} 30. Sync Function - Validationif (doc.type == "contact") {// Users can't assign their contact doc to another user.if (oldDoc != null && oldDoc.userId != doc.userId)throw({forbidden: "Can't change userId."});// Users can only change their own contact.requireUser(oldDoc == null ? doc.userId : oldDoc.userId);// snipped other doc type validation} else {// The 'admin' user can change any document.requireUser("admin");} 31. Inside the App 32. Startup Sequence Create Sync Gateway user (if needed) Install baseline data (if needed) Start replicators 33. Baseline Data Good first launch experience Provide early version of schedule, sessions,and speakers Old data is overwritten by first sync 34. Install Baseline Dataprivate void CreateDatabase (){_db = Manager.SharedInstance.GetExistingDatabase (DB_NAME);if (_db == null) {var assembly = Assembly.GetCallingAssembly ();var resourceName = assembly.GetManifestResourceNames ().Where (x => x.EndsWith ("couchbase-connect.cblite",StringComparison.CurrentCultureIgnoreCase)).Single ();var stream = assembly.GetManifestResourceStream (resourceName);Manager.SharedInstance.ReplaceDatabase (DB_NAME, stream, null);_db = Manager.SharedInstance.GetExistingDatabase (DB_NAME);}} 35. Initialize Replicationprivate void SetupReplication(Uri server){var pull = _db.CreatePullReplication (server);var push = _db.CreatePushReplication (server);pull.Continuous = true;push.Continuous = true;var userId = GetUserId ();pull.Authenticator = AuthenticatorFactory.CreateBasicAuthenticator (userId, userId);push.Authenticator = AuthenticatorFactory.CreateBasicAuthenticator (userId, userId);pull.Start();push.Start();} 36. Live Demo 37. Scan me, ok? 38. Len PrieskornDirector of Business DevelopmentFirefly Logic, Inc. 39. What happened there?Channel magic in the sync function! 40. Create Profileif (doc.type == "contact") {var contactChannelName = "contact-" + doc.userId;// give user access to it's contact channelaccess(doc.userId, contactChannelName);// add doc to user's contact channelchannel(contactChannelName);} 41. Contact Exchange Document{"_id": "contactexchange-e324e942-6c85-45ee-963d-7806266fbe61","_rev": "1-be88a43c4f0039248db58f610204bc65","first": "Zack","last": "Gramana","localUserId": "f5531d13-6f42-497f-b4cd-69d66c39696c","type": "contactexchange","userId": "5cd2c2a0-4d93-46d4-b4c4-8ea7000c5199"} 42. Create Contact Exchangeif (doc.type == "contactexchange") {// give remote user access to local users// contact channelaccess(doc.userId, "contact-" + doc.localUserId);// give local user access to remote users// contact channelaccess(doc.localUserId, "contact-" + doc.userId);} 43. Whats the offline experience? Im glad you asked! 44. the Contact Proxy 45. The all-contacts view + live query Excludes the users contact Emits contact and contact exchange info,potentially 1 or 2 rows Reduce function returns 1 row of data Live Query retrieves an existing Contact ormakes a Contact Proxy from a ContactExchange 46. Team & Timeline 47. Timeline12345650% 20% 20% 100% - - -20% 100% 100% - - 20%80% 50% 50% 100% 100% 100% 80%100% 50% - 100% 100% 100% 100%60% 20% - 40% 40% 100% 60%100% - - - - 100% 100%week50% 48. 85% 10% 5% 49. Lessons & Surprises 50. Only a handful of concepts to master 51. No backend server code 52. REST vs Sync 53. REST versus SyncImperative versus DeclarativeOnline only Prefer online Prefer offline Offline onlyNetwork available? Yes No Yes No Yes No Yes NoData is local and remote Good X Good OK Good Good Good GoodData is local only X X OK OK Good Good Good GoodData is remote only Good X Good X OK X X XData is nowhere X X X X X X X X 54. Keys with Tags 55. Examples of our Keys schedule app-config session-1031 speaker-bryan-hunter scavenger-hunt-item-009 contact-{users guid} agenda-{users guid} scavenger-hunt-capture-009-{users guid} contactexchange-{guid} session-rating-session-1031-{users guid} 56. Design for Conflict Free 57. Take-aways 58. we need to try Couchbase Mobile!!(you really should. Its pretty amazing.)