diff --git a/.gitignore b/.gitignore index f1735cb..dafe182 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ hs_err_pid* .classpath .project +.recommenders .settings/ target/ generated/ diff --git a/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/Readme.md b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/Readme.md new file mode 100644 index 0000000..8f417aa --- /dev/null +++ b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/Readme.md @@ -0,0 +1,96 @@ +# Exposing server side to http clients - HTTP Servlet Example +--- + + + + +## About +--- + + + +This example demonstrates how you can open a HTTP channel between a red5 server side application and a http client. The application registers a simple [java servlet](https://en.wikipedia.org/wiki/Java_servlet) `SampleHttpSevlet`class on the red5 web application. + +The servlet exposes & activates itself through the `web.xml` file which is located at `RED5_HOME/webapps/{appname}/WEB-INF/web.xml`. If you take a look at the servlet class `SampleHttpSevlet.java`, you will see how the red5 application object is injected into it using `@Autowired` annotation. + +We can then invoke custom application methods and standard [MultiThreadedApplicationAdapter](http://red5.org/javadoc/red5-server/org/red5/server/adapter/MultiThreadedApplicationAdapter.html) methods from the servlet itself. The servlet itself is capable to handling web requests from Http clients. Thus we can connect http client to application adapter easily. + + + + +## Build & Deploy +--- + + +### Build +--- + +To build this application : open a shell prompt in the application's project directory (where the pom.xml file resides). run the following maven command in your shell -> + +``` +mvn clean package + +``` + +The above command will generate a `war` file in the `target` directory inside the project directory. + + +### Deploy +--- + +To deploy the war to red5 / red5 pro server : + +1. Stop server if it is running. + +2. Extract the content of the `war file` to directory by war name. + +> The java war file is simply a `archive file` similar to `zip` format. you can extract it using a archive tool such as [7zip](#http://www.7-zip.org/), [Winrar trial](#http://www.rarlab.com/download.htm) etc + +3. Copy the folder into `RED5_HOME/webapps/` directory. + +4. Start server. + + +## How To Use Example +--- + + +Once you have the server application running, access the servlet running on server from your browser as: + +``` +http://{host}:5080/http-servlet-demo/endpoint +``` + +> Where ` {host}` is where you are running the server. Ex: for local testing it will be `localhost`. + + +The http call will return the following response from the servlet : + + +``` +Application context path = /default +``` + + + +## Eclipse +--- + +You can edit the server side code in your eclipse JEE IDE such as Luna, Mars, Neon etc. To import the code into your IDE: + +1. Navigate to the repository folder +2. Execute maven command `mvn eclipse:eclipse`. This will generate files necessary for eclipse to read the maven project properly. +3. In eclipse go to `File -> Import -> Existing Maven Projects` and click `Next`. +4. Browse and select `the project root` and Click `Finish` to import the project. + + + +## Additional Notes +--- + +NA + + + + + diff --git a/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/pom.xml b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/pom.xml new file mode 100644 index 0000000..1832016 --- /dev/null +++ b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/pom.xml @@ -0,0 +1,219 @@ + + 4.0.0 + com.red5pro + simple-webrtc-streamer + war + 1.0.0 + simple-webrtc-streamer + http://maven.apache.org + Red5 application demonstrating the basic skeleton of a webrtc enabled webapp + + simple-webrtc-streamer + UTF-8 + 1.0.10-M6 + 3.1.0 + 4.2.5.RELEASE + 2.0.19 + 1.7.18 + 1.1.6 + 2.0.8 + 1.8 + 1.8 + + + package + + + maven-compiler-plugin + 3.5.1 + + true + ${maven.compiler.source} + ${maven.compiler.target} + + + + maven-source-plugin + 2.4 + + + attach-sources + package + + jar + + + + + + maven-war-plugin + 2.4 + + ${finalName} + *.html,*.swf,*.js,*.swz,WEB-INF/*.properties,WEB-INF/*.xml,WEB-INF/classes/** + WEB-INF/lib/*.jar + + + + org.apache.felix + maven-bundle-plugin + 3.0.1 + true + + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + compile + + + org.red5 + red5-server + ${red5-server.version} + jar + compile + + + org.apache.mina + mina-integration-beans + + + org.apache.mina + mina-integration-jmx + + + + + org.apache.mina + mina-parent + ${mina.version} + pom + + + org.springframework + spring-beans + ${spring.version} + jar + compile + + + commons-logging + commons-logging + + + + + org.springframework + spring-core + ${spring.version} + jar + compile + + + commons-logging + commons-logging + + + + + org.springframework + spring-context + ${spring.version} + jar + compile + + + commons-logging + commons-logging + + + + + org.springframework + spring-context-support + ${spring.version} + jar + compile + + + commons-logging + commons-logging + + + + + + + + org.red5 + red5-server + + + org.red5 + tomcatplugin + ${tomcatplugin.version} + provided + + + javax.servlet + javax.servlet-api + ${servlet.version} + provided + + + org.slf4j + slf4j-api + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + org.slf4j + jul-to-slf4j + ${slf4j.version} + + + org.slf4j + log4j-over-slf4j + ${slf4j.version} + + + ch.qos.logback + logback-core + ${logback.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + org.apache.mina + mina-core + ${mina.version} + + + org.springframework + spring-beans + + + org.springframework + spring-context-support + + + org.springframework + spring-context + + + org.springframework + spring-core + + + diff --git a/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/java/com/red5/application/examples/webrtclive/Application.java b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/java/com/red5/application/examples/webrtclive/Application.java new file mode 100644 index 0000000..347208e --- /dev/null +++ b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/java/com/red5/application/examples/webrtclive/Application.java @@ -0,0 +1,46 @@ +package com.red5.application.examples.webrtclive; + +import org.red5.server.adapter.MultiThreadedApplicationAdapter; +import org.red5.server.api.IConnection; +import org.red5.server.api.scope.IScope; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class Application extends MultiThreadedApplicationAdapter { + + private static Logger log = LoggerFactory.getLogger(Application.class); + + + @Override + public boolean appStart(IScope app) { + WebSocketUtils.configureApplicationScopeWebSocket(app); + log.info("Application started"); + return super.appStart(app); + } + + + + @Override + public boolean appConnect(IConnection arg0, Object[] arg1) { + log.info("Client connecting"); + return super.appConnect(arg0, arg1); + } + + + + @Override + public void appDisconnect(IConnection arg0) { + log.info("Client disconnecting"); + super.appDisconnect(arg0); + } + + + + @Override + public void appStop(IScope app) { + WebSocketUtils.deConfigureApplicationScopeSocket(app); + log.info("Application stopped"); + super.appStop(app); + } +} diff --git a/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/java/com/red5/application/examples/webrtclive/WebSocketUtils.java b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/java/com/red5/application/examples/webrtclive/WebSocketUtils.java new file mode 100644 index 0000000..4ae501c --- /dev/null +++ b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/java/com/red5/application/examples/webrtclive/WebSocketUtils.java @@ -0,0 +1,59 @@ +package com.red5.application.examples.webrtclive; + +import org.red5.net.websocket.WSConstants; +import org.red5.net.websocket.WebSocketPlugin; +import org.red5.net.websocket.WebSocketScope; +import org.red5.net.websocket.WebSocketScopeManager; +import org.red5.server.adapter.MultiThreadedApplicationAdapter; +import org.red5.server.api.scope.IScope; +import org.red5.server.plugin.PluginRegistry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class WebSocketUtils { + + private static Logger log = LoggerFactory.getLogger(Application.class); + + + + public static void configureApplicationScopeWebSocket(IScope scope) { + + // first get the websocket plugin + WebSocketPlugin wsPlugin = ((WebSocketPlugin) PluginRegistry.getPlugin(WebSocketPlugin.NAME)); + // get the websocket scope manager for the red5 scope + WebSocketScopeManager manager = wsPlugin.getManager(scope); + + if (manager == null) { + // get the application adapter + MultiThreadedApplicationAdapter app = (MultiThreadedApplicationAdapter) scope.getHandler(); + log.debug("Creating WebSocketScopeManager for {}", app); + // set the application in the plugin to create a websocket scope manager for it + wsPlugin.setApplication(app); + // get the new manager + manager = wsPlugin.getManager(scope); + } + + // the websocket scope + WebSocketScope wsScope = (WebSocketScope) scope.getAttribute(WSConstants.WS_SCOPE); + + // check to see if its already configured + if (wsScope == null) { + log.debug("Configuring application scope: {}", scope); + // create a websocket scope for the application + wsScope = new WebSocketScope(scope); + // register the ws scope + wsScope.register(); + } + } + + + + + public static void deConfigureApplicationScopeSocket(IScope scope) + { + WebSocketScopeManager manager = ((WebSocketPlugin) PluginRegistry.getPlugin("WebSocketPlugin")).getManager(scope); + manager.removeApplication(scope); + manager.stop(); + } + +} diff --git a/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/red5-web.properties b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/red5-web.properties new file mode 100644 index 0000000..8ac4b2d --- /dev/null +++ b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/red5-web.properties @@ -0,0 +1,2 @@ +webapp.contextPath=/simple-webrtc-streamer +webapp.virtualHosts=* diff --git a/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/red5-web.xml b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/red5-web.xml new file mode 100644 index 0000000..8adb960 --- /dev/null +++ b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/red5-web.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/web.xml b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..1c3b604 --- /dev/null +++ b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,64 @@ + + + + + simple-webrtc-streamer + + + + webAppRootKey + /simple-webrtc-streamer + + + + + WebSocketFilter + org.red5.net.websocket.server.WsFilter + true + + + WebSocketFilter + /* + REQUEST + FORWARD + + + + org.red5.logging.ContextLoggingListener + + + + LoggerContextFilter + org.red5.logging.LoggerContextFilter + + + + LoggerContextFilter + /* + + + + + + + Forbidden + /streams/* + + + + + diff --git a/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/index.jsp b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/index.jsp new file mode 100644 index 0000000..db209e5 --- /dev/null +++ b/code-examples/server-side/red5-misc-examples/simple-webrtc-streamer/src/main/webapp/index.jsp @@ -0,0 +1,5 @@ + + +

Basic WebRTC Enabled Application

+ +