first commit
authorjordan lavatai <jordan lavatai>
Mon, 19 Jun 2017 07:17:47 +0000 (00:17 -0700)
committerjordan lavatai <jordan lavatai>
Mon, 19 Jun 2017 07:17:47 +0000 (00:17 -0700)
.gitignore [new file with mode: 0644]
.tern-project [new file with mode: 0644]
README.md [new file with mode: 0644]
admin.css [new file with mode: 0644]
admin.html [new file with mode: 0644]
admin.js [new file with mode: 0644]
main.js [new file with mode: 0644]
package.json [new file with mode: 0644]
renderer.html [new file with mode: 0644]
renderer.js [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..c2658d7
--- /dev/null
@@ -0,0 +1 @@
+node_modules/
diff --git a/.tern-project b/.tern-project
new file mode 100644 (file)
index 0000000..8e4dfe7
--- /dev/null
@@ -0,0 +1,16 @@
+{
+  "ecmaVersion": 6,
+  "libs": [],
+  "loadEagerly": [],
+  "dontLoad": [
+    "node_modules/**"
+  ],
+  "plugins": {
+    "doc_comment": true,
+    "node": {
+      "dontLoad": "",
+      "load": "",
+      "modules": ""
+    }
+  }
+}
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..383cbfb
--- /dev/null
+++ b/README.md
@@ -0,0 +1,45 @@
+# electron-quick-start
+
+**Clone and run for a quick way to see Electron in action.**
+
+This is a minimal Electron application based on the [Quick Start Guide](http://electron.atom.io/docs/tutorial/quick-start) within the Electron documentation.
+
+**Use this app along with the [Electron API Demos](http://electron.atom.io/#get-started) app for API code examples to help you get started.**
+
+A basic Electron application needs just these files:
+
+- `package.json` - Points to the app's main file and lists its details and dependencies.
+- `main.js` - Starts the app and creates a browser window to render HTML. This is the app's **main process**.
+- `index.html` - A web page to render. This is the app's **renderer process**.
+
+You can learn more about each of these components within the [Quick Start Guide](http://electron.atom.io/docs/tutorial/quick-start).
+
+## To Use
+
+To clone and run this repository you'll need [Git](https://git-scm.com) and [Node.js](https://nodejs.org/en/download/) (which comes with [npm](http://npmjs.com)) installed on your computer. From your command line:
+
+```bash
+# Clone this repository
+git clone https://github.com/electron/electron-quick-start
+# Go into the repository
+cd electron-quick-start
+# Install dependencies
+npm install
+# Run the app
+npm start
+```
+
+Note: If you're using Linux Bash for Windows, [see this guide](https://www.howtogeek.com/261575/how-to-run-graphical-linux-desktop-applications-from-windows-10s-bash-shell/) or use `node` from the command prompt.
+
+## Resources for Learning Electron
+
+- [electron.atom.io/docs](http://electron.atom.io/docs) - all of Electron's documentation
+- [electron.atom.io/community/#boilerplates](http://electron.atom.io/community/#boilerplates) - sample starter apps created by the community
+- [electron/electron-quick-start](https://github.com/electron/electron-quick-start) - a very basic starter Electron app
+- [electron/simple-samples](https://github.com/electron/simple-samples) - small applications with ideas for taking them further
+- [electron/electron-api-demos](https://github.com/electron/electron-api-demos) - an Electron app that teaches you how to use Electron
+- [hokein/electron-sample-apps](https://github.com/hokein/electron-sample-apps) - small demo apps for the various Electron APIs
+
+## License
+
+[CC0 1.0 (Public Domain)](LICENSE.md)
diff --git a/admin.css b/admin.css
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/admin.html b/admin.html
new file mode 100644 (file)
index 0000000..4ea1ed9
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="UTF-8">
+    <title>Hello World!</title>
+  </head>
+  <body>
+    <h1>Click 'start' to begin screen sharing</h1>
+    <select id="streamList">
+    </select>
+    <button id="streams"> List of streams to choose from </button>
+    <video autoplay></video>
+
+  </body>
+
+  <script src="http://127.0.0.1:5140/admin.js"></script>
+
+</html>
diff --git a/admin.js b/admin.js
new file mode 100644 (file)
index 0000000..a870de6
--- /dev/null
+++ b/admin.js
@@ -0,0 +1,25 @@
+function makeRequest() {
+console.log('Making ajax request')
+  httpRequest = new XMLHttpRequest();
+
+  if (!httpRequest) {
+    alert('Giving up :( Cannot create an XMLHTTP instance');
+    return false;
+  }
+  httpRequest.open('GET', 'http://127.0.0.1:5140/streamlist');
+  httpRequest.onreadystatechange = function(e) {
+    if (request.readyState === 4) {
+      if (request.status === 200) {
+        console.log(request.responseText)
+      }
+    }
+  }
+  httpRequest.send()
+}
+
+
+document.addEventListener('DOMContentLoaded', function() {
+  let streamlist = document.getElementById("streamlist")
+  console.log('Document is ready')
+  document.getElementById("streams").addEventListener('click', makeRequest);
+})
diff --git a/main.js b/main.js
new file mode 100644 (file)
index 0000000..13bcaa3
--- /dev/null
+++ b/main.js
@@ -0,0 +1,72 @@
+const electron = require('electron')
+const http = require('http')
+const path = require('path')
+const url = require('url')
+const fs = require('fs')
+const app = electron.app
+const BrowserWindow = electron.BrowserWindow
+const ipcMain = electron.ipcMain
+
+let mainWindow
+
+function beginRendererProcess() {
+  mainWindow = new BrowserWindow({show: true, webPreferences: { webSecurity: false, experimentalFeatures: true}})
+  mainWindow.loadURL(url.format({
+    pathname: path.join(__dirname, 'renderer.html'),
+    protocol: 'file:',
+    slashes: true
+  }))
+  mainWindow.webContents.openDevTools()
+}
+
+function captureStream() {
+  mainWindow.webContents.send('defaultStreamRequest', 'slr')
+  let p = new Promise((resolve,reject) => {
+    ipcMain.on('defaultStreamResponse', (event, arg) => {
+      console.log('defaultStreamResponse')
+      console.log(arg)
+      resolve(arg)
+    })
+  })
+
+  return p
+}
+
+
+const routes = {
+  '/': function root(response) {
+    response.write(fs.readFileSync('admin.html'))
+    response.end()
+  },
+  '/admin.js': function js(response) {
+    response.write(fs.readFileSync('admin.js'))
+    response.end()
+  },
+  '/admin.css': function css(response) {
+    response.write(fs.readFileSync('admin.css'))
+    response.end()
+  },
+  '/favicon.ico': function favicon() {
+    return 'strapp'
+    response.end()
+  },
+  '/streamlist': function streamlist(response) {
+    let mediaStream = captureStream().then((stream) => {
+      console.log(stream)
+    })
+
+    //response.write(mediaStream)
+  }
+}
+
+app.on('ready', function() {
+  beginRendererProcess()
+
+
+  http.createServer(function(request, response) {
+    const url = request.url
+    console.log('routing to ' + url);
+    routes[url](response)
+
+  }).listen(5140);
+});
diff --git a/package.json b/package.json
new file mode 100644 (file)
index 0000000..e9ab6fa
--- /dev/null
@@ -0,0 +1,22 @@
+{
+  "name": "strapp",
+  "version": "0.0.0",
+  "description": "A distributed desktop sharer",
+  "main": "main.js",
+  "scripts": {
+    "start": "electron ."
+  },
+  "repository": "",
+  "keywords": [
+    "WebRTC",
+    "Cool",
+    "Screen Sharing",
+    "Distributed",
+    "Prototype"
+  ],
+  "author": "Jordan Lavatai",
+  "license": "MIT",
+  "devDependencies": {
+    "electron": "~1.6.2"
+  }
+}
diff --git a/renderer.html b/renderer.html
new file mode 100644 (file)
index 0000000..ee9a802
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+  </head>
+  <body>
+  </body>
+  <script src="renderer.js"></script>
+</html>
diff --git a/renderer.js b/renderer.js
new file mode 100644 (file)
index 0000000..c6d45c5
--- /dev/null
@@ -0,0 +1,39 @@
+const ipcRenderer = require('electron').ipcRenderer
+const {desktopCapturer} = require('electron')
+
+
+function getDefaultStream(event) {
+  console.log('getDefaultStream')
+  desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
+    if (error) {
+      console.log(error)
+      return
+    }
+    for (let i = 0; i < sources.length; ++i) {
+      if (sources[i].name === 'Screen 1') {
+        navigator.mediaDevices.getUserMedia({
+          audio: false,
+          video: {
+            mandatory: {
+              chromeMediaSource: 'desktop',
+              chromeMediaSourceId: sources[i].id,
+              minWidth: 1280,
+              maxWidth: 1280,
+              minHeight: 720,
+              maxHeight: 720
+            }
+          }
+        }).then((stream) => {
+          console.log(stream)
+          event.sender.send('defaultStreamResponse', stream)
+        })
+      }
+    }
+    return
+  })
+}
+
+ipcRenderer.on('defaultStreamRequest', (event, message) => {
+  console.log('defaultStreamRequest received, grabbing media stream for screen1')
+  getDefaultStream(event)
+})