SlideShare una empresa de Scribd logo
1 de 132
Descargar para leer sin conexión
Using SockJS(Websocket) with Sencha Ext JS
Sencha Ext JS上のWebSocket実装の形
小堤 一弘

株式会社ゼノフィ
Xenophy.CO.,LTD
本日のアジェンダ
自己紹介
SockJSをSencha Ext JSで使うための準備
メッセージ交換と、マウス位置共有の設計
デモ
まとめ
自己紹介

こつつみ   かずひろ

小堤 一弘
株式会社ゼノフィ 代表取締役
Sencha 公式トレーニング認定トレーナー
Japan Sencha User Group 主宰
html5jエンタープライズ部
!
Twitter
@kotsutsumi
!
Facebook
https://www.facebook.com/kotsutsumi

Books
Ext JS Data-Driven Application Design
Sencha Ext JS 4 実践開発ガイド
Sencha Ext JS 4 実践開発ガイド 2
Sencha Touch 2 実践開発ガイド (監修)
SockJSをSencha Ext JSで使うための準備

まず、普通にSockJSでWebSocket通信を
するための準備をする。
Vert.x + SockJS Serverの環境構築について
昨日、 html5jエンタープライズ部
で、紹介させてもらった、
SPA のための Web サーバ構築ノウハウ
を参照してください。
http://www.slideshare.net/kotsutsumi/spa-web
SockJS Serverの作成

// Vert.x読み込み
var vertx = require('vertx');
!

// HTTPサーバー生成
var server = vertx.createHttpServer();
!

// SockJSサーバー生成
var sockJSServer = vertx.createSockJSServer(server);
SockJS Serverの作成

// Vert.x読み込み
var vertx = require('vertx');
!

// HTTPサーバー生成
var server = vertx.createHttpServer();
!

// SockJSサーバー生成
var sockJSServer = vertx.createSockJSServer(server);
SockJS Serverの作成

// Vert.x読み込み
var vertx = require('vertx');
!

// HTTPサーバー生成
var server = vertx.createHttpServer();
!

// SockJSサーバー生成
var sockJSServer = vertx.createSockJSServer(server);
SockJS Serverの作成

// Vert.x読み込み
var vertx = require('vertx');
!

// HTTPサーバー生成
var server = vertx.createHttpServer();
!

// SockJSサーバー生成
var sockJSServer = vertx.createSockJSServer(server);
SockJS Serverの作成
// ブリッジ設定
sockJSServer.bridge(
!

// コンフィグ
{prefix : ‘/eventbus’},

);

