You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2021/04/09 09:07:04 UTC

[myfaces-tobago] branch master updated: fix(demo): enable websocket example

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new c75c1ca  fix(demo): enable websocket example
c75c1ca is described below

commit c75c1ca61620eef2bbba33e32f4148bff4b80d15
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Apr 9 10:39:00 2021 +0200

    fix(demo): enable websocket example
    
    A requirement for f:websocket is JSF-2.3.
    Since Tobago 5 required JSF-2.3, it's safe to enable the websocket example by default.
---
 .../myfaces/tobago/example/demo/WebSocketController.java      | 11 ++++++-----
 .../src/main/webapp/WEB-INF/tobago-config.xml                 |  2 +-
 .../main/webapp/content/30-concept/18-websocket/WebSocket.js  |  2 +-
 .../webapp/content/30-concept/18-websocket/WebSocket.xhtml    |  9 ++-------
 4 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/WebSocketController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/WebSocketController.java
index ddcacf0..df4af5e 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/WebSocketController.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/WebSocketController.java
@@ -23,12 +23,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.enterprise.context.SessionScoped;
-//import javax.faces.push.Push;
-//import javax.faces.push.PushContext;
+import javax.faces.push.Push;
+import javax.faces.push.PushContext;
 import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.Serializable;
 import java.lang.invoke.MethodHandles;
+import java.time.LocalTime;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -42,8 +43,8 @@ public class WebSocketController implements Serializable {
   private ScheduledExecutorService scheduledExecutorService;
 
   @Inject
-//  @Push(channel = "clock")
-//  private PushContext push;
+  @Push(channel = "clock")
+  private PushContext push;
 
   public String startClock() {
     if (scheduledExecutorService == null || scheduledExecutorService.isShutdown()) {
@@ -53,7 +54,7 @@ public class WebSocketController implements Serializable {
     scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
       @Override
       public void run() {
-//        push.send(LocalTime.now().toString());
+        push.send(LocalTime.now().toString());
       }
     }, 0, 17, TimeUnit.MILLISECONDS);
     return null;
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml b/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
index 9c63486..5d5f784 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
@@ -49,7 +49,7 @@
 
   <content-security-policy mode="on">
     <!-- script-src: 'unsafe-inline' is required for WebSockets -->
-<!--    <directive name="script-src">'unsafe-inline'</directive>-->
+    <directive name="script-src">'unsafe-inline'</directive>
 
     <!-- needed for <tc:object> demo -->
     <directive name="child-src">https://www.openstreetmap.org</directive>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/18-websocket/WebSocket.js b/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/18-websocket/WebSocket.js
index a509a7c..c56ffe4 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/18-websocket/WebSocket.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/18-websocket/WebSocket.js
@@ -16,5 +16,5 @@
  */
 
 function websocketListener(message, channel, event) {
-  document.getElementById("clockId").innerHTML = message + "<br/>";
+  document.getElementById("clockId").innerHTML = message;
 }
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/18-websocket/WebSocket.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/18-websocket/WebSocket.xhtml
index 668ee5e..e068d2d 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/18-websocket/WebSocket.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/18-websocket/WebSocket.xhtml
@@ -25,15 +25,10 @@
   <p>Simple example for WebSockets.</p>
 
   <tc:section label="Example">
-    <p><tc:badge value="Warning" markup="warning"/>WebSockets are available since JSF 2.3</p>
-    <p><tc:badge value="Warning" markup="warning"/>CSP script-src: 'unsafe-inline' is needed.</p>
-    <p><tc:badge value="Warning" markup="warning"/>
-      WebSocket.xhtml: The comment for <code>&lt;f:websocket/></code> must be removed.</p>
-    <p><tc:badge value="Warning" markup="warning"/>
-      WebSocketController.java: The comment for 'push' and 'pushContext' must be removed.</p>
+    <p><tc:badge value="Warning" markup="warning"/> CSP script-src: 'unsafe-inline' is needed.</p>
 
     <tc:script file="#{request.contextPath}/content/30-concept/18-websocket/WebSocket.js"/>
-    <!--<f:websocket channel="clock" onmessage="websocketListener"/>-->
+    <f:websocket channel="clock" onmessage="websocketListener"/>
 
     <tc:buttons>
       <tc:button label="Start Clock" action="#{webSocketController.startClock}">