websocket

Red5 WebSocket plugin

License

License

GroupId

GroupId

org.red5
ArtifactId

ArtifactId

websocket
Last Version

Last Version

1.16.15
Release Date

Release Date

Type

Type

jar
Description

Description

websocket
Red5 WebSocket plugin
Project URL

Project URL

https://github.com/Red5/red5-websocket
Project Organization

Project Organization

Red5
Source Code Management

Source Code Management

https://github.com/Red5/red5-websocket.git

Download websocket

How to add to project

<!-- https://jarcasting.com/artifacts/org.red5/websocket/ -->
<dependency>
    <groupId>org.red5</groupId>
    <artifactId>websocket</artifactId>
    <version>1.16.15</version>
</dependency>
// https://jarcasting.com/artifacts/org.red5/websocket/
implementation 'org.red5:websocket:1.16.15'
// https://jarcasting.com/artifacts/org.red5/websocket/
implementation ("org.red5:websocket:1.16.15")
'org.red5:websocket:jar:1.16.15'
<dependency org="org.red5" name="websocket" rev="1.16.15">
  <artifact name="websocket" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.red5', module='websocket', version='1.16.15')
)
libraryDependencies += "org.red5" % "websocket" % "1.16.15"
[org.red5/websocket "1.16.15"]

Dependencies

compile (16)

Group / Artifact Type Version
org.red5 : red5-server jar 1.0.10-M9
org.bouncycastle : bcprov-jdk15on jar 1.59
org.bouncycastle : bctls-jdk15on jar 1.59
org.slf4j : slf4j-api jar 1.7.25
org.slf4j : jcl-over-slf4j jar 1.7.25
org.slf4j : jul-to-slf4j jar 1.7.25
org.slf4j : log4j-over-slf4j jar 1.7.25
ch.qos.logback : logback-classic jar 1.2.3
org.apache.mina : mina-core bundle 2.0.19
org.apache.mina : mina-integration-beans bundle 2.0.19
org.springframework : spring-aop jar 4.3.12.RELEASE
org.springframework : spring-beans jar 4.3.12.RELEASE
org.springframework : spring-context jar 4.3.12.RELEASE
org.springframework : spring-context-support jar 4.3.12.RELEASE
org.springframework : spring-core jar 4.3.12.RELEASE
org.springframework : spring-expression jar 4.3.12.RELEASE

test (3)

Group / Artifact Type Version
org.springframework : spring-test jar 4.3.12.RELEASE
junit : junit jar 4.12
org.glassfish.tyrus.bundles : tyrus-standalone-client-jdk jar 1.13.1

Project Modules

There are no modules declared in this project.

red5-websocket

Websocket plug-in for Red5

This plugin is meant to provide websocket functionality for applications running in red5. The code is constructed to comply with rfc6455.

http://tools.ietf.org/html/rfc6455

Special thanks to Takahiko Toda and Dhruv Chopra for the initial ideas and source.

Configuration

Add the WebSocket transport to the jee-container.xml or red5.xml. If placing it in the red5.xml, ensure the bean comes after the plugin launcher entry.

To bind to one or many IP addresses and ports:

<bean id="webSocketTransport" class="org.red5.net.websocket.WebSocketTransport">
        <property name="addresses">
            <list>
            	<value>192.168.1.174</value>
            	<value>192.168.1.174:8080</value>
            	<value>192.168.1.174:10080</value>
            </list>
        </property>
</bean>

If you don't want to specify the IP:

<bean id="webSocketTransport" class="org.red5.net.websocket.WebSocketTransport">
	<property name="port" value="8080"/>
</bean>

To support secure communication (wss) add this:

    <bean id="webSocketTransportSecure" class="org.red5.net.websocket.WebSocketTransport">
        <property name="secureConfig">
            <bean id="webSocketSecureConfig" class="org.red5.net.websocket.SecureWebSocketConfiguration">
                <property name="keystoreFile" value="conf/keystore"/>
                <property name="keystorePassword" value="password"/>
                <property name="truststoreFile" value="conf/truststore"/>
                <property name="truststorePassword" value="password"/>
            </bean>
        </property>
        <property name="addresses">
            <list>
                <value>192.168.1.174:10081</value>
            </list>
        </property>
    </bean>

