Search in sources :

Example 6 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project wicket by apache.

the class WebSocketPushBroadcaster method process.

private void process(final Application application, final Collection<IWebSocketConnection> wsConnections, final IWebSocketPushMessage message) {
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application);
    Executor executor = webSocketSettings.getWebSocketPushMessageExecutor();
    for (final IWebSocketConnection wsConnection : wsConnections) {
        executor.run(new Runnable() {

            @Override
            public void run() {
                wsConnection.sendMessage(message);
            }
        });
    }
}
Also used : Executor(org.apache.wicket.protocol.ws.concurrent.Executor) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings)

Example 7 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project wicket by apache.

the class WebSocketTester method broadcastAll.

/**
 * Broadcasts/pushes a message to all active web socket connections
 *
 * @param application
 *          The application where the web socket connection is registered
 * @param message
 *          The message to broadcast/push
 */
public void broadcastAll(Application application, IWebSocketPushMessage message) {
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application);
    WebSocketPushBroadcaster broadcaster = new WebSocketPushBroadcaster(webSocketSettings.getConnectionRegistry());
    broadcaster.broadcastAll(application, message);
}
Also used : WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings) WebSocketPushBroadcaster(org.apache.wicket.protocol.ws.api.WebSocketPushBroadcaster)

Example 8 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project wicket by apache.

the class BaseWebSocketBehavior method renderHead.

@Override
public void renderHead(Component component, IHeaderResponse response) {
    super.renderHead(component, response);
    response.render(JavaScriptHeaderItem.forReference(WicketWebSocketJQueryResourceReference.get()));
    PackageTextTemplate webSocketSetupTemplate = new PackageTextTemplate(WicketWebSocketJQueryResourceReference.class, "res/js/wicket-websocket-setup.js.tmpl");
    Map<String, Object> variables = Generics.newHashMap();
    // set falsy JS values for the non-used parameter
    if (Strings.isEmpty(resourceName)) {
        int pageId = component.getPage().getPageId();
        variables.put("pageId", pageId);
        variables.put("resourceName", "");
    } else {
        variables.put("resourceName", resourceName);
        variables.put("pageId", false);
    }
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(component.getApplication());
    CharSequence baseUrl = getBaseUrl(webSocketSettings);
    Args.notNull(baseUrl, "baseUrl");
    variables.put("baseUrl", baseUrl);
    Integer port = getPort(webSocketSettings);
    variables.put("port", port);
    Integer securePort = getSecurePort(webSocketSettings);
    variables.put("securePort", securePort);
    CharSequence contextPath = getContextPath(webSocketSettings);
    Args.notNull(contextPath, "contextPath");
    variables.put("contextPath", contextPath);
    // preserve the application name for JSR356 based impl
    variables.put("applicationName", component.getApplication().getName());
    CharSequence filterPrefix = getFilterPrefix(webSocketSettings);
    Args.notNull(filterPrefix, "filterPrefix");
    variables.put("filterPrefix", filterPrefix);
    final CharSequence sessionId = getSessionId(component);
    variables.put("sessionId", sessionId);
    String webSocketSetupScript = webSocketSetupTemplate.asString(variables);
    response.render(OnDomReadyHeaderItem.forScript(webSocketSetupScript));
}
Also used : PackageTextTemplate(org.apache.wicket.util.template.PackageTextTemplate) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings)

Example 9 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project openmeetings by apache.

the class WebSocketHelper method sendClient.

private static void sendClient(IWsClient client, Consumer<IWebSocketConnection> wsc) {
    Application app = (Application) getApp();
    WebSocketSettings settings = WebSocketSettings.Holder.get(app);
    IWebSocketConnectionRegistry reg = settings.getConnectionRegistry();
    // FIXME TODO
    Executor executor = settings.getWebSocketPushMessageExecutor();
    final IWebSocketConnection wc = reg.getConnection(app, client.getSessionId(), new PageIdKey(client.getPageId()));
    if (wc != null && wc.isOpen()) {
        executor.run(() -> {
            wsc.accept(wc);
        });
    }
}
Also used : Executor(org.apache.wicket.protocol.ws.concurrent.Executor) PageIdKey(org.apache.wicket.protocol.ws.api.registry.PageIdKey) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings) IWebSocketConnection(org.apache.wicket.protocol.ws.api.IWebSocketConnection) IWebSocketConnectionRegistry(org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry) IApplication(org.apache.openmeetings.IApplication) Application(org.apache.wicket.Application)

Aggregations

WebSocketSettings (org.apache.wicket.protocol.ws.WebSocketSettings)9 Application (org.apache.wicket.Application)2 WebSocketPushBroadcaster (org.apache.wicket.protocol.ws.api.WebSocketPushBroadcaster)2 Executor (org.apache.wicket.protocol.ws.concurrent.Executor)2 IApplication (org.apache.openmeetings.IApplication)1 Page (org.apache.wicket.Page)1 ChartWebSocketResource (org.apache.wicket.examples.websocket.charts.ChartWebSocketResource)1 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)1 HttpsConfig (org.apache.wicket.protocol.https.HttpsConfig)1 HttpsMapper (org.apache.wicket.protocol.https.HttpsMapper)1 IWebSocketConnection (org.apache.wicket.protocol.ws.api.IWebSocketConnection)1 WebSocketConnectionOriginFilter (org.apache.wicket.protocol.ws.api.WebSocketConnectionOriginFilter)1 ConnectedMessage (org.apache.wicket.protocol.ws.api.message.ConnectedMessage)1 IWebSocketConnectionRegistry (org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry)1 PageIdKey (org.apache.wicket.protocol.ws.api.registry.PageIdKey)1 IResource (org.apache.wicket.request.resource.IResource)1 ResourceReference (org.apache.wicket.request.resource.ResourceReference)1 SharedResourceReference (org.apache.wicket.request.resource.SharedResourceReference)1 PackageTextTemplate (org.apache.wicket.util.template.PackageTextTemplate)1 WicketTester (org.apache.wicket.util.tester.WicketTester)1