An open API service indexing awesome lists of open source software.

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

Websocket plug-in for Red5
https://github.com/red5/red5-websocket

java red5 red5-websocket websocket-plug websockets ws wss

Last synced: 15 days ago
JSON representation

Websocket plug-in for Red5

Awesome Lists containing this project

README

          

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:

```xml



192.168.1.174
192.168.1.174:8080
192.168.1.174:10080

```

If you don't want to specify the IP:
```

```
To support secure communication (wss) add this:

```xml











192.168.1.174:10081



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









TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_RSA_WITH_RC4_128_SHA
TLS_RSA_WITH_AES_128_CBC_SHA256
TLS_RSA_WITH_AES_128_CBC_SHA
SSL_RSA_WITH_RC4_128_SHA




TLSv1
TLSv1.1
TLSv1.2






192.168.1.174:10081


```

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:
```xml



${ws.host}:${ws.port}






localhost
red5.org



```
Properties:
* [sameOriginPolicy](https://www.w3.org/Security/wiki/Same_Origin_Policy) - Enables or disables SOP. The logic differs from standard web SOP by *NOT* enforcing protocol and port.
* [crossOriginPolicy](https://www.w3.org/Security/wiki/CORS) - 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.

```


WebSocket Test

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);

WebSocket Test


```

Demo application project
----------------
https://github.com/Red5/red5-websocket-chat

Pre-compiled JAR
----------------
You can find [compiled artifacts via Maven](http://mvnrepository.com/artifact/org.red5/websocket)