This workshop introduces to WebRTC and how you can utilize its open API to develop Rich Communication services in your web applications. It describes a general Java gateway to allow the translation of WebRTC to SIP, the protocol used internally in the majority of VoIP networks and how Groovy is used to empower the process. In the end of the workshop, the assistants will be able to develop and deploy a basic webpage and they will have the knowledge to customize the example and develop more complex features, adding audio, video or data to HTML5, iOS or Android applications.
5. There was a time...
●
Where we use to see video by using plug-ins and
external software
●
Instant Messaging was delivered using the same
concepts and Voice = Telephony
●
Suddenly everything changed
10. So, what is WebRTC?
●
A built-in application program interface that enables
browser-to-browser applications for:
●
voice calling
●
video chat
●
peer to peer of any data
●
Media engine in the browser, accessed by JavaScript,
downloaded from web-server.
●
Collaborative W3C and IETF standardization
12. So, what is WebRTC - Technically Speaking?
PEER CONNECTION
(AUDIO, VIDEO, DATA)
WEB SERVER
(WEBRTC CONTROL)
GATEWAY
PEER CONNECTION
(AUDIO, VIDEO, DATA)
PEER CONNECTION
(AUDIO, VIDEO, DATA)
WEB SERVER
(WEBRTC CONTROL)
13. What isn't WebRTC - Technically Speaking?
●
No MTI coded media
●
No defined signaling mechanism
It's a Standard
Specification and an
opensource project
14. Signaling – The Two Approach
SIP over WebSockets JSON over WebSockets
15. Why JSON, XMPP, * and not SIP?
●
Much more easy
●
There are more developers
●
Language of the web
●
And it’s natively supported by browser
●
Drives more SIP into the network
21. Consideration
●
Lack of WebRTC Support:
●
SDK/library for Windows Phone and IOS devices
●
Hardware support for Mobile Phone
●
Software encoding & decoding will kill your battery
for VP8
●
New device will benefits from power processor
●
Snapdragon 800 4
●
nVidia Tegra 4
39. Follow the mantra…
●
Java is Groovy, Groovy is Java.
●
Flat learning curve for Java developers, start with
straight Java syntax then move on to a groovier syntax
as you feel comfortable.
●
Almost 98% Java code is Groovy code, meaning you
can in most changes rename *.java to *.groovy and it
will work.
40. Template Engine maps messages in both
directions between applications and network
JSON Template
Engine
SIP message
Application Network
46. Inbound INVITE Request Template
TemplateContext passed as an argument
Using Script Library method
Creating a future task executed on successful ME response
48. Groovy tips and tricks
●
Use “def” to declare variables and make them local:
def b = "foo“.
●
Simplification of a getter method notation: def factory
= context.webFactory // instead of
context.getWebFactory()
●
Safe navigation operator (?.): def errorCode =
context.webMessage?.header?.error_code
●
Check for a null object: if
(context.webMessage?.payload?.sdp)
49. Groovy tips and tricks
●
Compile static @groovy.transform.CompileStatic (no
dynamic types, compiles better and faster)
●
Iterators
●
’as’ keyword
●
Closures
●
array and list operators * and *. – called ”spread” and
”spread-dot”
●
GPath – similar to xpath but runs on objects not xml
50. Groovy scripts troubleshooting
●
Add println statements and see output in the system
out, e.g.: println “from=" + from
●
Use log4j and see output in wsc.log file, e.g.
org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(getClass())
logger.info(“groovy info: from=“ + from)
●
When an exception is thrown within a Groovy script, a
stack trace will be logged in the wsc.log file.
52. Groovy scripts troubleshooting
Caused by: groovy.lang.MissingPropertyException: No such property: sipReq for class: Script2
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231
)
at Script2.pkg_register_dir_FROM_APP_typ_request_verb_connect_netsvc_default(Script2.groovy:705)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:952)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at groovy.lang.Closure.call(Closure.java:411)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.callGlobal(GroovyScriptEngineImpl.java:411)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.callGlobal(GroovyScriptEngineImpl.java:405)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.invokeImpl(GroovyScriptEngineImpl.java:394)
...
54. Example SIP Request Variable
// Create REGISTER request
def from = getFromAddress(context)
def to = getToAddress(context)
def sipReq = context.sipFactory.createSipRequest("REGISTER",
from, to)
// Set request URI
sipReq.requestURI =
context.sipFactory.createSipAddress(Constants.PROXY_SIP_URI)
.URI
// Set contact user
if (from.URI?.user) {
sipReq.setContactUser(from.URI.user)
}
// Set sip.instance to allow container to use SIP Outbound
// for routing purposes as defined in RFC 5626
def sipInstance = ""<urn:uuid:" +
java.util.UUID.randomUUID() + ">""
sipReq.setSipContactParameter("+sip.instance", sipInstance)
sipReq.setSipContactParameter("reg-id", "1")
context.subSessionStore.put("sip.instance", sipInstance)
sipReq.send()
55. GRUUs
A GRUU (Globally Routable User-Agent URI) is a SIP URI which
has a few properties.
?
57. Protecting System Performance
by Removing SIP Messages
if (sipResponse.status < 200) {
// Ignore provisional responses
} else if (sipResponse.status < 300)
// Proceed with processing
}
{...
}
58. Removing a SIP Header in a
Message
sipReq.removeHeader("headername")
59. Conditionally Passing SIP Headers
in Messages
def myWebParameter =
context.webMessage?.header.?myParameter
if (myWebParameter) {
sipRequest.setHeader("MyHeader",
myWebParameter)
}
60. REST
●
Asynchronous and synchronous callback responses
●
Support for HTTP and HTTPS
●
Support for all standard REST methods
●
Support for REST calls during message processing or
WebSocket connection establishment
61. Defining a REST URL Endpoint Constant
public static final MY_REST_URL =
"http://server:port/rest_endpoint"
Referencing the URL Constant
def restRequest =
context.restClient.createRequest(Constants.MY
_REST_URL...);
74. Summary
●
WebRTC is a great option to implement or add Real
Time Communication services.
●
Groovy is very good in network systems: it provides
flexibility, easy to use and good performance
●
If you like communications & developing, don't miss
TADHack 2015.