// セキュリティ設定
[{address : ‘demo.orderMgr'}],
[{address : ‘demo.orderMgr'}]
SockJS Serverの作成
// ブリッジ設定
sockJSServer.bridge(
!

// コンフィグ
{prefix : ‘/eventbus’},

);

// セキュリティ設定
[{address : ‘demo.orderMgr'}],
[{address : ‘demo.orderMgr'}]
SockJS Serverの作成
// ブリッジ設定
sockJSServer.bridge(
!

// コンフィグ
{prefix : ‘/eventbus’},

);

// セキュリティ設定
[{address : ‘demo.orderMgr'}],
[{address : ‘demo.orderMgr'}]
SockJS Serverの作成
// ブリッジ設定
sockJSServer.bridge(
!

// コンフィグ
{prefix : ‘/eventbus’},

);

// セキュリティ設定
[{address : ‘demo.orderMgr'}],
[{address : ‘demo.orderMgr'}]
SockJS Serverの作成
// ブリッジ設定
sockJSServer.bridge(
!

// コンフィグ
{prefix : ‘/eventbus’},
// セキュリティ設定
[{address : ‘demo.orderMgr'}],
[{address : ‘demo.orderMgr'}]

);

ブリッジはデフォルトのすべてを拒否するポリシーを
持つファイアウォールの一種のように動作します。
SockJS Serverの作成
// リスン
server.listen(8081);
SockJS Serverの起動

vertx run extjs-sockjs.js
クラスター起動する場合は、後ろに-clusterをつける
無事、起動!!
SockJS ClientのHTML作成
<html>
<head>
<script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js"></script>
<script src="vertxbus-2.1.js"></script>
<script src="sockjs-app.js"></script>
</head>
<body>
<h1>SockJS Client without Sencha Ext JS</h1>
<button onclick="ebSend();">Send Message</button>
</body>
</html>
SockJS ClientのHTML作成
<html>
<head>
<script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js"></script>
<script src="vertxbus-2.1.js"></script>
<script src="sockjs-app.js"></script>
</head>
<body>
<h1>SockJS Client without Sencha Ext JS</h1>
<button onclick="ebSend();">Send Message</button>
</body>
</html>
SockJS ClientのHTML作成
<html>
<head>
<script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js"></script>
<script src="vertxbus-2.1.js"></script>
<script src="sockjs-app.js"></script>
</head>
<body>
<h1>SockJS Client without Sencha Ext JS</h1>
<button onclick="ebSend();">Send Message</button>
</body>
</html>
SockJS ClientのHTML作成
<html>
<head>
<script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js"></script>
<script src="vertxbus-2.1.js"></script>
<script src="sockjs-app.js"></script>
</head>
<body>
<h1>SockJS Client without Sencha Ext JS</h1>
<button onclick="ebSend();">Send Message</button>
</body>
</html>
SockJS ClientのHTML作成
<html>
<head>
<script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js"></script>
<script src="vertxbus-2.1.js"></script>
<script src="sockjs-app.js"></script>
</head>
<body>
<h1>SockJS Client without Sencha Ext JS</h1>
<button onclick="ebSend();">Send Message</button>
</body>
</html>
SockJSクライアントに必要なリソース

sockjs-0.3.4.min.js
http://cdn.sockjs.org/sockjs-0.3.4.min.js

vertxbus-2.1.js
vert.x-2.1M2.tar.gzを解凍したディレクトリに格納されている
ので、HTMLからアクセスできるところに配置する。
vert.x-2.1M2/client/vertxbus-2.1.js
SockJSアプリケーション作成 - sockjs-app.js
// イベントバス生成
var eb = new vertx.EventBus(
'http://[Vert.xサーバーIP]:8081/eventbus'
);
SockJSアプリケーション作成 - sockjs-app.js
// イベントバス生成
var eb = new vertx.EventBus(
'http://[Vert.xサーバーIP]:8081/eventbus'
);
SockJSアプリケーション作成 - sockjs-app.js
// イベントバス生成
var eb = new vertx.EventBus(
'http://[Vert.xサーバーIP]:8081/eventbus'
);
これが、さっきサーバーサイドで設定したprefixね!

!

{prefix : '/eventbus'}
SockJSアプリケーション作成 - sockjs-app.js
// openイベントハンドラ
eb.onopen = function() {
console.log('open');
eb.registerHandler(
'demo.orderMgr',
function(message) {
console.log(
'received a message: ' + JSON.stringify(message)
);
}
);
}
SockJSアプリケーション作成 - sockjs-app.js
// openイベントハンドラ
eb.onopen = function() {
console.log('open');
eb.registerHandler(
'demo.orderMgr',
function(message) {
console.log(
'received a message: ' + JSON.stringify(message)
);
}
);
}
SockJSアプリケーション作成 - sockjs-app.js
// openイベントハンドラ
eb.onopen = function() {
console.log('open');
eb.registerHandler(
'demo.orderMgr',
function(message) {
console.log(
'received a message: ' + JSON.stringify(message)
);
}
);
}
SockJSアプリケーション作成 - sockjs-app.js
// openイベントハンドラ
eb.onopen = function() {
console.log('open');
eb.registerHandler(
'demo.orderMgr',
セキュリティ設定で指定したaddress
function(message) {
console.log(
'received a message: ' + JSON.stringify(message)
);
}
);
}
SockJSアプリケーション作成 - sockjs-app.js
// openイベントハンドラ
eb.onopen = function() {
console.log('open');
eb.registerHandler(
'demo.orderMgr',
function(message) { メッセージを受信したときのコールバック関数
console.log(
'received a message: ' + JSON.stringify(message)
);
}
);
}
実行すると、こんな感じ
SockJSで、WebSocket繋がったね!
やったねっ!
これ前回…
html5j エンタープライズ部でやったやつ…
を、ちょっと詳しく説明しただけ…
デス!!
続きまして…
メッセージ交換と、マウス位置共有の設計

SockJSをSencha Ext JSのクラスシステムで
ラッピングする
Sencha Cmdを利用してワークスペースを作成する

SDKまでのパス

sencha
-s ~/Library/Sencha/ext-4.2.2.1144
generate app MyApp ./
Sencha Cmdを利用してワークスペースを作成する

チンッ!!
ext-sockjsを作る

SockJSをラッピングして、Sencha Ext JSのクラスシステムとして
利用できるようにする。
ext-sockjsを作る
Controller A
EventBus A
Controller B

Controller C

Component A

Component B

Manager

EventBus B

EventBus C
ext-sockjsを作る

大体こんな感じの、Sencha Ext JSでは、
普通のExt.AbstractManagerを継承したクラス構成
ext-sockjsを作る

というのも、粗いので、ソースを見ていきましょう…
ext-sockjsを作る

Ext.sockjs.Manager
Ext.sockjs.Manager
Ext.define('Ext.sockjs.Manager', {
extend: 'Ext.AbstractManager',
requires: [
'Ext.util.MixedCollection',
'Ext.sockjs.EventBus'
],
mixins: {
observable: 'Ext.util.Observable'
},
singleton: true,
Ext.sockjs.Manager
Ext.define('Ext.sockjs.Manager', {
extend: 'Ext.AbstractManager',
requires: [
'Ext.util.MixedCollection',
'Ext.sockjs.EventBus'
],
mixins: {
observable: 'Ext.util.Observable'
},
singleton: true,
Ext.sockjs.Manager
Ext.define('Ext.sockjs.Manager', {
extend: 'Ext.AbstractManager',
requires: [
'Ext.util.MixedCollection',
'Ext.sockjs.EventBus'
],
mixins: {
observable: 'Ext.util.Observable'
},
singleton: true,
Ext.sockjs.Manager
Ext.define('Ext.sockjs.Manager', {
extend: 'Ext.AbstractManager',
requires: [
'Ext.util.MixedCollection',
'Ext.sockjs.EventBus'
],
mixins: {
observable: 'Ext.util.Observable'
},
singleton: true,
Ext.sockjs.Manager
Ext.define('Ext.sockjs.Manager', {
extend: 'Ext.AbstractManager',
requires: [
'Ext.util.MixedCollection',
'Ext.sockjs.EventBus'
],
mixins: {
observable: 'Ext.util.Observable'
},
singleton: true,
Ext.sockjs.Manager
Ext.define('Ext.sockjs.Manager', {
extend: 'Ext.AbstractManager',
requires: [
'Ext.util.MixedCollection',
'Ext.sockjs.EventBus'
],
mixins: {
observable: 'Ext.util.Observable'
},
singleton: true,
Ext.sockjs.Manager
constructor: function() {
var me = this;
me.eventbuses = new Ext.util.MixedCollection();
me.mixins.observable.constructor.call(me);
},
Ext.sockjs.Manager
constructor: function() {
var me = this;
me.eventbuses = new Ext.util.MixedCollection();
me.mixins.observable.constructor.call(me);
},
Ext.sockjs.Manager
constructor: function() {
var me = this;
me.eventbuses = new Ext.util.MixedCollection();
me.mixins.observable.constructor.call(me);
},
Ext.sockjs.Manager
constructor: function() {
var me = this;
me.eventbuses = new Ext.util.MixedCollection();
me.mixins.observable.constructor.call(me);
},
Ext.sockjs.Manager
addEventBus: function(config) {
var me = this;
config = config || {};
Ext.applyIf(config, {
url: '',
addr: ''
});
me.eventbuses.add(
config.addr,
Ext.create('Ext.sockjs.EventBus', config)
);
},
Ext.sockjs.Manager
addEventBus: function(config) {
var me = this;
config = config || {};
Ext.applyIf(config, {
url: '',
addr: ''
});
me.eventbuses.add(
config.addr,
Ext.create('Ext.sockjs.EventBus', config)
);
},
Ext.sockjs.Manager
addEventBus: function(config) {
var me = this;
config = config || {};
Ext.applyIf(config, {
url: '',
addr: ''
});
me.eventbuses.add(
config.addr,
Ext.create('Ext.sockjs.EventBus', config)
);
},
Ext.sockjs.Manager
addEventBus: function(config) {
var me = this;
config = config || {};
Ext.applyIf(config, {
url: '',
addr: ''
});
me.eventbuses.add(
config.addr,
Ext.create('Ext.sockjs.EventBus', config)
);
},
Ext.sockjs.Manager
addEventBus: function(config) {
var me = this;
config = config || {};
Ext.applyIf(config, {
url: '',
addr: ''
});
me.eventbuses.add(
config.addr,
Ext.create('Ext.sockjs.EventBus', config)
);
},
Ext.sockjs.Manager
get: function(name) {
var me = this;
return me.eventbuses.get(name);
}
}, function() {
Ext.SockJS = Ext.sockjs.Manager;
});
Ext.sockjs.Manager
get: function(name) {
var me = this;
return me.eventbuses.get(name);
}
}, function() {
Ext.SockJS = Ext.sockjs.Manager;
});
Ext.sockjs.Manager
get: function(name) {
var me = this;
return me.eventbuses.get(name);
}
}, function() {
Ext.SockJS = Ext.sockjs.Manager;
});
Ext.sockjs.Manager
get: function(name) {
var me = this;
return me.eventbuses.get(name);
}
}, function() {
Ext.SockJS = Ext.sockjs.Manager;
});
ext-sockjsを作る

Managerはできたので、次は管理される側を…
ext-sockjsを作る

Ext.sockjs.EventBus
Ext.sockjs.EventBus
Ext.define('Ext.sockjs.EventBus', {
mixins: {
observable: 'Ext.util.Observable'
},
Ext.sockjs.EventBus
Ext.define('Ext.sockjs.EventBus', {
mixins: {
observable: 'Ext.util.Observable'
},
Ext.sockjs.EventBus
Ext.define('Ext.sockjs.EventBus', {
mixins: {
observable: 'Ext.util.Observable'
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this, conn;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this, conn;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this, conn;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this, conn;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this, conn;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this, conn;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this, conn;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
constructor: function(config) {
var me = this, conn;
Ext.apply(me, config);
Ext.applyIf(me, {
id
: Ext.id(null, 'eventbus-'),
conn
: new vertx.EventBus(config.url)
});
Ext.apply(me.conn, {
onopen
: Ext.Function.pass(me.onOpen, [], me),
onmessage
: Ext.Function.pass(me.onMessage, [], me),
onclose
: Ext.Function.pass(me.onClose, [], me)
});
me.mixins.observable.constructor.call(me, config);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onOpen: function(eventbus) {
var me = this;
me.fireEvent('open');
me.conn.registerHandler(me.addr, Ext.Function.pass(me.onReceive, [], me));
},
onReceive: function(message) {
var me = this;
me.fireEvent('receive', message);
},
onMessage: function(e) {
var me = this;
me.fireEvent('message', e);
console.log('message', e.data);
},
Ext.sockjs.EventBus
onClose:function() {
var me = this;
me.fireEvent('close');
console.log('close');
},
publish: function(o) {
var me = this;
me.conn.publish(me.addr, o);
}
});
Ext.sockjs.EventBus
onClose: function() {
var me = this;
me.fireEvent('close');
console.log('close');
},
publish: function(o) {
var me = this;
me.conn.publish(me.addr, o);
}
});
Ext.sockjs.EventBus
onClose: function() {
var me = this;
me.fireEvent('close');
console.log('close');
},
publish: function(o) {
var me = this;
me.conn.publish(me.addr, o);
}
});
Ext.sockjs.EventBus
onClose: function() {
var me = this;
me.fireEvent('close');
console.log('close');
},
publish: function(o) {
var me = this;
me.conn.publish(me.addr, o);
}
});
Ext.sockjs.EventBus
onClose: function() {
var me = this;
me.fireEvent('close');
console.log('close');
},
publish: function(o) {
var me = this;
me.conn.publish(me.addr, o);
}
});
メッセージのやりとりをする

最初に解説した、素のSockJSサンプルと同じ事を
Sencha Ext JS上で、作ったクラスを使ってやってみま
しょう。
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
!

eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
!

eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
!

eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
!

eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
!

eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
!

eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
!

eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr);
!

eb.on('receive', function(o) {
console.log(o);
});
サンプルコード

this.control({
'button[action=publish]': {
click: function() {
eb.publish('testdata');
}
},
});
サンプルコード

this.control({
'button[action=publish]': {
click: function() {
eb.publish('testdata');
}
},
});
サンプルコード

this.control({
'button[action=publish]': {
click: function() {
eb.publish('testdata');
}
},
});
サンプルコード

this.control({
'button[action=publish]': {
click: function() {
eb.publish('testdata');
}
},
});
サンプルコード

this.control({
'button[action=publish]': {
click: function() {
eb.publish('testdata');
}
},
});
デモ
共有オブジェクト(仮)

メッセージのやりとりができたので、
今度は、Ext.window.Windowを表示して、
複数のブラウザで位置やサイズを共有してみましょう。
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr),
win, lock = false;
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr),
win, lock = false;
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr),
win, lock = false;
サンプルコード

Ext.SockJS.addEventBus({
url
: 'http://xxx.xxx.xxx.xxx:8081/eventbus',
addr
: 'demo.orderMgr'
});
!

var addr = 'demo.orderMgr',
eb = Ext.SockJS.get(addr),
win, lock = false;
サンプルコード
eb.on('receive', function(o) {
if(!lock) {
win.suspendEvents(false);
if(o.x || o.y) {
win.setPosition(o.x, o.y);
} else if(o.width || o.height) {
win.setSize(o.width, o.height);
}
win.resumeEvents();
}
lock = false;
});
サンプルコード
eb.on('receive', function(o) {
if(!lock) {
win.suspendEvents(false);
if(o.x || o.y) {
win.setPosition(o.x, o.y);
} else if(o.width || o.height) {
win.setSize(o.width, o.height);
}
win.resumeEvents();
}
lock = false;
});
サンプルコード
eb.on('receive', function(o) {
if(!lock) {
win.suspendEvents(false);
if(o.x || o.y) {
win.setPosition(o.x, o.y);
} else if(o.width || o.height) {
win.setSize(o.width, o.height);
}
win.resumeEvents();
}
lock = false;
});
サンプルコード
eb.on('receive', function(o) {
if(!lock) {
win.suspendEvents(false);
if(o.x || o.y) {
win.setPosition(o.x, o.y);
} else if(o.width || o.height) {
win.setSize(o.width, o.height);
}
win.resumeEvents();
}
lock = false;
});
サンプルコード

this.control({
'button[action=createwindow]': {
click: function() {
win = Ext.widget('window', {
itemId: 'hoge',
autoShow: true,
width: 300,
height: 200
});
サンプルコード

this.control({
'button[action=createwindow]': {
click: function() {
win = Ext.widget('window', {
itemId: 'hoge',
autoShow: true,
width: 300,
height: 200
});
サンプルコード

this.control({
'button[action=createwindow]': {
click: function() {
win = Ext.widget('window', {
itemId: 'hoge',
autoShow: true,
width: 300,
height: 200
});
サンプルコード

});

}

}

win.on({
move: function(win, x, y) {
lock = true;
eb.publish({
x: x,
y: y
});
},
resize: function(win, width, height) {
lock = true;
eb.publish({
width: width,
height: height
});
}
});
サンプルコード

});

}

}

win.on({
move: function(win, x, y) {
lock = true;
eb.publish({
x: x,
y: y
});
},
resize: function(win, width, height) {
lock = true;
eb.publish({
width: width,
height: height
});
}
});
サンプルコード

});

}

}

win.on({
move: function(win, x, y) {
lock = true;
eb.publish({
x: x,
y: y
});
},
resize: function(win, width, height) {
lock = true;
eb.publish({
width: width,
height: height
});
}
});
デモ
まとめ

SockJSのクライアントライブラリと、EventBusをラッピングして
しまえば、Sencha クラスシステム上で違和感なく利用できる。
メッセージングで処理する内容を、コンポーネントの共有(共有オ
ブジェクト)や、データストアなどSencha クラスシステム上の構
造に乗せていくと、よりリアルタイムにおもしろいアプリケーショ
ンが作れそう。
まとめ

インフラは、前回html5j エンタープライズ部で話した、vert.xでス
ケールもできてEventBusに乗せとけば、あまり細かいこと考えなく
ても良さそう。
素のWebSocket使ってやるより、良くない?
使う技術に翻弄されず、
やりたいことを迅速に実現しよう!
今日、紹介したソースコードは、GitHubにて公開してあります。

が!まだまだSencha Ext JSクラスっぽく無いので鋭意作成中…

https://github.com/xenophy/ext-sockjs
Sencha フレームワーク SockJS
まだまだ、可能性がありそうだねっ!
ご清聴ありがとうございました!

Más contenido relacionado

La actualidad más candente

日本 GNU AWK ユーザー会チラシ - OSC2012 Tokyo/Fall
日本 GNU AWK ユーザー会チラシ - OSC2012 Tokyo/Fall日本 GNU AWK ユーザー会チラシ - OSC2012 Tokyo/Fall
日本 GNU AWK ユーザー会チラシ - OSC2012 Tokyo/Fall
博文 斉藤
 
サーバー実装いろいろ
サーバー実装いろいろサーバー実装いろいろ
サーバー実装いろいろ
kjwtnb
 
ISUCONの話(夏期講習2014)
ISUCONの話(夏期講習2014)ISUCONの話(夏期講習2014)
ISUCONの話(夏期講習2014)
SATOSHI TAGOMORI
 
CategoLJについて
CategoLJについてCategoLJについて
CategoLJについて
Toshiaki Maki
 

La actualidad más candente (20)

第1回Webサーバ勉強会 - 212-223 ブラウザマッチ処理
第1回Webサーバ勉強会 - 212-223 ブラウザマッチ処理第1回Webサーバ勉強会 - 212-223 ブラウザマッチ処理
第1回Webサーバ勉強会 - 212-223 ブラウザマッチ処理
 
日本 GNU AWK ユーザー会チラシ - OSC2012 Tokyo/Fall
日本 GNU AWK ユーザー会チラシ - OSC2012 Tokyo/Fall日本 GNU AWK ユーザー会チラシ - OSC2012 Tokyo/Fall
日本 GNU AWK ユーザー会チラシ - OSC2012 Tokyo/Fall
 
おすすめ gem
おすすめ gemおすすめ gem
おすすめ gem
 
SlackのIncomingWebhooksとOutgoingWebhooksを使って電子工作と連携させてみよう
SlackのIncomingWebhooksとOutgoingWebhooksを使って電子工作と連携させてみようSlackのIncomingWebhooksとOutgoingWebhooksを使って電子工作と連携させてみよう
SlackのIncomingWebhooksとOutgoingWebhooksを使って電子工作と連携させてみよう
 
第1回鹿児島node.jsの会資料_内村
第1回鹿児島node.jsの会資料_内村第1回鹿児島node.jsの会資料_内村
第1回鹿児島node.jsの会資料_内村
 
Start React with Browserify
Start React with BrowserifyStart React with Browserify
Start React with Browserify
 
「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップ「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップ
 
Tide - SmalltalkでSPA
Tide - SmalltalkでSPATide - SmalltalkでSPA
Tide - SmalltalkでSPA
 
PHP 2大 web フレームワークの徹底比較!
PHP 2大 web フレームワークの徹底比較!PHP 2大 web フレームワークの徹底比較!
PHP 2大 web フレームワークの徹底比較!
 
サーバー実装いろいろ
サーバー実装いろいろサーバー実装いろいろ
サーバー実装いろいろ
 
ISUCONの話(夏期講習2014)
ISUCONの話(夏期講習2014)ISUCONの話(夏期講習2014)
ISUCONの話(夏期講習2014)
 
Windows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMIWindows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMI
 
CategoLJについて
CategoLJについてCategoLJについて
CategoLJについて
 
EWD 3トレーニングコース#31 ewd-xpressでWebおよびRESTサービスを作る
EWD 3トレーニングコース#31 ewd-xpressでWebおよびRESTサービスを作るEWD 3トレーニングコース#31 ewd-xpressでWebおよびRESTサービスを作る
EWD 3トレーニングコース#31 ewd-xpressでWebおよびRESTサービスを作る
 
EWD 3トレーニングコース#4 ewd-xpressのインストールと構成
EWD 3トレーニングコース#4 ewd-xpressのインストールと構成EWD 3トレーニングコース#4 ewd-xpressのインストールと構成
EWD 3トレーニングコース#4 ewd-xpressのインストールと構成
 
丸の内MongoDB勉強会#20LT 2.8のストレージエンジン動かしてみました
丸の内MongoDB勉強会#20LT 2.8のストレージエンジン動かしてみました丸の内MongoDB勉強会#20LT 2.8のストレージエンジン動かしてみました
丸の内MongoDB勉強会#20LT 2.8のストレージエンジン動かしてみました
 
Progressive Framework Vue.js 2.0
Progressive Framework Vue.js 2.0Progressive Framework Vue.js 2.0
Progressive Framework Vue.js 2.0
 
これから利用拡大?WebSocket
これから利用拡大?WebSocketこれから利用拡大?WebSocket
これから利用拡大?WebSocket
 
20081003
2008100320081003
20081003
 
Wight: Phantom’s Perl friend - YAPC::Asia 2012
Wight: Phantom’s Perl friend - YAPC::Asia 2012Wight: Phantom’s Perl friend - YAPC::Asia 2012
Wight: Phantom’s Perl friend - YAPC::Asia 2012
 

Destacado

SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
Ngoc Dao
 

Destacado (20)

SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
WebSockets with Spring 4
WebSockets with Spring 4WebSockets with Spring 4
WebSockets with Spring 4
 
Make social media work for you
Make social media work for youMake social media work for you
Make social media work for you
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
 
WebSockets and Java
WebSockets and JavaWebSockets and Java
WebSockets and Java
 
讓「文字型簡報」可讀性更高
讓「文字型簡報」可讀性更高讓「文字型簡報」可讀性更高
讓「文字型簡報」可讀性更高
 
把握每個人生機會 創造自我高峰 | 莊淑芬 Shenan Chuang
把握每個人生機會 創造自我高峰 | 莊淑芬 Shenan Chuang把握每個人生機會 創造自我高峰 | 莊淑芬 Shenan Chuang
把握每個人生機會 創造自我高峰 | 莊淑芬 Shenan Chuang
 
Websockets and SockJS, Real time chatting
Websockets and SockJS, Real time chattingWebsockets and SockJS, Real time chatting
Websockets and SockJS, Real time chatting
 
SKET Servise Guide
SKET Servise GuideSKET Servise Guide
SKET Servise Guide
 
日本都市再生15年回顧
日本都市再生15年回顧日本都市再生15年回顧
日本都市再生15年回顧
 
Spring + WebSocket integration
Spring + WebSocket integrationSpring + WebSocket integration
Spring + WebSocket integration
 
デザイン提案の参考資料
デザイン提案の参考資料デザイン提案の参考資料
デザイン提案の参考資料
 
Webライティング11のルール
Webライティング11のルールWebライティング11のルール
Webライティング11のルール
 
Digital Leadership, Reputation and Being Your Best Self
Digital Leadership, Reputation and Being Your Best SelfDigital Leadership, Reputation and Being Your Best Self
Digital Leadership, Reputation and Being Your Best Self
 
REST vs. Messaging For Microservices
REST vs. Messaging For MicroservicesREST vs. Messaging For Microservices
REST vs. Messaging For Microservices
 
素敵なプレゼン資料を作るためのKnow-Howてんこ盛りセッション:プレゼン道場 Ver 2.2
素敵なプレゼン資料を作るためのKnow-Howてんこ盛りセッション:プレゼン道場 Ver 2.2素敵なプレゼン資料を作るためのKnow-Howてんこ盛りセッション:プレゼン道場 Ver 2.2
素敵なプレゼン資料を作るためのKnow-Howてんこ盛りセッション:プレゼン道場 Ver 2.2
 
ビジネスマン必見!キレイな提案書を作るためのデザインの基礎知識
ビジネスマン必見!キレイな提案書を作るためのデザインの基礎知識ビジネスマン必見!キレイな提案書を作るためのデザインの基礎知識
ビジネスマン必見!キレイな提案書を作るためのデザインの基礎知識
 
【プレゼン】見やすいプレゼン資料の作り方【初心者用】
【プレゼン】見やすいプレゼン資料の作り方【初心者用】【プレゼン】見やすいプレゼン資料の作り方【初心者用】
【プレゼン】見やすいプレゼン資料の作り方【初心者用】
 
Social Media Best Practices, Part 1
Social Media Best Practices, Part 1Social Media Best Practices, Part 1
Social Media Best Practices, Part 1
 
Top Non Profits On Social Media Q4 2015
Top Non Profits On Social Media Q4 2015Top Non Profits On Social Media Q4 2015
Top Non Profits On Social Media Q4 2015
 

Similar a Using SockJS(Websocket) with Sencha Ext JS

大阪Node学園八時限目 「expressで作るWebアプリ」
大阪Node学園八時限目 「expressで作るWebアプリ」大阪Node学園八時限目 「expressで作るWebアプリ」
大阪Node学園八時限目 「expressで作るWebアプリ」
Shunsuke Watanabe
 
13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs
Takayoshi Tanaka
 
Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話
Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話
Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話
Akira Inoue
 
かんたん Twitter アプリをつくろう
かんたん Twitter アプリをつくろう かんたん Twitter アプリをつくろう
かんたん Twitter アプリをつくろう
Shuhei Iitsuka
 
Titanium Mobile
Titanium MobileTitanium Mobile
Titanium Mobile
Naoya Ito
 

Similar a Using SockJS(Websocket) with Sencha Ext JS (20)

大阪Node学園八時限目 「expressで作るWebアプリ」
大阪Node学園八時限目 「expressで作るWebアプリ」大阪Node学園八時限目 「expressで作るWebアプリ」
大阪Node学園八時限目 「expressで作るWebアプリ」
 
ボット開発でも DevOps! BotBuilder のテスト手法
ボット開発でも DevOps! BotBuilder のテスト手法ボット開発でも DevOps! BotBuilder のテスト手法
ボット開発でも DevOps! BotBuilder のテスト手法
 
13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs
 
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)
 
Real world android akka
Real world android akkaReal world android akka
Real world android akka
 
WebRTC meetup Tokyo 1
WebRTC meetup  Tokyo 1WebRTC meetup  Tokyo 1
WebRTC meetup Tokyo 1
 
Java EE8 Report
Java EE8 ReportJava EE8 Report
Java EE8 Report
 
Vue.js で XSS
Vue.js で XSSVue.js で XSS
Vue.js で XSS
 
Node handson
Node handsonNode handson
Node handson
 
JavaOne2014報告会資料
JavaOne2014報告会資料JavaOne2014報告会資料
JavaOne2014報告会資料
 
リアルFacebookガジェットを作った(ロングバージョン)
リアルFacebookガジェットを作った(ロングバージョン)リアルFacebookガジェットを作った(ロングバージョン)
リアルFacebookガジェットを作った(ロングバージョン)
 
Data apiで実現 進化するwebの世界
Data apiで実現 進化するwebの世界Data apiで実現 進化するwebの世界
Data apiで実現 進化するwebの世界
 
Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話
Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話
Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話
 
Node.jsでブラウザメッセンジャー
Node.jsでブラウザメッセンジャーNode.jsでブラウザメッセンジャー
Node.jsでブラウザメッセンジャー
 
かんたん Twitter アプリをつくろう
かんたん Twitter アプリをつくろう かんたん Twitter アプリをつくろう
かんたん Twitter アプリをつくろう
 
ScalaMatsuri 2016
ScalaMatsuri 2016ScalaMatsuri 2016
ScalaMatsuri 2016
 
ゲーム開発初心者の僕がUnity + WebSocketで何か作ってみた
ゲーム開発初心者の僕がUnity + WebSocketで何か作ってみたゲーム開発初心者の僕がUnity + WebSocketで何か作ってみた
ゲーム開発初心者の僕がUnity + WebSocketで何か作ってみた
 
Ext.direct
Ext.directExt.direct
Ext.direct
 
Djangoフレームワークの紹介
Djangoフレームワークの紹介Djangoフレームワークの紹介
Djangoフレームワークの紹介
 
Titanium Mobile
Titanium MobileTitanium Mobile
Titanium Mobile
 

Último

Último (10)

論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 

Using SockJS(Websocket) with Sencha Ext JS