Skip to content

A widget that lets you load a camera via WebRTC inside ChiliPeppr.

Notifications You must be signed in to change notification settings

reecem7/widget-cam-octopi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

com-chilipeppr-widget-cam-octopi

This widget loads a webcam view in ChiliPeppr via WebRTC.

alt text

ChiliPeppr Widget / Cam

All ChiliPeppr widgets/elements are defined using cpdefine() which is a method that mimics require.js. Each defined object must have a unique ID so it does not conflict with other ChiliPeppr widgets.

Item Value
ID com-chilipeppr-widget-cam-octopi
Name Widget / Cam
Description This widget loads a webcam view in ChiliPeppr via WebRTC.
chilipeppr.load() URL http://raw.githubusercontent.com/reecem7/widget-cam-octopi/master/auto-generated-widget.html
Edit URL http://ide.c9.io/reecem7/widget-cam-octopi
Github URL http://github.com/reecem7/widget-cam-octopi
Test URL https://preview.c9users.io/reecem7/widget-cam-octopi/widget.html

Example Code for chilipeppr.load() Statement

You can use the code below as a starting point for instantiating this widget inside a workspace or from another widget. The key is that you need to load your widget inlined into a div so the DOM can parse your HTML, CSS, and Javascript. Then you use cprequire() to find your widget's Javascript and get back the instance of it.

// Inject new div to contain widget or use an existing div with an ID
$("body").append('<' + 'div id="myDivWidgetCamOctopi"><' + '/div>');

chilipeppr.load(
  "#myDivWidgetCamOctopi",
  "http://raw.githubusercontent.com/reecem7/widget-cam-octopi/master/auto-generated-widget.html",
  function() {
    // Callback after widget loaded into #myDivWidgetCamOctopi
    // Now use require.js to get reference to instantiated widget
    cprequire(
      ["inline:com-chilipeppr-widget-cam-octopi"], // the id you gave your widget
      function(myObjWidgetCamOctopi) {
        // Callback that is passed reference to the newly loaded widget
        console.log("Widget / Cam just got loaded.", myObjWidgetCamOctopi);
        myObjWidgetCamOctopi.init();
      }
    );
  }
);

Publish

This widget/element publishes the following signals. These signals are owned by this widget/element and are published to all objects inside the ChiliPeppr environment that listen to them via the chilipeppr.subscribe(signal, callback) method. To better understand how ChiliPeppr's subscribe() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
(No signals defined in this widget/element)

Subscribe

This widget/element subscribes to the following signals. These signals are owned by this widget/element. Other objects inside the ChiliPeppr environment can publish to these signals via the chilipeppr.publish(signal, data) method. To better understand how ChiliPeppr's publish() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
(No signals defined in this widget/element)

Foreign Publish

This widget/element publishes to the following signals that are owned by other objects. To better understand how ChiliPeppr's subscribe() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
(No signals defined in this widget/element)

Foreign Subscribe

This widget/element publishes to the following signals that are owned by other objects. To better understand how ChiliPeppr's publish() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
(No signals defined in this widget/element)

Methods / Properties

The table below shows, in order, the methods and properties inside the widget/element.

Method / Property Type Description
idstring"com-chilipeppr-widget-cam-octopi"

The ID of the widget. You must define this and make it unique.
namestring"Widget / Cam"
descstring"This widget loads a webcam view in ChiliPeppr via WebRTC."
urlstring"http://raw.githubusercontent.com/reecem7/widget-cam-octopi/master/auto-generated-widget.html"
fiddleurlstring"http://ide.c9.io/reecem7/widget-cam-octopi"
githuburlstring"http://github.com/reecem7/widget-cam-octopi"
testurlstring"http://widget-cam-octopi-reecem7.c9users.io/widget.html"
publishobjectPlease see docs above.

Define the publish signals that this widget/element owns or defines so that other widgets know how to subscribe to them and what they do.
subscribeobjectPlease see docs above.

Define the subscribe signals that this widget/element owns or defines so that other widgets know how to subscribe to them and what they do.
foreignPublishobjectPlease see docs above.

Document the foreign publish signals, i.e. signals owned by other widgets or elements, that this widget/element publishes to.
foreignSubscribeobjectPlease see docs above.

Document the foreign subscribe signals, i.e. signals owned by other widgets or elements, that this widget/element subscribes to.
initfunctionfunction ()

All widgets should have an init method. It should be run by the instantiating code like a workspace or a different widget.
activatefunctionfunction ()

When this widget is activated
deactivatefunctionfunction ()

When this widget is deactivated
isRunningInitCheckForCambooleanWhen this widget is activated, we need to do a few things: 1. Check if there is a stored setting of what cam to connect to because this could be a different host than what SPJS is running on. If no setting: 1. Check if we are SPJS connected 2. Check if we are on a Raspberry Pi 3. If so, then see if uv4l is installed 4. If so, then launch it 5. Connect If not Raspi, show error. If no uv4l, go into install process.
initCheckForCamfunctionfunction ()
webRtcCallbackobject
webRtcGofunctionfunction (callback)

Use this as your main entry point. You need to provide a callback which will be told success or error.
onWebRtcSuccessfunctionfunction ()

Called after successfully streaming remote video
onWebRtcErrorfunctionfunction (errMsg)

Called if failure connecting and streaming.
webRtcInitfunctionfunction ()

Trigger the initial check of whether WebRTC is running on the server.
webRtcCeatePeerConnectionfunctionfunction ()
onWebRtcIceCandidatefunctionfunction (event)
onWebRtcRemoteStreamAddedfunctionfunction (event)
onWebRtcRemoteStreamRemovedfunctionfunction (event)
webRtcOfferfunctionfunction (stream)
webRtcStartfunctionfunction ()
webRtcStopfunctionfunction ()
setupPubSubForSpjsConnectfunctionfunction ()

