• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

moto web application


コミットメタ情報

リビジョン1816d8604e55b94b08df43ab939ef7b4b32ebd96 (tree)
日時2014-02-03 17:27:16
作者astoria-d <astoria-d@mail...>
コミッターastoria-d

ログメッセージ

clean up

変更サマリ

差分

--- a/WEB-INF/classes/motoSample/AtmosRes.java
+++ b/WEB-INF/classes/motoSample/AtmosRes.java
@@ -43,18 +43,4 @@ public class AtmosRes {
4343 }
4444 }
4545
46- /**
47- * Simple annotated class that demonstrate how {@link org.atmosphere.config.managed.Encoder} and {@link org.atmosphere.config.managed.Decoder
48- * can be used.
49- *
50- * @param message an instance of {@link Message}
51- * @return
52- * @throws IOException
53- @org.atmosphere.config.service.Message(encoders = {JacksonEncoder.class}, decoders = {JacksonDecoder.class})
54- public Message onMessage(Message message) throws IOException {
55- logger.info("{} just send {}", message.getAuthor(), message.getMessage());
56- return message;
57- }
58- */
59-
6046 }
\ No newline at end of file
--- a/WEB-INF/classes/motoSample/ChatBean.java
+++ b/WEB-INF/classes/motoSample/ChatBean.java
@@ -28,9 +28,6 @@ import java.util.Date;
2828 import java.text.SimpleDateFormat;
2929 import java.util.UUID;
3030
31-//import org.primefaces.push.PushContext;
32-//import org.primefaces.push.PushContextFactory;
33-
3431 import org.atmosphere.cpr.Broadcaster;
3532 import org.atmosphere.cpr.BroadcasterFactory;
3633 import org.codehaus.jackson.map.ObjectMapper;
@@ -227,9 +224,6 @@ public class ChatBean implements Serializable {
227224 cm.setDate(dt);
228225 cm.setUname(userBean.getUid());
229226
230- //PushContext pushContext = PushContextFactory.getDefault().getPushContext();
231- //pushContext.push("/" + chatRoom, pm);
232-
233227 Broadcaster b = BroadcasterFactory.getDefault().lookup("/chat", true);
234228 ObjectMapper mapper = new ObjectMapper();
235229 try {
--- a/WEB-INF/classes/motoSample/UserBean.java
+++ b/WEB-INF/classes/motoSample/UserBean.java
@@ -18,8 +18,10 @@ import javax.servlet.http.HttpSession;
1818 import java.util.ArrayList;
1919 import javax.faces.model.SelectItem;
2020
21-//import org.primefaces.push.PushContext;
22-//import org.primefaces.push.PushContextFactory;
21+import org.atmosphere.cpr.Broadcaster;
22+import org.atmosphere.cpr.BroadcasterFactory;
23+import org.codehaus.jackson.map.ObjectMapper;
24+import java.io.IOException;
2325
2426 @ManagedBean
2527 @SessionScoped
@@ -123,12 +125,19 @@ public class UserBean implements Serializable {
123125 for (SelectItem si : flights) {
124126 String chatRoom = si.getValue().toString();
125127
126- /*PushMsg pm = PushMsg.newLoginPushMsg();
127- pm.lu.uid = uid;
128- pm.lu.login = true;
129-*/
130- //PushContext pushContext = PushContextFactory.getDefault().getPushContext();
131- //pushContext.push("/" + chatRoom, pm);
128+ PushMsg pm = PushMsg.newLoginPushMsg();
129+ PushMsg.LoginUser lu = pm.getLoginUser();
130+ lu.setUid(uid);
131+ lu.setLogin(true);
132+
133+ Broadcaster b = BroadcasterFactory.getDefault().lookup("/chat", true);
134+ ObjectMapper mapper = new ObjectMapper();
135+ try {
136+ String json = mapper.writeValueAsString(pm);
137+ b.broadcast(json);
138+ } catch (IOException e) {
139+ log.severe("json encode error.");
140+ }
132141 }
133142
134143 ///after login, redirect to the user specified url.
@@ -160,12 +169,19 @@ public class UserBean implements Serializable {
160169 //notify log in message
161170 for (SelectItem si : flights) {
162171 String chatRoom = si.getValue().toString();
163- /*PushMsg pm = PushMsg.newLoginPushMsg();
164- pm.lu.uid = uid;
165- pm.lu.login = false;
166-*/
167- //PushContext pushContext = PushContextFactory.getDefault().getPushContext();
168- //pushContext.push("/" + chatRoom, pm);
172+ PushMsg pm = PushMsg.newLoginPushMsg();
173+ PushMsg.LoginUser lu = pm.getLoginUser();
174+ lu.setUid(uid);
175+ lu.setLogin(false);
176+
177+ Broadcaster b = BroadcasterFactory.getDefault().lookup("/chat", true);
178+ ObjectMapper mapper = new ObjectMapper();
179+ try {
180+ String json = mapper.writeValueAsString(pm);
181+ b.broadcast(json);
182+ } catch (IOException e) {
183+ log.severe("json encode error.");
184+ }
169185 }
170186 loginMemberBean.login(uid, false);
171187 context.getExternalContext().invalidateSession();
--- a/secured/chat.xhtml
+++ b/secured/chat.xhtml
@@ -74,19 +74,12 @@ $(function () {
7474 var content = $('#content');
7575 //var input = $('#input');
7676 var input = $('#chatForm\\:msg');
77- var submitBtn = $('#chatForm\\:postBtn');
78- var inputStatus = $('#chatForm\\:inputStatus');
79-
77+
8078 var status = $('#status');
81- var myName = false;
82- var author = null;
83- var logged = false;
8479 var socket = atmosphere;
8580 var subSocket;
8681 var transport = 'websocket';
8782
88- inputStatus.value = 'init';
89-
9083 // We are now ready to cut the request
9184 var request = { url: '/moto_web_app/chat',
9285 contentType : "application/json",
@@ -110,7 +103,7 @@ $(function () {
110103
111104 request.onClientTimeout = function(r) {
112105 content.html($('<p>', { text: 'Client closed the connection after a timeout. Reconnecting in ' + request.reconnectInterval }));
113- subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: 'is inactive and closed the connection. Will reconnect in ' + request.reconnectInterval }));
106+ //subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: 'is inactive and closed the connection. Will reconnect in ' + request.reconnectInterval }));
114107 input.attr('disabled', 'disabled');
115108 setTimeout(function (){
116109 subSocket = socket.subscribe(request);
@@ -134,28 +127,19 @@ $(function () {
134127 var message = response.responseBody;
135128 try {
136129 var json = atmosphere.util.parseJSON(message);
137- handleMessage(json);
138130 } catch (e) {
139131 console.log('This doesn\'t look like a valid JSON: ', message);
140132 return;
141133 }
142-
143134
135+ handleMessage(json);
144136 input.removeAttr('disabled').focus();
145- /*if (!logged && myName) {
146- logged = true;
147- status.text(myName + ': ').css('color', 'blue');
148- } else {
149- var me = json.author == author;
150- var date = typeof(json.time) == 'string' ? parseInt(json.time) : json.time;
151- addMessage(json.author, json.message, me ? 'blue' : 'black', new Date(date));
152- }*/
153137 };
154138
155139 request.onClose = function(response) {
156140 content.html($('<p>', { text: 'Server closed the connection after a timeout' }));
157141 if (subSocket) {
158- subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: 'disconnecting' }));
142+ //subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: 'disconnecting' }));
159143 }
160144 input.attr('disabled', 'disabled');
161145 };
@@ -163,7 +147,6 @@ $(function () {
163147 request.onError = function(response) {
164148 content.html($('<p>', { text: 'Sorry, but there\'s some problem with your '
165149 + 'socket or the server is down' }));
166- logged = false;
167150 };
168151
169152 request.onReconnect = function(request, response) {
@@ -172,82 +155,9 @@ $(function () {
172155 };
173156
174157 subSocket = socket.subscribe(request);
175- /*
176- input.keydown(function(e) {
177- //console.log(e);
178- console.log("keydown. kc: " + e.keyCode + ", st: " + inputStatus.value);
179- if (e.keyCode === 13) {
180- var msg = $(this).val();
181-
182- // First message is always the author's name
183- if (author == null) {
184- author = msg;
185- }
186-
187- //subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: msg }));
188-// $(this).val('');
189-
190-// input.attr('disabled', 'disabled');
191- if (myName === false) {
192- myName = msg;
193- }
194- inputStatus.value = 'dataSubmit';
195- inputStatus.change();
196- }
197- });
198-
199- inputStatus.change(function () {
200- console.log('status changed: ' + inputStatus.value);
201- if (inputStatus.value == 'dataProcessed') {
202- alert('bbb');
203- inputStatus.value = 'pushRequested';
204- inputStatus.change();
205- }
206- });
207-
208- function pushMsg(uid, msg) {
209- subSocket.push(atmosphere.util.stringifyJSON({ author: uid, message: msg }));
210- }
211-*/
212- function addMessage(author, message, color, datetime) {
213- content.append('<p><span style="color:' + color + '">' + author + '</span> @ ' +
214- + (datetime.getHours() < 10 ? '0' + datetime.getHours() : datetime.getHours()) + ':'
215- + (datetime.getMinutes() < 10 ? '0' + datetime.getMinutes() : datetime.getMinutes())
216- + ': ' + message + '</p>');
217- }
218-});
219158
220-/* function handlePostBtn(data) {
221- var buttonElement = data.source; // The HTML DOM element which invoked the ajax event.
222- var ajaxStatus = data.status; // Can be "begin", "complete" and "success".
223- //var inputStatus = document.getElementById("chatForm:inputStatus");
224- var inputStatus = $('#chatForm\\:inputStatus');
159+});
225160
226- switch (ajaxStatus) {
227- case "begin": // This is called right before ajax request is been sent.
228- buttonElement.disabled = true;
229- break;
230-
231- case "complete": // This is called right after ajax response is received.
232- // We don't want to enable it yet here, right?
233- break;
234-
235- case "success": // This is called when ajax response is successfully processed.
236- buttonElement.disabled = false;
237-
238- var msg = document.getElementById("chatForm:msg");
239- msg.value = '';
240- msg.focus();
241- //pushMsg('aaa', 'bss');
242- inputStatus.value = "dataProcessed";
243- console.log("ajax return. st: " + inputStatus.value);
244- inputStatus.change();
245-
246- break;
247- }
248- }
249- */
250-
251161 //]]>
252162 </script>
253163
@@ -312,7 +222,6 @@ $(function () {
312222 <f:ajax execute="viewId chatRoom msg" />
313223 <!-- f:ajax execute="viewId chatRoom msg" onevent="handlePostBtn" / -->
314224 </h:commandButton>
315- <h:inputHidden id="inputStatus" value=""/>
316225
317226 </td>
318227 <td>
@@ -343,7 +252,6 @@ $(function () {
343252 <div id="content"></div>
344253 <div>
345254 <span id="status">Connecting...</span>
346- <input type="text" id="input" disabled="disabled"/>
347255 </div>
348256
349257 </ui:define>