If you are not using unlimited strength JCE (you are outside the US), you may have to specify the cipher suites as shown below:

    <bean id="webSocketTransportSecure" class="org.red5.net.websocket.WebSocketTransport">
        <property name="secureConfig">
            <bean id="webSocketSecureConfig" class="org.red5.net.websocket.SecureWebSocketConfiguration">
                <property name="keystoreFile" value="conf/keystore"/>
                <property name="keystorePassword" value="password"/>
                <property name="truststoreFile" value="conf/truststore"/>
                <property name="truststorePassword" value="password"/>
                <property name="cipherSuites">
                    <array>
                        <value>TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256</value>
                        <value>TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA</value>
                        <value>TLS_ECDHE_RSA_WITH_RC4_128_SHA</value>
                        <value>TLS_RSA_WITH_AES_128_CBC_SHA256</value>
                        <value>TLS_RSA_WITH_AES_128_CBC_SHA</value>
                        <value>SSL_RSA_WITH_RC4_128_SHA</value>
                    </array>
                </property>
                <property name="protocols">
                    <array>
                        <value>TLSv1</value>
                        <value>TLSv1.1</value>
                        <value>TLSv1.2</value>
                    </array>
                </property>
            </bean>
        </property>
        <property name="addresses">
            <list>
                <value>192.168.1.174:10081</value>
            </list>
        </property>
    </bean>

Adding WebSocket to an Application

To enable websocket support in your application, add this to your appStart() method:

  WebSocketScopeManager manager = ((WebSocketPlugin) PluginRegistry.getPlugin("WebSocketPlugin")).getManager(scope);
  manager.setApplication(this);

For clean-up add this to appStop():

  WebSocketScopeManager manager = ((WebSocketPlugin) PluginRegistry.getPlugin("WebSocketPlugin")).getManager(scope);
  manager.stop();

Security Features

Since WebSockets don't implement Same Origin Policy (SOP) nor Cross-Origin Resource Sharing (CORS), we've implemented a means to restrict access via configuration using SOP / CORS logic. To configure the security features, edit your conf/jee-container.xml file and locate the bean displayed below:

    <bean id="webSocketTransport" class="org.red5.net.websocket.WebSocketTransport">
        <property name="addresses">
            <list>
                <value>${ws.host}:${ws.port}</value>
            </list>
        </property>
        <property name="sameOriginPolicy" value="false" />
        <property name="crossOriginPolicy" value="true" />
        <property name="allowedOrigins">
            <array>
                <value>localhost</value>
                <value>red5.org</value>
            </array>
        </property>
    </bean>

Properties:

  • sameOriginPolicy - Enables or disables SOP. The logic differs from standard web SOP by NOT enforcing protocol and port.
  • crossOriginPolicy - Enables or disables CORS. This option pairs with the allowedOrigins array.
  • allowedOrigins - The list or host names or fqdn which are to be permitted access. The default if none are specified is * which equates to any or all.

Test Page

Replace the wsUri variable with your applications path.

<!DOCTYPE html>  
<meta charset="utf-8" />  
<title>WebSocket Test</title>  
<script language="javascript" type="text/javascript">  
var wsUri = "ws://192.168.1.174:10080/myapp"; 
var output;  function init() { output = document.getElementById("output"); testWebSocket(); }  function testWebSocket() { websocket = new WebSocket(wsUri); websocket.onopen = function(evt) { onOpen(evt) }; websocket.onclose = function(evt) { onClose(evt) }; websocket.onmessage = function(evt) { onMessage(evt) }; websocket.onerror = function(evt) { onError(evt) }; }  function onOpen(evt) { writeToScreen("CONNECTED"); doSend("WebSocket rocks"); }  function onClose(evt) { writeToScreen("DISCONNECTED"); }  function onMessage(evt) { writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>'); websocket.close(); }  function onError(evt) { writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); }  function doSend(message) { writeToScreen("SENT: " + message);  websocket.send(message); }  function writeToScreen(message) { var pre = document.createElement("p"); pre.style.wordWrap = "break-word"; pre.innerHTML = message; output.appendChild(pre); }  window.addEventListener("load", init, false);  </script>  <h2>WebSocket Test</h2> <div id="output"></div>

Demo application project

https://github.com/Red5/red5-websocket-chat

Pre-compiled JAR

You can find compiled artifacts via Maven

org.red5
Red5 Media Server

Versions

Version
1.16.15
1.16.14
1.16.13
1.16.12
1.16.11
1.16.10
1.16.9
1.16.8
1.16.6
1.16.2
1.16.0
1.15
1.14
1.12
1.11
1.10
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0