SlideShare uma empresa Scribd logo
1 de 49
Baixar para ler offline
Sencha Touch 2 and Sencha.io
how to use cloud services in your app


Nils Dehl, Senior Developer (@nilsdehl)
Nils Dehl


 Senior Developer
 Trainer
 Meetup Frankfurt
 Conference Talks
 Sencha Forum: mrsunshine
 Conference Photographer
flickr.co
         m/photo
                s/nils-de
                            hl
dkd Internet Service GmbH


 owner-managed full-service internet agency
 Frankfurt Germany
 development, communication & design
 specialized in TYPO3
   Ruby on Rails
   Sencha Touch / ExtJS
 42 employees
 + 350 projects
Customer-Portfolio
Sencha Touch 2
Sencha.io
Sencha.io
Services
Login
Data
Messaging
Deployment
Src
Login


 Sencha.io
 Sencha Forum
 Facebook
 Twitter
Data


 sync local data in the cloud
 access from multi devices
 offline handling
Messaging


 send messages
 receive messages
 one to one
 one to many
Deployment


 version management
 management tools
 usergroup management
 app delivery through the Sencha app repository
 myapp.senchafy.com
Src


 src.sencha.io
 resize images
   altering sizes
   percentage sizing
 data URLs
 domain sharding
Demo App
How to use Sencha.io
Sencha.io
settings
How to implement the
Sencha.io in your app

