Permalink
Browse files

Events Push - server-side

  • Loading branch information...
smaldini committed May 21, 2012
1 parent 499f367 commit 6b8bf062a57788b6f59b6cf4c5ab7d97c2f37920
@@ -1,3 +1,20 @@
+/* Copyright 2011-2012 the original author or authors:
+ *
+ * Marc Palmer (marc@grailsrocks.com)
+ * Stéphane Maldini (stephane.maldini@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import org.grails.plugin.platform.events.push.EventsPushHandler
class EventsPushGrailsPlugin {
@@ -9,9 +26,13 @@ class EventsPushGrailsPlugin {
def dependsOn = [:]
// resources that are excluded from plugin packaging
def pluginExcludes = [
- "grails-app/views/error.gsp"
+ "grails-app/views/error.gsp",
+ "grails-app/views/index.gsp",
+ "grails-app/conf/Test*.groovy",
+ "grails-app/services/**/Test*.groovy"
]
+
def title = "Events Push Plugin" // Headline display name of the plugin
def author = "Stephane Maldini"
def authorEmail = "stephane.maldini@gmail.com"
View
@@ -0,0 +1,17 @@
+/* Copyright 2011-2012 the original author or authors:
+ *
+ * Marc Palmer (marc@grailsrocks.com)
+ * Stéphane Maldini (stephane.maldini@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
@@ -18,6 +18,7 @@ log4j = {
}
debug 'org.atmosphere'
+ debug 'org.grails.plugin.platform'
error 'org.codehaus.groovy.grails.web.servlet', // controllers
@@ -0,0 +1,23 @@
+/* Copyright 2011-2012 the original author or authors:
+ *
+ * Marc Palmer (marc@grailsrocks.com)
+ * Stéphane Maldini (stephane.maldini@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import org.grails.plugin.platform.test.SampleService
+
+events = {
+ "sampleHello" scope:'browser'
+ //"sampleBro" scope:'browser', clientBroadcast:true
+}
@@ -0,0 +1,39 @@
+/* Copyright 2011-2012 the original author or authors:
+ *
+ * Marc Palmer (marc@grailsrocks.com)
+ * Stéphane Maldini (stephane.maldini@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.groovy.grails.platform.push
+
+import grails.events.Listener
+
+/**
+ * @file
+ * @author Stephane Maldini <smaldini@doc4web.com>
+ * @version 1.0
+ * @date 21/05/12
+
+ * @section DESCRIPTION
+ *
+ * [Does stuff]
+ */
+class TestService {
+
+ @Listener('sampleHello')
+ def testEvent(test) {
+ println """--> $test"""
+ new grails.events.BroadcastOrder('{ "message":"hello !!!!" }')
+ }
+}
View
@@ -37,11 +37,9 @@
request.onMessage = function (response) {
detectedTransport = response.transport;
- if (response.status == 200) {
- var data = response.responseBody;
- if (data.length > 0) {
- $('ul').prepend($('<li></li>').text(" Message Received: " + data + " but detected transport is " + detectedTransport));
- }
+ if (response.status == 200 && response.responseBody.length > 0) {
+ var data = $.parseJSON(response.responseBody);
+ $('ul').prepend($('<li></li>').text(" Message Received: " + data.message + " but detected transport is " + detectedTransport));
}
};
@@ -54,7 +52,7 @@
}
function connect() {
- unsubscribe();
+ //unsubscribe();
getElementById('phrase').value = '';
getElementById('sendMessage').className = '';
getElementById('phrase').focus();
@@ -90,7 +88,7 @@
m = " sent trying to use " + detectedTransport;
}
- subSocket.push({data:'message=' + getElementByIdValue('phrase') + m});
+ subSocket.push({data:$.stringifyJSON({message:getElementByIdValue('phrase') + m})});
getElementById('phrase').value = '';
return false;
@@ -110,7 +108,7 @@
m = " sent trying to use " + detectedTransport;
}
- subSocket.push({data:'message=' + getElementByIdValue('phrase') + m});
+ subSocket.push({data:$.stringifyJSON({message:getElementByIdValue('phrase') + m})});
getElementById('phrase').value = '';
return false;
View
@@ -1,3 +1,20 @@
+/* Copyright 2011-2012 the original author or authors:
+ *
+ * Marc Palmer (marc@grailsrocks.com)
+ * Stéphane Maldini (stephane.maldini@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import groovy.xml.StreamingMarkupBuilder
import org.codehaus.groovy.grails.commons.ConfigurationHolder
@@ -0,0 +1,40 @@
+/* Copyright 2011-2012 the original author or authors:
+ *
+ * Marc Palmer (marc@grailsrocks.com)
+ * Stéphane Maldini (stephane.maldini@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package grails.events;
+
+/**
+ * @author Stephane Maldini <smaldini@doc4web.com>
+ * @version 1.0
+ * @file
+ * @date 21/05/12
+ * @section DESCRIPTION
+ * <p/>
+ * [Does stuff]
+ */
+public class BroadcastOrder {
+
+ private Object data;
+
+ public BroadcastOrder(Object data){
+ this.data = data;
+ }
+
+ public Object getData() {
+ return data;
+ }
+}
Oops, something went wrong.

0 comments on commit 6b8bf06

Please sign in to comment.