managing ptz cameras using elixir and the phoenix framework
TRANSCRIPT
![Page 1: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/1.jpg)
Manage PTZ Cameras with Phoenix
José C García-Sacristán
@jgsacristan
![Page 2: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/2.jpg)
![Page 3: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/3.jpg)
“Phoenix is a framework for building HTML5 apps, API backends and distributed systems to take on the modern Web.”
“Written in Elixir, you get beautiful syntax, productive tooling and a fast runtime”
![Page 4: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/4.jpg)
2 million connections per server
400 million users, 30 engineers
![Page 5: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/5.jpg)
![Page 6: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/6.jpg)
Erlang
• Created in 1986
- Windows in 1985
- Linux in 1991
• Handles 50% of the worlds telecom traffic
• Reported 99.9999999% availability (nine nines)
![Page 7: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/7.jpg)
![Page 8: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/8.jpg)
Elixir
Elixir is a functional, concurrent, general-purpose programming language that runs on the Erlang virtual machine (BEAM). Elixir builds on top of Erlang to provide distributed, fault-tolerant, soft real-time, non-stop applications but also extends it to support metaprogramming with macros and polymorphism via protocols.
![Page 9: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/9.jpg)
Productivity in Phoenix
• Short term productivity
- Documentation / Guides / Generators
- Eliminates trivial choices
• Long term productivity
- Maintainability
- Introspection
![Page 10: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/10.jpg)
Easy installation
• $mix local.hex
• $ mix archive.installhttps://github.com/phoenixframework/phoenix/releases/download/v1.0.2/phoenix_new-1.0.2.ez
• $mix phoenix.new my_app
![Page 11: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/11.jpg)
Endpoints
![Page 12: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/12.jpg)
Routers
![Page 13: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/13.jpg)
Controllers
![Page 14: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/14.jpg)
![Page 15: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/15.jpg)
![Page 16: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/16.jpg)
Generators
$ mix phoenix.gen.html
$ mix phoenix.gen.json
$ mix phoenix.gen.channel
![Page 17: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/17.jpg)
Views & Templates
• Precompiled. Fast
• Views render templates.
• Views serve as a presentation layer
• Beyond HTML
![Page 18: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/18.jpg)
Performance
![Page 19: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/19.jpg)
Robust Concurrency Model
• “processes” – extreme lightweight units of concurrency
• Garbage collection is per process
- No global pauses
• Load balances on IO and CPU
![Page 20: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/20.jpg)
Channels
Trivial realtime communication for connected devices
![Page 21: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/21.jpg)
![Page 22: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/22.jpg)
![Page 23: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/23.jpg)
![Page 24: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/24.jpg)
![Page 25: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/25.jpg)
![Page 26: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/26.jpg)
![Page 27: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/27.jpg)
But there is more ..
• Form builders
• Static build tools with ES6 by default
• Live reloading
• First class test tools
• Packages via hex.pm (+2MM downloads)
![Page 28: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/28.jpg)
Applications
• Package and run our code
• Can be started and stopped as a unit
• Provide unified configuration
• Hold processes and state in the supervision tree
![Page 29: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/29.jpg)
:observer.start
![Page 30: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/30.jpg)
:observer.start
![Page 31: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/31.jpg)
![Page 32: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/32.jpg)
![Page 33: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/33.jpg)
![Page 34: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/34.jpg)
• The ONVIF specification defines a common protocol for the exchange of information between network video devices including automatic device discovery, video streaming and intelligence metadata.
![Page 35: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/35.jpg)
Onvif Specification
Based on relevant Web Services standards including security and IP configuration requirements. Areas covered:• IP configuration• Device discovery• Device management• Media configuration• Real time viewing• Event handling• PTZ camera control• Video analytics• Security
![Page 36: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/36.jpg)
http://www.onvif.org/onvif/ver20/util/operationIndex.html
![Page 37: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/37.jpg)
Integration with evercam-media
Problems:
• Poor SOAP support in Erlang/Elixir.
• WS-Security not implemented.
• SOAP operations return XML.
• evercam-media needs JSON responses.
![Page 38: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/38.jpg)
Integration with evercam-media
Solution:
• HTTPotion for HTTP requests
![Page 39: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/39.jpg)
![Page 40: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/40.jpg)
Integration with evercam-media
Solution:
• HTTPotion for HTTP requests
• Own implementation of SOAP Envelope and WS-Security headers.
![Page 41: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/41.jpg)
![Page 42: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/42.jpg)
![Page 43: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/43.jpg)
Integration with evercam-media
Solution:
• HTTPotion for HTTP requests
• Own implementation of SOAP Envelope and WS-Security headers.
• Own implementation of XML to Elixir Map transformations using Erlang xmerl library
![Page 44: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/44.jpg)
![Page 45: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/45.jpg)
Integration with evercam-media
• Definition of needed operations using onvif_client methods.
![Page 46: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/46.jpg)
![Page 47: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/47.jpg)
Integration with evercam-media
• Definition of needed operations using onvif_client methods.
• Add REST routes to web/router.ex
![Page 48: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/48.jpg)
![Page 49: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/49.jpg)
![Page 50: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/50.jpg)
Integration with evercam-media
• Definition of needed operations using onvif_client methods.
• Add REST routes to web/router.ex
• Implement controllers that will invoke ONVIF operations and return the responses as Elixir Map structures.
![Page 51: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/51.jpg)
![Page 52: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/52.jpg)
Integration with evercam-media
• Definition of needed operations using onvif_client methods.
• Add REST routes to web/router.ex
• Implement controllers that will invoke ONVIF operations and return the responses as Elixir Map structures.
• Phoenix translate these Maps into JSON structures without the need of extra coding
![Page 53: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/53.jpg)
![Page 54: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/54.jpg)
Demo
![Page 55: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/55.jpg)
![Page 56: Managing PTZ cameras using Elixir and the Phoenix Framework](https://reader034.vdocument.in/reader034/viewer/2022050613/58a465e61a28abb8288b606d/html5/thumbnails/56.jpg)