x
Setup
Load Sencha.io in app.js

  Ext.Loader.setPath({
  'Ext': 'sdk/src',
  ...
  'Ext.io': 'libs/sencha-io-0.1.0/src/io',
  'Ext.cf': 'libs/sencha-io-0.1.0/src/cf',
    ...
});
Ext.application({
    requires: [
       'Ext.io.Io',
       'Ext.io.data.Proxy',
    ],
Init / Setup

ioSetup: function() {
     // Calling this method is optional. It assumes the defaults if not called.
     Ext.io.Io.setup({
          // app id string configured on http://developer.sencha.io/apps
          appId: this.getIoAppId(),
          // the server URL. Defaults to http://msg.sencha.io
          url: 'http://msg.sencha.io',
          // logging level. Should be one of "none", "debug",
           // "info", "warn" or "error". Defaults to "error".
          logLevel: 'error',
          // the transport type to use for communicating with the server.
           // Should be one of "polling" (HTTP polling) or "socket"
           // (SocketIO). Defaults to "polling".
          transportName: 'socket'
     });
},
ioInit: function() {
     Ext.io.Io.init();
},
Login
Get app .io usergroup

/**
 * get the app usergroup object from the server
 */
ioGetGroup: function() {
     Ext.io.Io.getGroup({
          id: this.getIoGroupId(),
          success: this.ioSetGroup,
          failure: function() {
               console.log("PHODO IO get group failure");
          },
          scope: this
     });
},
/**
 * set the io group object reference in auth module
 */
ioSetGroup: function(group, options) {
     this.setIoGroup(group);
},
Login / Authenticate

doLogin: function() {
    var formValues = this.getLoginView().getValues();

     // the io usergroup object contains the authenticate method
     this.getIoGroup().authenticate({
          params: {
               username: formValues.username ? formValues.username : '',
               password: formValues.password ? formValues.password : ''
          },
          callback: function(opts, isAuth, user) {
               if (isAuth) {
                     this.setIoUser(user);
                     this.loginSuccess();
               } else {
                     this.loginFailure('Login Failure');
               }
          },
          scope: this
     });
},
Share data between
user devices
Use proxy type syncstorage in the
model
Ext.define('Photos.model.Photo', {
     extend: 'Ext.data.Model',
     config: {
         fields: [
               {
                   name: 'title'
               },
               ...
         ],

          proxy: {
              type: 'syncstorage',
              id: 'photos'
          }
      }
});
Add to store and sync

addPhoto: function(button) {
    var form = button.up('formpanel'),
         values = form.getValues(),
         store = Ext.getStore('photos');
    store.add(values);
    store.sync();
    // send message to all devices of the user to sync stores there as well
    Ext.io.Io.getCurrentUser({
         callback: function(cb, isAuth, user) {
            if (isAuth) {
                    user.send({
                          message: {
                               event: 'photo-added'
                          },
                          callback: function() {}
                    });
                }
         }
    });
},
Listen on user messages

addUserMessageReceiver: function() {
   Ext.io.Io.getCurrentUser({
        callback: function(cb, isAuth, user) {
             if (!isAuth) {
                    console.log("no user, we need to auth.", user);
                    this.redirectTo('login');

               } else {
                     // Listen on user messages
                    user.receive({
                           callback: this.onUserReceivedMessage,
                           scope: this
                    });
               }
           },
           scope: this
     });
},
Listen on user messages

onUserReceivedMessage: function(cb, bool, sender, message) {
   var store = null,
        view = this.getDataView();

    if (message.event === 'photo-added') {
         store = Ext.getStore('photos') ;
         store.load();
         store.sort();
         store.sync();
    }
}
Share between users
of usergroup
publish to message queue

shareInTheCloud: function(data, user) {
     Ext.io.Io.getQueue({
          params: {
               name: 'share'
          },
          callback: function(options, success, queue) {
               queue.publish({
                    message: {
                         event: 'share',
                         content: data,
                         fromMailHash: Ext.cf.util.Md5.hash(user.data.email)
                    },
                    callback: function() {},
                    scope: this
               });
          }
    });
},
Subscribe to message queue

onLoginStatusChanged: function(status) {
    if (status) {
          Ext.io.Io.getQueue({
               params: {
                    name: 'share'
               },
               callback: function(options, success, queue) {
                    queue.subscribe({
                         callback: this.onUserReceivedMessage,
                         scope: this
                    });
               },
               scope: this
          });
    }
},
handle received data

onUserReceivedMessage: function(cb, bool, sender, message) {
   var store = Ext.getStore('shareditems'),
       record = {
             from: message.fromMailHash,
             imageurl: message.content.url,
             date: Ext.Date.format(new Date(), 'U')
        };
        store.add(record);
        store.sort();
        store.sync();
},
Manipulate images
with Src
Sencha.io Src

Ext.define('Photos.view.Photo', {
    extend: 'Ext.Container',
    xtype: 'photodetail',
    config: {
        cls: 'bg photodetail',
        scrollable: true,
        styleHtmlContent: true,

          tpl: '<div class="image">' +
                 '<img src="http://src.sencha.io/280/{url}" />' +
               '</div>'
      }
});
dkd
     development
     kommunikation
     design




thank you.
???
@nilsdehl


flickr.com/photos/nils-dehl/

Mais conteúdo relacionado

Mais procurados

First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
techbed
 

Mais procurados (20)

RIA - Entwicklung mit Ext JS
RIA - Entwicklung mit Ext JSRIA - Entwicklung mit Ext JS
RIA - Entwicklung mit Ext JS
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 light
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84
 
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
iBATIS
iBATISiBATIS
iBATIS
 
Clojure: Functional Concurrency for the JVM (presented at OSCON)
Clojure: Functional Concurrency for the JVM (presented at OSCON)Clojure: Functional Concurrency for the JVM (presented at OSCON)
Clojure: Functional Concurrency for the JVM (presented at OSCON)
 
앱스프레소를 이용한 모바일 앱 개발(2)
앱스프레소를 이용한 모바일 앱 개발(2)앱스프레소를 이용한 모바일 앱 개발(2)
앱스프레소를 이용한 모바일 앱 개발(2)
 
Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testing
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
 
The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 
Banquet 52
Banquet 52Banquet 52
Banquet 52
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Pengenalan blaast platform sdk
Pengenalan blaast platform sdkPengenalan blaast platform sdk
Pengenalan blaast platform sdk
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
 

Destaque

Eight Steps to an Effective Vulnerability Assessment
Eight Steps to an Effective Vulnerability AssessmentEight Steps to an Effective Vulnerability Assessment
Eight Steps to an Effective Vulnerability Assessment
Sirius
 

Destaque (7)

Sencha Touch meets TYPO3 CMS
Sencha Touch meets TYPO3 CMSSencha Touch meets TYPO3 CMS
Sencha Touch meets TYPO3 CMS
 
HTML5 Touch Interfaces: SXSW extended version.
HTML5 Touch Interfaces: SXSW extended version.HTML5 Touch Interfaces: SXSW extended version.
HTML5 Touch Interfaces: SXSW extended version.
 
Beautiful Documentation with YUI Doc
Beautiful Documentation with YUI DocBeautiful Documentation with YUI Doc
Beautiful Documentation with YUI Doc
 
Dgeni documentation generator
Dgeni   documentation generatorDgeni   documentation generator
Dgeni documentation generator
 
Eight Steps to an Effective Vulnerability Assessment
Eight Steps to an Effective Vulnerability AssessmentEight Steps to an Effective Vulnerability Assessment
Eight Steps to an Effective Vulnerability Assessment
 
Best Practices: Project Documentation and Construction Management
Best Practices: Project Documentation and Construction ManagementBest Practices: Project Documentation and Construction Management
Best Practices: Project Documentation and Construction Management
 
Good Documentation Practice
Good Documentation PracticeGood Documentation Practice
Good Documentation Practice
 

Semelhante a SenchaTouch 2 and Sencha.io

JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
philogb
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
philogb
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
Eldar Djafarov
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
OSCON Byrum
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript
Qiangning Hong
 

Semelhante a SenchaTouch 2 and Sencha.io (20)

Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
Aprimorando sua Aplicação com Ext JS 4 - BrazilJSAprimorando sua Aplicação com Ext JS 4 - BrazilJS
Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
 
NodeJS and ExpressJS.pdf
NodeJS and ExpressJS.pdfNodeJS and ExpressJS.pdf
NodeJS and ExpressJS.pdf
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Extjsslides 091216224157-phpapp02
Extjsslides 091216224157-phpapp02Extjsslides 091216224157-phpapp02
Extjsslides 091216224157-phpapp02
 
ExtJS framework
ExtJS frameworkExtJS framework
ExtJS framework
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Express JS
Express JSExpress JS
Express JS
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdf
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
 
Dpilot - Source Code with Snapshots
Dpilot - Source Code with SnapshotsDpilot - Source Code with Snapshots
Dpilot - Source Code with Snapshots
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript
 
Sencha Touch - Introduction
Sencha Touch - IntroductionSencha Touch - Introduction
Sencha Touch - Introduction
 
Testando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependênciasTestando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependências
 

Mais de Nils Dehl

Mais de Nils Dehl (6)

Dynamic package loading 
and routing with Ext JS
Dynamic package loading 
and routing with Ext JSDynamic package loading 
and routing with Ext JS
Dynamic package loading 
and routing with Ext JS
 
jsday.it - develop and test custom components for sencha touch by nils dehl
jsday.it - develop and test custom components for sencha touch by nils dehljsday.it - develop and test custom components for sencha touch by nils dehl
jsday.it - develop and test custom components for sencha touch by nils dehl
 
Sencha Touch meets TYPO3
Sencha Touch meets TYPO3Sencha Touch meets TYPO3
Sencha Touch meets TYPO3
 
Workshop getting started with sencha touch 2 - nils dehl
Workshop   getting started with sencha touch 2 - nils dehlWorkshop   getting started with sencha touch 2 - nils dehl
Workshop getting started with sencha touch 2 - nils dehl
 
SenchaCon 2011 VGF Showcase
SenchaCon 2011 VGF ShowcaseSenchaCon 2011 VGF Showcase
SenchaCon 2011 VGF Showcase
 
Development of the TYPO3 Phoenix User Interface with Ext JS
Development of the TYPO3 Phoenix User Interface with Ext JSDevelopment of the TYPO3 Phoenix User Interface with Ext JS
Development of the TYPO3 Phoenix User Interface with Ext JS
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

SenchaTouch 2 and Sencha.io

  • 1. Sencha Touch 2 and Sencha.io how to use cloud services in your app Nils Dehl, Senior Developer (@nilsdehl)
  • 2. Nils Dehl Senior Developer Trainer Meetup Frankfurt Conference Talks Sencha Forum: mrsunshine Conference Photographer
  • 3. flickr.co m/photo s/nils-de hl
  • 4. dkd Internet Service GmbH owner-managed full-service internet agency Frankfurt Germany development, communication & design specialized in TYPO3 Ruby on Rails Sencha Touch / ExtJS 42 employees + 350 projects
  • 7.
  • 8.
  • 9.
  • 10.
  • 13. Login Sencha.io Sencha Forum Facebook Twitter
  • 14. Data sync local data in the cloud access from multi devices offline handling
  • 15. Messaging send messages receive messages one to one one to many
  • 16. Deployment version management management tools usergroup management app delivery through the Sencha app repository myapp.senchafy.com
  • 17. Src src.sencha.io resize images altering sizes percentage sizing data URLs domain sharding
  • 19.
  • 20. How to use Sencha.io
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. How to implement the Sencha.io in your app x
  • 27. Setup
  • 28. Load Sencha.io in app.js Ext.Loader.setPath({ 'Ext': 'sdk/src', ... 'Ext.io': 'libs/sencha-io-0.1.0/src/io', 'Ext.cf': 'libs/sencha-io-0.1.0/src/cf', ... }); Ext.application({ requires: [ 'Ext.io.Io', 'Ext.io.data.Proxy', ],
  • 29. Init / Setup ioSetup: function() { // Calling this method is optional. It assumes the defaults if not called. Ext.io.Io.setup({ // app id string configured on http://developer.sencha.io/apps appId: this.getIoAppId(), // the server URL. Defaults to http://msg.sencha.io url: 'http://msg.sencha.io', // logging level. Should be one of "none", "debug", // "info", "warn" or "error". Defaults to "error". logLevel: 'error', // the transport type to use for communicating with the server. // Should be one of "polling" (HTTP polling) or "socket" // (SocketIO). Defaults to "polling". transportName: 'socket' }); }, ioInit: function() { Ext.io.Io.init(); },
  • 30. Login
  • 31. Get app .io usergroup /** * get the app usergroup object from the server */ ioGetGroup: function() { Ext.io.Io.getGroup({ id: this.getIoGroupId(), success: this.ioSetGroup, failure: function() { console.log("PHODO IO get group failure"); }, scope: this }); }, /** * set the io group object reference in auth module */ ioSetGroup: function(group, options) { this.setIoGroup(group); },
  • 32.
  • 33. Login / Authenticate doLogin: function() { var formValues = this.getLoginView().getValues(); // the io usergroup object contains the authenticate method this.getIoGroup().authenticate({ params: { username: formValues.username ? formValues.username : '', password: formValues.password ? formValues.password : '' }, callback: function(opts, isAuth, user) { if (isAuth) { this.setIoUser(user); this.loginSuccess(); } else { this.loginFailure('Login Failure'); } }, scope: this }); },
  • 35.
  • 36. Use proxy type syncstorage in the model Ext.define('Photos.model.Photo', { extend: 'Ext.data.Model', config: { fields: [ { name: 'title' }, ... ], proxy: { type: 'syncstorage', id: 'photos' } } });
  • 37. Add to store and sync addPhoto: function(button) { var form = button.up('formpanel'), values = form.getValues(), store = Ext.getStore('photos'); store.add(values); store.sync(); // send message to all devices of the user to sync stores there as well Ext.io.Io.getCurrentUser({ callback: function(cb, isAuth, user) { if (isAuth) { user.send({ message: { event: 'photo-added' }, callback: function() {} }); } } }); },
  • 38. Listen on user messages addUserMessageReceiver: function() { Ext.io.Io.getCurrentUser({ callback: function(cb, isAuth, user) { if (!isAuth) { console.log("no user, we need to auth.", user); this.redirectTo('login'); } else { // Listen on user messages user.receive({ callback: this.onUserReceivedMessage, scope: this }); } }, scope: this }); },
  • 39. Listen on user messages onUserReceivedMessage: function(cb, bool, sender, message) { var store = null, view = this.getDataView(); if (message.event === 'photo-added') { store = Ext.getStore('photos') ; store.load(); store.sort(); store.sync(); } }
  • 41.
  • 42. publish to message queue shareInTheCloud: function(data, user) { Ext.io.Io.getQueue({ params: { name: 'share' }, callback: function(options, success, queue) { queue.publish({ message: { event: 'share', content: data, fromMailHash: Ext.cf.util.Md5.hash(user.data.email) }, callback: function() {}, scope: this }); } }); },
  • 43. Subscribe to message queue onLoginStatusChanged: function(status) { if (status) { Ext.io.Io.getQueue({ params: { name: 'share' }, callback: function(options, success, queue) { queue.subscribe({ callback: this.onUserReceivedMessage, scope: this }); }, scope: this }); } },
  • 44. handle received data onUserReceivedMessage: function(cb, bool, sender, message) { var store = Ext.getStore('shareditems'), record = { from: message.fromMailHash, imageurl: message.content.url, date: Ext.Date.format(new Date(), 'U') }; store.add(record); store.sort(); store.sync(); },
  • 46. Sencha.io Src Ext.define('Photos.view.Photo', { extend: 'Ext.Container', xtype: 'photodetail', config: { cls: 'bg photodetail', scrollable: true, styleHtmlContent: true, tpl: '<div class="image">' + '<img src="http://src.sencha.io/280/{url}" />' + '</div>' } });
  • 47. dkd development kommunikation design thank you.
  • 48. ???