Initial javascript setup.
Can browserify and serve the sample app, and generate javascript from
vdl files.
Change-Id: Ic2052c2b7f6f946d23ebe7db55a244094305f31a
diff --git a/.gitignore b/.gitignore
index f447f7c..82cf2a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
/.v23
-go/pkg/
-go/bin/
\ No newline at end of file
+/go/pkg/
+/go/bin/
+/js/build
+/js/node_modules
diff --git a/README.md b/README.md
index d04eb27..5f053f8 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,9 @@
This is an example application built on the Vanadium stack.
+See design doc here:
+https://docs.google.com/document/d/1TT7eiSPJpGiAS__NNf51RZEAEio2myKUmH0jM3k_OxI
+
# Development
# Deployment
diff --git a/js/.jshintignore b/js/.jshintignore
new file mode 100644
index 0000000..94c965b
--- /dev/null
+++ b/js/.jshintignore
@@ -0,0 +1,3 @@
+build
+node_modules
+src/gen-vdl
diff --git a/js/.jshintrc b/js/.jshintrc
new file mode 100644
index 0000000..f846f31
--- /dev/null
+++ b/js/.jshintrc
@@ -0,0 +1,28 @@
+{
+ "camelcase": true,
+ "eqeqeq": true,
+ "expr": true,
+ "forin": true,
+ "freeze": true,
+ "immed": true,
+ "indent": 2,
+ "latedef": "nofunc",
+ "maxlen": 80,
+ "newcap": true,
+ "noarg": true,
+ "nonbsp": true,
+ "nonew": true,
+ "quotmark": "single",
+ "sub": true,
+ "trailing": true,
+ "undef": true,
+ "unused": "vars",
+ "esnext": true,
+ "browser": true,
+ "devel": true,
+ "node": true,
+
+ "globals": {
+ "Promise": true
+ }
+}
diff --git a/js/Makefile b/js/Makefile
new file mode 100644
index 0000000..03ecad2
--- /dev/null
+++ b/js/Makefile
@@ -0,0 +1,72 @@
+SHELL := /bin/bash -euo pipefail
+export PATH := $(V23_ROOT)/release/go/bin:node_modules/.bin:$(V23_ROOT)/third_party/cout/node/bin:$(PATH)
+
+# This target causes any target files to be deleted if the target task fails.
+# This is especially useful for browserify, which creates files even if it
+# fails.
+.DELETE_ON_ERROR:
+
+# Default browserify options: use sourcemaps.
+BROWSERIFY_OPTS := --debug
+# Names that should not be mangled by minification.
+RESERVED_NAMES := 'context,ctx,callback,cb,$$stream,serverCall'
+# Don't mangle RESERVED_NAMES, and screw ie8.
+MANGLE_OPTS := --mangle [--except $(RESERVED_NAMES) --screw_ie8 ]
+# Don't remove unused variables from function arguments, which could mess up signatures.
+# Also don't evaulate constant expressions, since we rely on them to conditionally require modules only in node.
+COMPRESS_OPTS := --compress [ --no-unused --no-evaluate ]
+
+# Browserify and extract sourcemap, but do not minify.
+define BROWSERIFY
+ mkdir -p $(dir $2)
+ browserify $1 $(BROWSERIFY_OPTS) | exorcist $2.map > $2
+endef
+
+# Browserify, minify, and extract sourcemap.
+define BROWSERIFY-MIN
+ mkdir -p $(dir $2)
+ browserify $1 $(BROWSERIFY_OPTS) --g [ uglifyify $(MANGLE_OPTS) $(COMPRESS_OPTS) ] | exorcist $2.map > $2
+endef
+
+node_modules: package.json
+ npm prune
+ npm install
+ # Link Vanadium from V23_ROOT.
+ rm -rf ./node_modules/vanadium
+ cd "$(V23_ROOT)/release/javascript/core" && npm link
+ npm link vanadium
+ touch node_modules
+
+src/gen-vdl: $(shell find ../go/src/ -name "*.vdl")
+ v23 run vdl generate --lang=javascript --js-out-dir=src/gen-vdl v.io/x/media_sharing
+
+build/bundle.js: src/index.js $(shell find src/ -name "*.js") src/gen-vdl node_modules
+ mkdir -p build
+ifndef NOMINIFY
+ $(call BROWSERIFY,$<,$@)
+else
+ $(call BROWSERIFY-MIN,$<,$@)
+endif
+
+build/index.html: public/index.html
+ mkdir -p build
+ cp $< $@
+
+build/style.css: public/style.css
+ mkdir -p build
+ cp $< $@
+
+build: build/bundle.js build/index.html build/style.css
+
+serve: build
+ static build
+
+.PHONY: lint
+lint: node_modules
+ jshint .
+
+.PHONY: clean
+clean:
+ rm -rf \
+ build \
+ node_modules
diff --git a/js/package.json b/js/package.json
new file mode 100644
index 0000000..1f95d9a
--- /dev/null
+++ b/js/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "media-client",
+ "private": true,
+ "version": "0.0.0",
+ "description": "client for Vanadium media server",
+ "main": "src/index.js",
+ "license": "ISC",
+ "dependencies": {
+ "domready": "~1.0.8"
+ },
+ "devDependencies": {
+ "browserify": "~10.2.0",
+ "jshint": "~2.7.0",
+ "exorcist": "~0.4.0",
+ "uglifyify": "~3.0.1",
+ "node-static": "~0.7.6"
+ }
+}
diff --git a/js/public/index.html b/js/public/index.html
new file mode 100644
index 0000000..2a0efc7
--- /dev/null
+++ b/js/public/index.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+ <title>Vanadium Media Client</title>
+ <link rel="stylesheet" type = "text/css" href="style.css">
+ <script src="bundle.js"></script>
+</head>
+<body>
+ <div id="content"></div>
+</body>
+</html>
diff --git a/js/public/style.css b/js/public/style.css
new file mode 100644
index 0000000..2a234b9
--- /dev/null
+++ b/js/public/style.css
@@ -0,0 +1,5 @@
+/* Copyright 2015 The Vanadium Authors. All rights reserved. */
+/* Use of this source code is governed by a BSD-style */
+/* license that can be found in the LICENSE file. */
+
+/* CSS will go here. */
diff --git a/js/src/gen-vdl/v.io/x/media_sharing/index.js b/js/src/gen-vdl/v.io/x/media_sharing/index.js
new file mode 100644
index 0000000..c201989
--- /dev/null
+++ b/js/src/gen-vdl/v.io/x/media_sharing/index.js
@@ -0,0 +1,104 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file was auto-generated by the vanadium vdl tool.
+var vdl = require('vanadium').vdl;
+
+
+
+
+
+
+module.exports = {};
+
+
+
+// Types:
+var _type1 = new vdl.Type();
+_type1.kind = vdl.kind.LIST;
+_type1.name = "";
+_type1.elem = vdl.types.BYTE;
+_type1.freeze();
+
+
+
+
+// Consts:
+
+
+
+// Errors:
+
+
+
+// Services:
+
+
+
+function MediaSharing(){}
+module.exports.MediaSharing = MediaSharing;
+
+
+
+MediaSharing.prototype.displayUrl = function(ctx, serverCall, url) {
+ throw new Error('Method DisplayUrl not implemented');
+};
+
+
+MediaSharing.prototype.displayBytes = function(ctx, serverCall, mediaType) {
+ throw new Error('Method DisplayBytes not implemented');
+};
+
+
+
+MediaSharing.prototype._serviceDescription = {
+ name: 'MediaSharing',
+ pkgPath: 'v.io/x/media_sharing',
+ doc: "",
+ embeds: [],
+ methods: [
+
+
+ {
+ name: 'DisplayUrl',
+ doc: "// DisplayURL will cause the server to display whatever media is at\n// the given URL. The server will rely on the ContentType response\n// header it gets when fetching the url to decide how to display\n// the media.",
+ inArgs: [{
+ name: 'url',
+ doc: "",
+ type: vdl.types.STRING
+ },
+ ],
+ outArgs: [],
+ inStream: null,
+ outStream: null,
+ tags: []
+ },
+
+
+ {
+ name: 'DisplayBytes',
+ doc: "// DisplayBytes will cause the server to display whatever media is\n// sent in the stream. In the case of audio or movie media, the\n// media should be played while the data is streaming. The mediaType\n// can be used by the server to decide how to display the media.",
+ inArgs: [{
+ name: 'mediaType',
+ doc: "",
+ type: vdl.types.STRING
+ },
+ ],
+ outArgs: [],
+ inStream: {
+ name: '',
+ doc: '',
+ type: _type1
+ },
+ outStream: null,
+ tags: []
+ },
+
+ ]
+};
+
+
+
+
+
diff --git a/js/src/index.js b/js/src/index.js
new file mode 100644
index 0000000..7571ce0
--- /dev/null
+++ b/js/src/index.js
@@ -0,0 +1,9 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+var domready = require('domready');
+
+domready(function() {
+ document.querySelector('#content').innerText = 'Hello Vanadium World';
+});