This talk will cover how you can use Sencha's sencha.io cloud services in your Sencha Touch 2 mobile web app.
Sencha provides several service to create, store and share data in the cloud.
In this talk we go through the following services:
* Sencha.io Login: provides a set of APIs for user registration and login.
* Sencha.io Data: synchronizes data with the cloud.
* Sencha.io Messaging: enables reliable one-to-one and one-to-many messaging.
* Sencha.io Src: dynamically resize images for the ever increasing number of mobile screen sizes
and will see how to use and implement the services in detail.
The implementation will be explained by the code of an Sencha Touch 2 app using the sencha.io services.
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
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();
},
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);
},
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();
}
}