building decentralised realtime collaborative applications - building google docs without google

45
Mozfest Decentralised David Dias & Pedro Teixeira Using IPFS, Y.js a Browser and some JavaScript Decentralised collaborative documents a.k.a. Building Google Docs without the “Google”

Upload: pedro-teixeira

Post on 22-Jan-2018

1.679 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

David Dias & Pedro Teixeira

Using IPFS, Y.js a Browser and some JavaScript

Decentralised collaborative documents

a.k.a. Building Google Docs without the “Google”

Page 2: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

WarningThis is going to envolve some coding.

Probably pairing up!

Page 3: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Agenda• Grouping• Motivation for Decentralising Web Apps• Goal• Setup• Code! (30 mins)• Discussion: Decentralised Web Apps• Quick Announcement

Page 4: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

MotivationCloud-based software has taken the web a long way,

but lead us into centralisation.

Page 5: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

DNS

a.com 30.30.30.30

b.com 40.40.40.40

c.com 50.50.50.50

Page 6: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

cvs/svn

Page 7: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

cvs/svn

Page 8: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

cvs/svn

Page 9: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google
Page 10: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google
Page 11: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google
Page 12: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google
Page 13: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google
Page 14: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

GoalCreate a

decentralised collaborative web-based real-timeFlipchart application

Page 15: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Materials• Modern Browser• JavaScript• IPFS (js-ipfs)• CRDT• Code Editor• Command line

Page 16: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Setup:Install Node.js

Page 17: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Setup:Download code

• Through git:

• or download zip file from

http://bit.ly/2xsCJfP

Page 18: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Setup:Install dependencies

Page 19: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Setup:Build and watch

Page 20: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Setup:Start HTTP server

Page 21: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Setup:Test flipchart app

Page 22: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Page 23: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

The source code

Open a code editor and take a peek atsrc/index.js

Page 24: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Add 1 IPFS

Let’s create an IPFS node inside the browser app.

Page 25: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Wait for IPFS to start

…by handling the IPFS“start” event.

Page 26: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Print IPFS status

and IPFS Peer ID

Page 27: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

• Content-addressable storage• DAG formed by cryptographically secure links

• Pub-sub network• Naming (IPNS)• Multi-transport• Multi-discovery• Multi-*• Community-driven open-source• Go, JS and more!• Future-proof

Page 28: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Offline-first, real-time, shared editing for data structures

Page 29: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Page 30: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Add 1 CRDT

Let’s replace direct manipulation of the line array with an array of lines.

Each line is (still) an array of points.

Page 31: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Y.jsstep 1

Import Y.js dependencies

Page 32: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Y.jsstep 2

Initialise Y.js

Page 33: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Y.jsstep 3

Routine to draw a linefrom a Y.js array

Page 34: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Y.jsstep 4

Listen for changes indrawing and act.

Page 35: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Y.jsstep 5

Draw pre-existing lines

Page 36: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Y.jsstep 6

Create new line on drag

Page 37: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Y.jsstep 7

When user drags,add points to current line

Page 38: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Y.jsstep 8

When user clears,remove all lines from CRDT

Page 39: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Page 40: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Under thehood

Page 41: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

HomeworkChallenge

• Allow user to take a snapshot• Save the snapshot to IPFS

Page 42: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

CRDTs

CRDTs will be the building block of decentralised collaborative applications.

This type of data structures allows building conflict-free offline-first reliable decentralised apps.

Page 43: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

Discussion

CRDTs allow you to build a decentralised collaborative store.

What other building blocks will be necessary to build DApps?

• Identity• Authentication• Access Control• Privacy• Files• non-local Key/Object

store• Messaging• … ?

Page 44: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised

PeerPad

PeerPad is a real-time collaborative editing tool, powered by IPFS and CRDTs.

https://peerpad.net

Page 45: Building Decentralised Realtime Collaborative Applications - Building Google Docs without Google

MozfestDecentralised