Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
33
gaia/distros/spark/apps/sharing/js/services/achievements_service.js
Executable file
33
gaia/distros/spark/apps/sharing/js/services/achievements_service.js
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
define(["exports", "fxos-achievements-service/dist/achievements-service", "app/js/services/broadcast_service"], function (exports, _fxosAchievementsServiceDistAchievementsService, _appJsServicesBroadcastService) {
|
||||
"use strict";
|
||||
|
||||
var AchievementsService = _fxosAchievementsServiceDistAchievementsService["default"];
|
||||
var BroadcastService = _appJsServicesBroadcastService["default"];
|
||||
|
||||
|
||||
var ACHIEVEMENT_CRITERIA = "achievements/sharing-is-caring";
|
||||
var ACHIEVEMENT_EVIDENCE = "urn:sharing:p2p_broadcast:true";
|
||||
|
||||
var AchievementsServiceWrapper = function AchievementsServiceWrapper() {
|
||||
// Create an achievements service
|
||||
var achievementsService = new AchievementsService();
|
||||
|
||||
// When sharing is enabled, reward an achievement
|
||||
BroadcastService.addEventListener("broadcast", function (_ref) {
|
||||
var broadcast = _ref.broadcast;
|
||||
if (!broadcast) {
|
||||
// Do nothing if sharing is disabled
|
||||
return;
|
||||
}
|
||||
achievementsService.reward({
|
||||
criteria: ACHIEVEMENT_CRITERIA,
|
||||
evidence: ACHIEVEMENT_EVIDENCE,
|
||||
name: "Sharing is Caring",
|
||||
description: "Share your apps and add-ons with the Sharing app",
|
||||
image: "icons/sharing-is-caring.png"
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports["default"] = new AchievementsServiceWrapper();
|
||||
});
|
||||
38
gaia/distros/spark/apps/sharing/js/services/activity_service.js
Executable file
38
gaia/distros/spark/apps/sharing/js/services/activity_service.js
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc"], function (exports, _fxosMvcDistMvc) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var ActivityService = (function (Service) {
|
||||
var ActivityService = function ActivityService(guard) {
|
||||
Service.call(this);
|
||||
|
||||
navigator.mozSetMessageHandler("activity", function (req) {
|
||||
var option = req.source;
|
||||
|
||||
if (option.name === "share") {
|
||||
window.activityHandled = "share";
|
||||
var app = option.data.app;
|
||||
window.alert("Sharing " + app + " is not implemented yet");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
_extends(ActivityService, Service);
|
||||
|
||||
return ActivityService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new ActivityService();
|
||||
});
|
||||
215
gaia/distros/spark/apps/sharing/js/services/apps_service.js
Executable file
215
gaia/distros/spark/apps/sharing/js/services/apps_service.js
Executable file
|
|
@ -0,0 +1,215 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc", "app/js/models/app"], function (exports, _fxosMvcDistMvc, _appJsModelsApp) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var App = _appJsModelsApp["default"];
|
||||
var AppsService = (function (Service) {
|
||||
var AppsService = function AppsService() {
|
||||
var _this = this;
|
||||
Service.call(this);
|
||||
|
||||
this._apps = [];
|
||||
this._getApps();
|
||||
|
||||
var mgmt = navigator.mozApps.mgmt;
|
||||
mgmt.addEventListener("install", function (app) {
|
||||
return _this._handleInstall(app);
|
||||
});
|
||||
mgmt.addEventListener("uninstall", function (app) {
|
||||
return _this._handleUninstall(app);
|
||||
});
|
||||
};
|
||||
|
||||
_extends(AppsService, Service);
|
||||
|
||||
AppsService.prototype.installAppBlob = function (appData) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var sdcard = navigator.getDeviceStorage("sdcard");
|
||||
if (!sdcard) {
|
||||
console.error("No SD card!");
|
||||
reject({ name: "No SD card!" });
|
||||
return;
|
||||
}
|
||||
|
||||
var fileName = "temp-app.zip";
|
||||
var delReq = sdcard["delete"](fileName);
|
||||
delReq.onsuccess = delReq.onerror = function () {
|
||||
var req = sdcard.addNamed(new Blob([appData], { type: "application/openwebapp+zip" }), fileName);
|
||||
|
||||
req.onsuccess = function () {
|
||||
var getReq = sdcard.get(fileName);
|
||||
|
||||
getReq.onsuccess = function () {
|
||||
var file = getReq.result;
|
||||
navigator.mozApps.mgmt["import"](file).then(function (app) {
|
||||
resolve(app);
|
||||
}, function (e) {
|
||||
console.error("error installing app", e);
|
||||
reject(e);
|
||||
});
|
||||
};
|
||||
|
||||
getReq.onerror = function () {
|
||||
console.error("error getting file", getReq.error.name);
|
||||
reject(getReq.error);
|
||||
};
|
||||
};
|
||||
|
||||
req.onerror = function (e) {
|
||||
console.error("error saving blob", e);
|
||||
reject(e);
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
AppsService.prototype.markInstalledAppsInProximityApps = function (peers) {
|
||||
var _this2 = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this2._getApps().then(function () {
|
||||
resolve(peers);
|
||||
});
|
||||
});
|
||||
/*
|
||||
for (var peerIndex in peers) {
|
||||
var peer = peers[peerIndex];
|
||||
['apps', 'addons', 'themes'].forEach(appType => {
|
||||
if (!peer[appType]) {
|
||||
return;
|
||||
}
|
||||
for (var i = peer[appType].length - 1; i >= 0; i--) {
|
||||
var app = peer[appType][i];
|
||||
var matchingApp = this._apps.find((installedApp) => {
|
||||
return installedApp.manifest.name === app.manifest.name;
|
||||
});
|
||||
if (matchingApp) {
|
||||
peer[appType][i].installed = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
resolve(peers);
|
||||
});
|
||||
});
|
||||
*/
|
||||
};
|
||||
|
||||
AppsService.prototype.getApps = function (noFilter) {
|
||||
var _this3 = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this3._getApps().then(function () {
|
||||
resolve(noFilter ? _this3._apps : App.filterDefaults(_this3._apps));
|
||||
}, reject);
|
||||
});
|
||||
};
|
||||
|
||||
AppsService.prototype._getApp = function (app, resolve) {
|
||||
var _this4 = this;
|
||||
// XXX/drs: This is higher than we need, but some apps scale have
|
||||
// icons as low as 16px, which look really bad. I'd rather we
|
||||
// scale them down than up.
|
||||
navigator.mozApps.mgmt.getIcon(app, "128").then(function (icon) {
|
||||
var fr = new FileReader();
|
||||
fr.addEventListener("loadend", function () {
|
||||
app.icon = fr.result;
|
||||
_this4._apps.push(app);
|
||||
if (resolve) {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
fr.readAsDataURL(icon);
|
||||
}, function () {
|
||||
app.icon = "icons/default.png";
|
||||
_this4._apps.push(app);
|
||||
if (resolve) {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AppsService.prototype._getApps = function () {
|
||||
var _this5 = this;
|
||||
if (!this._initialized) {
|
||||
this._initialized = new Promise(function (oresolve, reject) {
|
||||
_this5._apps = [];
|
||||
|
||||
var iconPromises = [];
|
||||
|
||||
var req = navigator.mozApps.mgmt.getAll();
|
||||
req.onsuccess = function () {
|
||||
var result = req.result;
|
||||
|
||||
for (var index in result) {
|
||||
var app = result[index];
|
||||
iconPromises.push(new Promise(function (resolve, reject) {
|
||||
return _this5._getApp(app, resolve);
|
||||
}));
|
||||
}
|
||||
|
||||
Promise.all(iconPromises).then(function () {
|
||||
oresolve(_this5._apps);
|
||||
_this5._dispatchEvent("updated");
|
||||
});
|
||||
};
|
||||
|
||||
req.onerror = function (e) {
|
||||
console.error("error fetching installed apps: ", e);
|
||||
reject(e);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return this._initialized;
|
||||
};
|
||||
|
||||
AppsService.prototype._handleInstall = function (e) {
|
||||
var _this6 = this;
|
||||
var app = e.application;
|
||||
|
||||
var updateApp = function () {
|
||||
(new Promise(function (resolve, reject) {
|
||||
_this6._apps = _this6._apps.filter(function (installedApp) {
|
||||
return app.manifestURL !== installedApp.manifestURL;
|
||||
});
|
||||
_this6._getApp(app, resolve);
|
||||
})).then(function () {
|
||||
_this6._dispatchEvent("updated");
|
||||
});
|
||||
};
|
||||
|
||||
if (app.downloading) {
|
||||
var downloaded = function () {
|
||||
app.removeEventListener("downloadsuccess", downloaded);
|
||||
updateApp();
|
||||
};
|
||||
app.addEventListener("downloadsuccess", downloaded);
|
||||
} else {
|
||||
updateApp();
|
||||
}
|
||||
};
|
||||
|
||||
AppsService.prototype._handleUninstall = function (e) {
|
||||
var app = e.application;
|
||||
this._apps = this._apps.filter(function (installedApp) {
|
||||
return app.manifestURL !== installedApp.manifestURL;
|
||||
});
|
||||
this._dispatchEvent("updated");
|
||||
};
|
||||
|
||||
return AppsService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new AppsService();
|
||||
});
|
||||
77
gaia/distros/spark/apps/sharing/js/services/broadcast_service.js
Executable file
77
gaia/distros/spark/apps/sharing/js/services/broadcast_service.js
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc"], function (exports, _fxosMvcDistMvc) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var BroadcastService = (function (Service) {
|
||||
var BroadcastService = function BroadcastService() {
|
||||
var _this = this;
|
||||
Service.call(this);
|
||||
|
||||
this._initialized = new Promise(function (resolve, reject) {
|
||||
navigator.mozSettings.addObserver("lightsaber.p2p_broadcast", function (e) {
|
||||
_this._broadcastLoaded(e.settingValue);
|
||||
});
|
||||
|
||||
var broadcastSetting = navigator.mozSettings.createLock().get("lightsaber.p2p_broadcast", false);
|
||||
|
||||
broadcastSetting.onsuccess = function () {
|
||||
_this._broadcastLoaded(broadcastSetting.result["lightsaber.p2p_broadcast"]);
|
||||
resolve();
|
||||
};
|
||||
|
||||
broadcastSetting.onerror = function () {
|
||||
console.error("error getting `lightsaber.p2p_broadcast` setting");
|
||||
reject();
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
_extends(BroadcastService, Service);
|
||||
|
||||
BroadcastService.prototype.getBroadcast = function () {
|
||||
var _this2 = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this2._initialized.then(function () {
|
||||
resolve(_this2._broadcast);
|
||||
}, reject);
|
||||
});
|
||||
};
|
||||
|
||||
BroadcastService.prototype.setBroadcast = function (val) {
|
||||
new Promise(function (resolve, reject) {
|
||||
var request = navigator.mozSettings.createLock().set({
|
||||
"lightsaber.p2p_broadcast": val });
|
||||
|
||||
request.onsuccess = function () {
|
||||
resolve();
|
||||
};
|
||||
|
||||
request.onerror = function (e) {
|
||||
console.error("error getting `lightsaber.p2p_broadcast` setting");
|
||||
reject(e);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
BroadcastService.prototype._broadcastLoaded = function (val) {
|
||||
this._broadcast = val;
|
||||
this._dispatchEvent("broadcast", { broadcast: val });
|
||||
};
|
||||
|
||||
return BroadcastService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new BroadcastService();
|
||||
});
|
||||
99
gaia/distros/spark/apps/sharing/js/services/device_name_service.js
Executable file
99
gaia/distros/spark/apps/sharing/js/services/device_name_service.js
Executable file
|
|
@ -0,0 +1,99 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc"], function (exports, _fxosMvcDistMvc) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var DeviceNameService = (function (Service) {
|
||||
var DeviceNameService = function DeviceNameService() {
|
||||
var _this = this;
|
||||
Service.call(this);
|
||||
|
||||
navigator.mozSettings.addObserver("lightsaber.device_name", function (e) {
|
||||
_this._deviceName = e.settingValue;
|
||||
_this._dispatchEvent("devicenamechange", { deviceName: e.settingValue });
|
||||
});
|
||||
|
||||
this._initialized = new Promise(function (resolve, reject) {
|
||||
var request = navigator.mozSettings.createLock().get("lightsaber.device_name");
|
||||
|
||||
request.onsuccess = function () {
|
||||
var result = request.result["lightsaber.device_name"];
|
||||
if (!result) {
|
||||
_this._isDefault = true;
|
||||
}
|
||||
|
||||
_this._deviceName = result || "";
|
||||
|
||||
resolve();
|
||||
};
|
||||
|
||||
request.onerror = function (e) {
|
||||
console.error("error getting lightsaber.device_name: " + e);
|
||||
reject(e);
|
||||
};
|
||||
}).then(function () {
|
||||
_this._dispatchEvent("devicenamechange", { deviceName: _this._deviceName });
|
||||
});
|
||||
};
|
||||
|
||||
_extends(DeviceNameService, Service);
|
||||
|
||||
DeviceNameService.prototype.setDeviceName = function (deviceName) {
|
||||
var _this2 = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (!deviceName) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
|
||||
var request = navigator.mozSettings.createLock().set({
|
||||
"lightsaber.device_name": deviceName });
|
||||
|
||||
request.onsuccess = function () {
|
||||
_this2._isDefault = false;
|
||||
_this2._dispatchEvent("devicenamechange", { deviceName: deviceName });
|
||||
resolve();
|
||||
};
|
||||
|
||||
request.onerror = function (e) {
|
||||
console.error("error setting lightsaber.device_name: " + e);
|
||||
reject(e);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
DeviceNameService.prototype.getDeviceName = function () {
|
||||
var _this3 = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
return _this3._initialized.then(function () {
|
||||
resolve(_this3._deviceName);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
DeviceNameService.prototype.isDefault = function () {
|
||||
return this._isDefault;
|
||||
};
|
||||
|
||||
DeviceNameService.prototype.signalDeviceNameCanceled = function () {
|
||||
if (this._isDefault) {
|
||||
this._dispatchEvent("devicenamechange-cancel");
|
||||
}
|
||||
};
|
||||
|
||||
return DeviceNameService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new DeviceNameService();
|
||||
});
|
||||
98
gaia/distros/spark/apps/sharing/js/services/http_client_service.js
Executable file
98
gaia/distros/spark/apps/sharing/js/services/http_client_service.js
Executable file
|
|
@ -0,0 +1,98 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc", "app/js/models/peer", "app/js/services/apps_service", "app/js/services/url_service"], function (exports, _fxosMvcDistMvc, _appJsModelsPeer, _appJsServicesAppsService, _appJsServicesUrlService) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var Peer = _appJsModelsPeer["default"];
|
||||
var AppsService = _appJsServicesAppsService["default"];
|
||||
var UrlService = _appJsServicesUrlService["default"];
|
||||
|
||||
|
||||
var TIMEOUT = 2000;
|
||||
|
||||
var HttpClientService = (function (Service) {
|
||||
var HttpClientService = function HttpClientService() {
|
||||
Service.apply(this, arguments);
|
||||
};
|
||||
|
||||
_extends(HttpClientService, Service);
|
||||
|
||||
HttpClientService.prototype.downloadApp = function (app) {
|
||||
var _this = this;
|
||||
var url = UrlService.getAppDownloadUrl(app);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var xhr = new XMLHttpRequest({ mozAnon: true, mozSystem: true });
|
||||
xhr.open("GET", url);
|
||||
xhr.responseType = "blob";
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
AppsService.installAppBlob(xhr.response).then(resolve, reject);
|
||||
}
|
||||
};
|
||||
_this._xhrAttachErrorListeners(xhr, reject, app.peer);
|
||||
xhr.send();
|
||||
});
|
||||
};
|
||||
|
||||
HttpClientService.prototype.sendPeerInfo = function (fromPeer, toPeer) {
|
||||
var _this2 = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var url = UrlService.getPeerUrl(toPeer);
|
||||
var body = Peer.stringify(fromPeer);
|
||||
|
||||
var xhr = new XMLHttpRequest({ mozAnon: true, mozSystem: true });
|
||||
xhr.open("POST", url);
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
_this2._xhrAttachErrorListeners(xhr, reject, toPeer);
|
||||
xhr.send(body);
|
||||
});
|
||||
};
|
||||
|
||||
HttpClientService.prototype.signalDisconnecting = function (peer) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var xhr = new XMLHttpRequest({ mozAnon: true, mozSystem: true });
|
||||
xhr.open("GET", UrlService.getPeerDisconnectUrl(peer));
|
||||
xhr.send();
|
||||
});
|
||||
};
|
||||
|
||||
HttpClientService.prototype._xhrAttachErrorListeners = function (xhr, reject, peer) {
|
||||
var _this3 = this;
|
||||
xhr.timeout = TIMEOUT;
|
||||
xhr.ontimeout = function () {
|
||||
reject({ name: "Timeout" });
|
||||
_this3._dispatchEvent("disconnect", { peer: peer });
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
reject({ name: "Network error" });
|
||||
_this3._dispatchEvent("disconnect", { peer: peer });
|
||||
};
|
||||
xhr.addEventListener("load", function () {
|
||||
if (xhr.status !== 200) {
|
||||
reject({ name: "HTTP error", message: xhr.status });
|
||||
_this3._dispatchEvent("disconnect", { peer: peer });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return HttpClientService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new HttpClientService();
|
||||
});
|
||||
165
gaia/distros/spark/apps/sharing/js/services/http_server_service.js
Executable file
165
gaia/distros/spark/apps/sharing/js/services/http_server_service.js
Executable file
|
|
@ -0,0 +1,165 @@
|
|||
define(["exports", "fxos-web-server/dist/fxos-web-server", "fxos-mvc/dist/mvc", "app/js/models/app", "app/js/services/device_name_service", "app/js/services/share_service"], function (exports, _fxosWebServerDistFxosWebServer, _fxosMvcDistMvc, _appJsModelsApp, _appJsServicesDeviceNameService, _appJsServicesShareService) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var App = _appJsModelsApp["default"];
|
||||
var DeviceNameService = _appJsServicesDeviceNameService["default"];
|
||||
var ShareService = _appJsServicesShareService["default"];
|
||||
/*import P2pService from 'app/js/services/p2p_service';*/
|
||||
|
||||
var HttpServerService = (function (Service) {
|
||||
var HttpServerService = function HttpServerService() {
|
||||
var _this = this;
|
||||
Service.call(this);
|
||||
|
||||
this._cache = {};
|
||||
|
||||
window.addEventListener("beforeunload", this._deactivate.bind(this));
|
||||
|
||||
DeviceNameService.addEventListener("devicenamechange", function (e) {
|
||||
_this._deviceName = e.deviceName;
|
||||
}, true);
|
||||
|
||||
this._activate();
|
||||
};
|
||||
|
||||
_extends(HttpServerService, Service);
|
||||
|
||||
HttpServerService.prototype.clearPeerCache = function (peer) {
|
||||
delete this._cache[peer.address];
|
||||
};
|
||||
|
||||
HttpServerService.prototype._serverPeer = function (evt) {
|
||||
var response = evt.response;
|
||||
var request = evt.request;
|
||||
|
||||
var body = request.body;
|
||||
var data = JSON.parse(body);
|
||||
data.address = response.socket.host;
|
||||
if (this._cache[data.address] !== body) {
|
||||
this._cache[data.address] = body;
|
||||
// XXX/drs: We get "P2pService undefined" errors if we try using it
|
||||
// directly. I'm not sure why, but it's probably some kind of circular
|
||||
// reference issue. For now, this fixes it, but we should figure out why
|
||||
// we have to do this.
|
||||
window.p2pService.receivePeerInfo(data);
|
||||
}
|
||||
|
||||
response.send("");
|
||||
};
|
||||
|
||||
HttpServerService.prototype._getAppFromRequest = function (evt) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var request = evt.request;
|
||||
|
||||
var appId = decodeURIComponent(request.params.app || "");
|
||||
|
||||
ShareService.getApps().then(function (apps) {
|
||||
var app = App.getApp(apps, { manifestURL: appId });
|
||||
if (app) {
|
||||
resolve(app);
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
}, reject);
|
||||
});
|
||||
};
|
||||
|
||||
HttpServerService.prototype._serverManifest = function (evt) {
|
||||
var response = evt.response;
|
||||
|
||||
this._getAppFromRequest(evt).then(function (app) {
|
||||
response.headers["Content-Type"] = "application/x-web-app-manifest+json";
|
||||
var manifest = app.manifest;
|
||||
response.send(JSON.stringify(manifest));
|
||||
}, function () {
|
||||
return response.send("");
|
||||
});
|
||||
};
|
||||
|
||||
HttpServerService.prototype._serverDownload = function (evt) {
|
||||
var response = evt.response;
|
||||
|
||||
this._getAppFromRequest(evt).then(function (app) {
|
||||
app["export"]().then(function (blob) {
|
||||
response.headers["Content-Type"] = blob.type;
|
||||
response.sendFile(blob);
|
||||
});
|
||||
}, function () {
|
||||
return response.send("");
|
||||
});
|
||||
};
|
||||
|
||||
HttpServerService.prototype._serverDisconnect = function (evt) {
|
||||
var response = evt.response;
|
||||
|
||||
var peer = { address: response.socket.host };
|
||||
window.p2pService.receivePeerDisconnect(peer);
|
||||
|
||||
this.clearPeerCache(peer);
|
||||
|
||||
response.send("");
|
||||
};
|
||||
|
||||
HttpServerService.prototype._activate = function () {
|
||||
var _this2 = this;
|
||||
if (this.httpServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.httpServer = new HTTPServer(8080);
|
||||
this.httpServer.addEventListener("request", function (evt) {
|
||||
var request = evt.request;
|
||||
|
||||
var path = request.path;
|
||||
var routes = {
|
||||
"/manifest.webapp": function (evt) {
|
||||
return _this2._serverManifest(evt);
|
||||
},
|
||||
"/download": function (evt) {
|
||||
return _this2._serverDownload(evt);
|
||||
},
|
||||
"/disconnect": function (evt) {
|
||||
return _this2._serverDisconnect(evt);
|
||||
},
|
||||
"/peer": function (evt) {
|
||||
return _this2._serverPeer(evt);
|
||||
},
|
||||
"/": function (evt) {
|
||||
return evt.response.send("");
|
||||
}
|
||||
};
|
||||
var route = routes[path];
|
||||
if (route) {
|
||||
route(evt);
|
||||
}
|
||||
});
|
||||
this.httpServer.start();
|
||||
};
|
||||
|
||||
HttpServerService.prototype._deactivate = function () {
|
||||
if (!this.httpServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.httpServer.stop();
|
||||
this.httpServer = null;
|
||||
};
|
||||
|
||||
return HttpServerService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new HttpServerService();
|
||||
});
|
||||
62
gaia/distros/spark/apps/sharing/js/services/icon_service.js
Executable file
62
gaia/distros/spark/apps/sharing/js/services/icon_service.js
Executable file
|
|
@ -0,0 +1,62 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc"], function (exports, _fxosMvcDistMvc) {
|
||||
"use strict";
|
||||
|
||||
var _classProps = function (child, staticProps, instanceProps) {
|
||||
if (staticProps) Object.defineProperties(child, staticProps);
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
};
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
|
||||
|
||||
var singletonGuard = {};
|
||||
var instance;
|
||||
|
||||
/* jshint -W101 */
|
||||
var icons = ["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAANCAYAAAB2HjRBAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDowMTgwMTE3NDA3MjA2ODExOEM5RkVDOTQxRDNGQzczQSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpBQjI5NUNCQzZBQ0ExMUUxOTEwMkY4NzAyQjVDRTJERCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpBQjI5NUNCQjZBQ0ExMUUxOTEwMkY4NzAyQjVDRTJERCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1LjEgTWFjaW50b3NoIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NkY0OTRDMTgxNTIwNjgxMUIzNjVENjU0NThENUFEQkEiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6MDE4MDExNzQwNzIwNjgxMThDOUZFQzk0MUQzRkM3M0EiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5n+0vmAAAA40lEQVR42mL8KCbBAAWWQBwOxJxAvAaIdzMggDEQRwHxXyDeBMRHQIKMUM2ZQDwZiJmRNDQBcT0Q50DlkEExEPeBNIsCGQ+hNjJgUdSFZigI/AJiDRYg4YpDIwj04hBnA+JAJiAhx0AekABpfk2m5hcgP/MDGTdAJpGg8QsQq4Js/gjEQVABYgBM/QsmqMBxINaD0vjADiDWhqUBJiSJ+0BsBcRZQPwdTRMocZQBsScQP4UJMmExfToQm4OcBeWDDAoF4m50hUw4nHcZassvqMb12BSx4PHfBSC2BeJTuBQABBgAkf0rYAW2ug4AAAAASUVORK5CYII=", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAE1JREFUOE9jYACC/2QAkD6wxqamJpIxSB9ezfgMxqsZ3SforsOpGWYjWTYPnGaQ/5ABttggOrSx+X0QaiYUx7AwoU0KI5TewQFGSa4CAIp5nbtWcD+xAAAAAElFTkSuQmCC", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAATCAYAAAB2pebxAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHRJREFUeNrM1G0KwCAIBuCMzuqhvKz7AEcrNbdF7P1Z9oAZATOnr4ElCBGdBYgIrxABJBZkIi3gQSpSA/shWTOhDtGAak+FbogHeNCFRAALysrFDd9FW5PThExBSrR3r9X/tKOO+EmOEZuPLQqs+08i2QQYAIoIXFlI2XeyAAAAAElFTkSuQmCC", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAF9JREFUeNpiYKA34AfieiB+D8T/ofg9VIwfm+LzSArR8Xl0DSBT/r9//x6McWiqR9bwnggN7xmRNPwnxpNMpIYKsoYPRKj/wIzE4QBiBwIaOtAFSApW5ODFFnFgABBgADYiOslAa4FxAAAAAElFTkSuQmCC"];
|
||||
var IconService = (function (Service) {
|
||||
var IconService = function IconService(guard) {
|
||||
if (guard !== singletonGuard) {
|
||||
console.error("Cannot create singleton class");
|
||||
return;
|
||||
}
|
||||
|
||||
Service.call(this);
|
||||
};
|
||||
|
||||
_extends(IconService, Service);
|
||||
|
||||
_classProps(IconService, {
|
||||
instance: {
|
||||
get: function () {
|
||||
if (!instance) {
|
||||
instance = new this(singletonGuard);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
icons: {
|
||||
get: function () {
|
||||
return icons;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return IconService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = IconService;
|
||||
});
|
||||
267
gaia/distros/spark/apps/sharing/js/services/p2p_service.js
Executable file
267
gaia/distros/spark/apps/sharing/js/services/p2p_service.js
Executable file
|
|
@ -0,0 +1,267 @@
|
|||
define(["exports", "dns-sd.js/dist/dns-sd", "fxos-mvc/dist/mvc", "app/js/models/peer", "app/js/services/apps_service", "app/js/services/broadcast_service", "app/js/services/device_name_service", "app/js/services/http_client_service", "app/js/services/http_server_service", "app/js/services/share_service", "app/js/services/wifi_service"], function (exports, _dnsSdJsDistDnsSd, _fxosMvcDistMvc, _appJsModelsPeer, _appJsServicesAppsService, _appJsServicesBroadcastService, _appJsServicesDeviceNameService, _appJsServicesHttpClientService, _appJsServicesHttpServerService, _appJsServicesShareService, _appJsServicesWifiService) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var Peer = _appJsModelsPeer["default"];
|
||||
var AppsService = _appJsServicesAppsService["default"];
|
||||
var BroadcastService = _appJsServicesBroadcastService["default"];
|
||||
var DeviceNameService = _appJsServicesDeviceNameService["default"];
|
||||
var HttpClientService = _appJsServicesHttpClientService["default"];
|
||||
var HttpServerService = _appJsServicesHttpServerService["default"];
|
||||
var ShareService = _appJsServicesShareService["default"];
|
||||
var WifiService = _appJsServicesWifiService["default"];
|
||||
/*import IconService from 'app/js/services/icon_service';*/
|
||||
|
||||
var P2pService = (function (Service) {
|
||||
var P2pService = function P2pService() {
|
||||
var _this = this;
|
||||
Service.call(this);
|
||||
|
||||
window.p2pService = this;
|
||||
|
||||
this._peers = [];
|
||||
|
||||
this._ipAddresses = new Promise(function (resolve, reject) {
|
||||
IPUtils.getAddresses(function (ipAddress) {
|
||||
// XXX/drs: This will break if we have multiple IP addresses.
|
||||
resolve([ipAddress]);
|
||||
});
|
||||
});
|
||||
|
||||
this._enableP2pConnection();
|
||||
|
||||
window.addEventListener("visibilitychange", function () {
|
||||
return DNSSD.startDiscovery();
|
||||
});
|
||||
|
||||
window.addEventListener("beforeunload", function () {
|
||||
return _this._beforeUnload();
|
||||
});
|
||||
|
||||
AppsService.addEventListener("updated", function () {
|
||||
return _this.sendPeersInfo();
|
||||
});
|
||||
|
||||
DeviceNameService.addEventListener("devicenamechange", function () {
|
||||
return _this.sendPeersInfo();
|
||||
});
|
||||
|
||||
HttpClientService.addEventListener("disconnect", function (e) {
|
||||
return _this.receivePeerInfo({ address: e.peer.address });
|
||||
});
|
||||
|
||||
BroadcastService.addEventListener("broadcast", function () {
|
||||
return _this.sendPeersInfo();
|
||||
});
|
||||
|
||||
ShareService.addEventListener("share", function () {
|
||||
return _this.sendPeersInfo();
|
||||
});
|
||||
|
||||
WifiService.addEventListener("statuschange", function (status) {
|
||||
return _this._wifiStatusChange(status);
|
||||
});
|
||||
};
|
||||
|
||||
_extends(P2pService, Service);
|
||||
|
||||
P2pService.prototype.getApps = function () {
|
||||
if (!this._peers.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var reduceApps = function (el) {
|
||||
var apps = el && el.apps || [];
|
||||
return apps.map(function (app) {
|
||||
app.peer = el;
|
||||
return app;
|
||||
});
|
||||
};
|
||||
|
||||
if (this._peers.length === 1) {
|
||||
return reduceApps(this._peers[0]);
|
||||
}
|
||||
|
||||
return this._peers.reduce(function (prev, cur) {
|
||||
return reduceApps(prev).concat(reduceApps(cur));
|
||||
});
|
||||
};
|
||||
|
||||
P2pService.prototype.receivePeerInfo = function (peer) {
|
||||
var _this2 = this;
|
||||
for (var i = 0; i < this._peers.length; i++) {
|
||||
if (this._peers[i].address === peer.address) {
|
||||
if (peer.address && Object.keys(peer).length === 1) {
|
||||
HttpServerService.clearPeerCache(peer);
|
||||
this._peers.splice(i, 1);
|
||||
this._dispatchEvent("proximity");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._peers[i].session !== peer.session) {
|
||||
Peer.getMe().then(function (me) {
|
||||
return _this2._sendPeerInfo(me, peer);
|
||||
});
|
||||
}
|
||||
|
||||
this._peers[i] = peer;
|
||||
this._dispatchEvent("proximity");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._peers.push(peer);
|
||||
this._dispatchEvent("proximity");
|
||||
};
|
||||
|
||||
P2pService.prototype._sendPeerInfo = function (me, peer) {
|
||||
HttpClientService.sendPeerInfo(me, peer);
|
||||
};
|
||||
|
||||
P2pService.prototype.sendPeersInfo = function () {
|
||||
var _this3 = this;
|
||||
Peer.getMe().then(function (me) {
|
||||
return _this3._peers.forEach(function (peer) {
|
||||
return _this3._sendPeerInfo(me, peer);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
P2pService.prototype.receivePeerDisconnect = function (peer) {
|
||||
for (var i = 0; i < this._peers.length; i++) {
|
||||
if (this._peers[i].address === peer.address) {
|
||||
this._peers.splice(i, 1);
|
||||
this._dispatchEvent("proximity");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
P2pService.prototype._deletePeer = function (peer) {
|
||||
this.receivePeerInfo({ address: peer.address });
|
||||
};
|
||||
|
||||
P2pService.prototype._enableP2pConnection = function () {
|
||||
var _this4 = this;
|
||||
DNSSD.registerService("_fxos-sharing._tcp.local", 8080, {});
|
||||
|
||||
DNSSD.addEventListener("discovered", function (e) {
|
||||
var isSharingPeer = e.services.find(function (service) {
|
||||
return service === "_fxos-sharing._tcp.local";
|
||||
});
|
||||
|
||||
if (!isSharingPeer) {
|
||||
return;
|
||||
}
|
||||
|
||||
var address = e.address;
|
||||
|
||||
_this4._ipAddresses.then(function (ipAddresses) {
|
||||
// Make sure we're not trying to connect to ourself.
|
||||
if (ipAddresses.indexOf(address) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var peer = { address: address };
|
||||
|
||||
Peer.getMe().then(function (me) {
|
||||
_this4._sendPeerInfo(me, peer);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
DNSSD.startDiscovery();
|
||||
setInterval(function () {
|
||||
return DNSSD.startDiscovery();
|
||||
}, 30000 /* every 30 seconds */);
|
||||
setInterval(function () {
|
||||
return _this4.sendPeersInfo();
|
||||
}, 30000 /* every 30 seconds */);
|
||||
};
|
||||
|
||||
P2pService.prototype._beforeUnload = function () {
|
||||
this._peers.forEach(function (peer) {
|
||||
HttpClientService.signalDisconnecting(peer);
|
||||
});
|
||||
};
|
||||
|
||||
P2pService.prototype._wifiStatusChange = function (status) {
|
||||
if (status !== "connected") {
|
||||
this._peers = [];
|
||||
this._dispatchEvent("proximity");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug tool. Used only to insert fake data for testing.
|
||||
*/
|
||||
/*
|
||||
insertFakeData() {
|
||||
var icons = IconService.instance.icons;
|
||||
setTimeout(() => {
|
||||
this._updatePeerInfo('127.0.0.1', {name: '', apps: [{
|
||||
manifestURL: 'abc',
|
||||
icon: icons[0],
|
||||
manifest: {
|
||||
name: 'Sharing',
|
||||
description: 'doo',
|
||||
developer: {
|
||||
name: 'Dougiashdfihajksdhfkashdfkjhkasjhdfasdffd'
|
||||
}
|
||||
},
|
||||
}, {
|
||||
manifestURL: 'def',
|
||||
icon: icons[1],
|
||||
manifest: {
|
||||
name: 'HelloWorld',
|
||||
description: 'too',
|
||||
developer: {
|
||||
name: 'Hammasjdjkfhakshdfjkhaskjd'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
manifestURL: 'ghi',
|
||||
icon: icons[2],
|
||||
manifest: {
|
||||
name: 'Rail Rush',
|
||||
description: 'game',
|
||||
developer: {
|
||||
name: 'Gamer'
|
||||
}
|
||||
}
|
||||
}], addons: [{
|
||||
manifestURL: 'jkl',
|
||||
icon: icons[3],
|
||||
role: 'addon',
|
||||
manifest: {
|
||||
name: 'test',
|
||||
description: 'ham',
|
||||
developer: {
|
||||
name: 'abcabcacbasdasdasd'
|
||||
}
|
||||
}
|
||||
}]});
|
||||
}, 0);
|
||||
setTimeout(() => {
|
||||
this._updatePeerInfo('192.168.100.100', {name: 'garbage', apps: []});
|
||||
}, 2000);
|
||||
}
|
||||
*/
|
||||
;
|
||||
|
||||
return P2pService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new P2pService();
|
||||
});
|
||||
161
gaia/distros/spark/apps/sharing/js/services/share_service.js
Executable file
161
gaia/distros/spark/apps/sharing/js/services/share_service.js
Executable file
|
|
@ -0,0 +1,161 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc", "app/js/models/app", "app/js/services/apps_service", "app/js/services/broadcast_service"], function (exports, _fxosMvcDistMvc, _appJsModelsApp, _appJsServicesAppsService, _appJsServicesBroadcastService) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var App = _appJsModelsApp["default"];
|
||||
var AppsService = _appJsServicesAppsService["default"];
|
||||
var BroadcastService = _appJsServicesBroadcastService["default"];
|
||||
|
||||
|
||||
// Prune the database 60 seconds after opening the app.
|
||||
var PRUNE_TIMER = 60000;
|
||||
|
||||
var ShareService = (function (Service) {
|
||||
var ShareService = function ShareService() {
|
||||
var _this = this;
|
||||
Service.call(this);
|
||||
|
||||
this._shares = {};
|
||||
|
||||
this._initialized = new Promise(function (resolve, reject) {
|
||||
navigator.getDataStores("p2p_shares").then(function (stores) {
|
||||
_this._store = stores[0];
|
||||
_this._store.getLength().then(function (length) {
|
||||
if (!length) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
var cursor = _this._store.sync();
|
||||
_this._runNextTask(cursor, resolve, reject, function (id, data) {
|
||||
return _this._loadShare(id, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
return _this._pruneStore();
|
||||
}, PRUNE_TIMER);
|
||||
}).then(function () {
|
||||
return _this._dispatchEvent("share");
|
||||
});
|
||||
};
|
||||
|
||||
_extends(ShareService, Service);
|
||||
|
||||
ShareService.prototype.getApps = function (options) {
|
||||
var _this2 = this;
|
||||
options = options || {};
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
Promise.all([BroadcastService.getBroadcast(), AppsService.getApps(), _this2._initialized]).then(function (results) {
|
||||
var broadcast = results[0];
|
||||
if (!broadcast && !options.ignoreBroadcast) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
var apps = results[1];
|
||||
resolve(apps.filter(function (app) {
|
||||
return !!_this2._shares[app.manifestURL];
|
||||
}));
|
||||
}, reject);
|
||||
});
|
||||
};
|
||||
|
||||
ShareService.prototype.setAppShare = function (app, enable) {
|
||||
var _this3 = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (enable) {
|
||||
_this3._store.add(app.manifestURL).then(function (id) {
|
||||
_this3._loadShare(id, app.manifestURL);
|
||||
resolve();
|
||||
_this3._dispatchEvent("share");
|
||||
}, reject);
|
||||
} else {
|
||||
_this3._store.remove(_this3._shares[app.manifestURL]).then(function (success) {
|
||||
if (success) {
|
||||
delete _this3._shares[app.manifestURL];
|
||||
resolve();
|
||||
_this3._dispatchEvent("share");
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
}, reject);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
ShareService.prototype._runNextTask = function (cursor, resolve, reject, cb) {
|
||||
var _this4 = this;
|
||||
cursor.next().then(function (task) {
|
||||
return _this4._manageTask(cursor, task, resolve, reject, cb);
|
||||
});
|
||||
};
|
||||
|
||||
ShareService.prototype._manageTask = function (cursor, task, resolve, reject, cb) {
|
||||
switch (task.operation) {
|
||||
case "done":
|
||||
resolve();
|
||||
break;
|
||||
case "add":
|
||||
cb(task.id, task.data);
|
||||
/* falls through */
|
||||
default:
|
||||
this._runNextTask(cursor, resolve, reject, cb);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
ShareService.prototype._loadShare = function (id, manifestURL) {
|
||||
this._shares[manifestURL] = id;
|
||||
};
|
||||
|
||||
ShareService.prototype._pruneShare = function (id, data) {
|
||||
var _this5 = this;
|
||||
AppsService.getApps().then(function (apps) {
|
||||
var app = App.getApp(apps, { manifestURL: data });
|
||||
// If this app isn't installed, or has occurred multiple times in the
|
||||
// DataStore, delete it.
|
||||
if (!app || _this5._prunedShares[data]) {
|
||||
_this5._store.remove(id);
|
||||
}
|
||||
_this5._prunedShares[data] = id;
|
||||
});
|
||||
};
|
||||
|
||||
ShareService.prototype._pruneStore = function () {
|
||||
var _this6 = this;
|
||||
new Promise(function (resolve, reject) {
|
||||
_this6._initialized.then(function () {
|
||||
// Keep an array with all of the app instances that we've run into so
|
||||
// far, to determine uniqueness.
|
||||
_this6._prunedShares = {};
|
||||
var cursor = _this6._store.sync();
|
||||
_this6._runNextTask(cursor, resolve, reject, function (id, data) {
|
||||
return _this6._pruneShare(id, data);
|
||||
});
|
||||
});
|
||||
// Clear the array as it's no longer needed.
|
||||
}).then(function () {
|
||||
return delete _this6._prunedShares;
|
||||
});
|
||||
};
|
||||
|
||||
return ShareService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new ShareService();
|
||||
});
|
||||
50
gaia/distros/spark/apps/sharing/js/services/url_service.js
Executable file
50
gaia/distros/spark/apps/sharing/js/services/url_service.js
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc"], function (exports, _fxosMvcDistMvc) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var UrlService = (function (Service) {
|
||||
var UrlService = function UrlService() {
|
||||
Service.apply(this, arguments);
|
||||
};
|
||||
|
||||
_extends(UrlService, Service);
|
||||
|
||||
UrlService.getPeerUrl = function (peer) {
|
||||
return "http://" + peer.address + ":8080/peer";
|
||||
};
|
||||
|
||||
UrlService.getPeerPingUrl = function (peer) {
|
||||
return "http://" + peer.address + ":8080";
|
||||
};
|
||||
|
||||
UrlService.getPeerDisconnectUrl = function (peer) {
|
||||
return "http://" + peer.address + ":8080/disconnect";
|
||||
};
|
||||
|
||||
UrlService.getAppDownloadUrl = function (app) {
|
||||
var id = encodeURIComponent(app.manifestURL);
|
||||
return "http://" + app.peer.address + ":8080/download?app=" + id;
|
||||
};
|
||||
|
||||
UrlService.getAppManifestUrl = function (app) {
|
||||
var id = encodeURIComponent(app.manifestURL);
|
||||
return "http://" + app.peer.address + ":8080/manifest?app=" + id;
|
||||
};
|
||||
|
||||
return UrlService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = UrlService;
|
||||
});
|
||||
41
gaia/distros/spark/apps/sharing/js/services/wifi_service.js
Executable file
41
gaia/distros/spark/apps/sharing/js/services/wifi_service.js
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
define(["exports", "fxos-mvc/dist/mvc"], function (exports, _fxosMvcDistMvc) {
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Service = _fxosMvcDistMvc.Service;
|
||||
var WifiService = (function (Service) {
|
||||
var WifiService = function WifiService(options) {
|
||||
var _this = this;
|
||||
Service.call(this, options);
|
||||
|
||||
navigator.mozWifiManager.addEventListener("statuschange", function (e) {
|
||||
return _this._statusChange(e.status);
|
||||
});
|
||||
};
|
||||
|
||||
_extends(WifiService, Service);
|
||||
|
||||
WifiService.prototype.isConnected = function () {
|
||||
return navigator.mozWifiManager.connection.status === "connected";
|
||||
};
|
||||
|
||||
WifiService.prototype._statusChange = function (status) {
|
||||
this._dispatchEvent("statuschange", { status: status });
|
||||
};
|
||||
|
||||
return WifiService;
|
||||
})(Service);
|
||||
|
||||
exports["default"] = new WifiService();
|
||||
});
|
||||
Loading…
Reference in a new issue