Subscribe to connect/disconnect events for SPJS so we can pivot off of it for detection.
ipAddrForSpjsobject
onSpjsConnectfunctionfunction (payload, more)
onSpjsDisconnectfunctionfunction ()
sendExecRuntimefunctionfunction ()

Send the execruntime command to the currently running SPJS to see what OS is running.
sendfunctionfunction (cmd)

Send a terminal command to the currently running SPJS.
isInSendSyncModeboolean
sendSyncCallbackobject
sendSyncIdNumnumber
sendSyncfunctionfunction (cmd, callback)

Send synchronously with callback as if you were right at the command line
onSendSyncWsRecvfunctionfunction (msg)
isAreWeSubscribedToLowLevelboolean
subscribeToLowLevelSerialfunctionfunction ()
unsubscribeFromLowLevelSerialfunctionfunction ()
onWsRecvfunctionfunction (msg)
isInRaspiCheckModeboolean
raspiCapturestring
isRaspberryPiboolean
checkRaspiUserCallbackobject
checkIfRaspberryPifunctionfunction (callback)
checkIfRaspberryPiCallbackfunctionfunction (payload)
isInCheckLinuxModeboolean
checkLinuxCallbackobject
checkIfLinuxfunctionfunction (callback)
execruntimeobject
onExecRuntimeStatusfunctionfunction (json)
isSpjsStatusInittedboolean
statusCallbackobject
checkIfSpjsConnectedfunctionfunction (callback)
requestSpjsStatusfunctionfunction ()
onRequestSpjsStatusCallbackfunctionfunction (payload)
uv4lSetupInstallfunctionfunction ()

Attach all events to the install div to enable everything to work.
isUseLoginboolean
userobject
passobject
onHostLoginfunctionfunction ()
signalling_server_hostnamestring"localhost"
signalling_server_addressstring"undefined:443"
isFirefoxboolean
initCamfunctionfunction ()

Initialize the Cam widget
onBtnStartClickfunctionfunction (evt)
onBtnStopClickfunctionfunction (evt)
wsobject
pcobject
audio_video_streamobject
pcConfigobject
pcOptionsobject
mediaConstraintsobject
RTCPeerConnectionobject
RTCSessionDescriptionobject
RTCIceCandidateobject
URLobject
createPeerConnectionfunctionfunction ()
onIceCandidatefunctionfunction (event)
onRemoteStreamAddedfunctionfunction (event)
onRemoteStreamRemovedfunctionfunction (event)
serverobject
startfunctionfunction ()
offerfunctionfunction (stream)
stopfunctionfunction ()
mutefunctionfunction ()
pausefunctionfunction ()
fullscreenfunctionfunction ()
singleselectionfunctionfunction (name, id)
btnSetupfunctionfunction ()

Call this method from init to setup all the buttons when this widget is first loaded. This basically attaches click events to your buttons. It also turns on all the bootstrap popovers by scanning the entire DOM of the widget.
showOptionsModalfunctionfunction ()
optionsobject
setupUiFromLocalStoragefunctionfunction ()

Call this method on init to setup the UI by reading the user's stored settings from localStorage and then adjust the UI to reflect what the user wants.
saveOptionsLocalStoragefunctionfunction ()

When a user changes a value that is stored as an option setting, you should call this method immediately so that on next load the value is correctly set.
showBodyfunctionfunction (evt)

Show the body of the panel.

evt ({jquery_event}) - If you pass the event parameter in, we know it was clicked by the user and thus we store it for the next load so we can reset the user's preference. If you don't pass this value in we don't store the preference because it was likely code that sent in the param.
hideBodyfunctionfunction (evt)

Hide the body of the panel.

evt ({jquery_event}) - If you pass the event parameter in, we know it was clicked by the user and thus we store it for the next load so we can reset the user's preference. If you don't pass this value in we don't store the preference because it was likely code that sent in the param.
forkSetupfunctionfunction ()

This method loads the pubsubviewer widget which attaches to our upper right corner triangle menu and generates 3 menu items like Pubsub Viewer, View Standalone, and Fork Widget. It also enables the modal dialog that shows the documentation for this widget.

By using chilipeppr.load() we can ensure that the pubsubviewer widget is only loaded and inlined once into the final ChiliPeppr workspace. We are given back a reference to the instantiated singleton so its not instantiated more than once. Then we call it's attachTo method which creates the full pulldown menu for us and attaches the click events.

About ChiliPeppr

ChiliPeppr is a hardware fiddle, meaning it is a website that lets you easily create a workspace to fiddle with your hardware from software. ChiliPeppr provides a Serial Port JSON Server that you run locally on your computer, or remotely on another computer, to connect to the serial port of your hardware like an Arduino or other microcontroller.

You then create a workspace at ChiliPeppr.com that connects to your hardware by starting from scratch or forking somebody else's workspace that is close to what you are after. Then you write widgets in Javascript that interact with your hardware by forking the base template widget or forking another widget that is similar to what you are trying to build.

ChiliPeppr is massively capable such that the workspaces for TinyG and Grbl CNC controllers have become full-fledged CNC machine management software used by tens of thousands.

ChiliPeppr has inspired many people in the hardware/software world to use the browser and Javascript as the foundation for interacting with hardware. The Arduino team in Italy caught wind of ChiliPeppr and now ChiliPeppr's Serial Port JSON Server is the basis for the Arduino's new web IDE. If the Arduino team is excited about building on top of ChiliPeppr, what will you build on top of it?

About

A widget that lets you load a camera via WebRTC inside ChiliPeppr.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 54.4%
  • HTML 45.1%
  • CSS 0.5%