Commit f1caf11c authored by Hardik Juneja's avatar Hardik Juneja Committed by hardikj

gadget_officejs: Add support for websocket

parent 637e2050
...@@ -11,19 +11,22 @@ ...@@ -11,19 +11,22 @@
<script src="handlebars.js"></script> <script src="handlebars.js"></script>
<script class="view-web-page-template" type="text/x-handlebars-template"> <script class="view-web-page-template" type="text/x-handlebars-template">
<form class="select-share-type">
<div class="center">
<div class="ui-field-contain">
<label data-i18n="Public Link:"> Public Link: </label>
<button type="submit" id="generatelink" name="generatelink" data-i18n="Jio Link" style="display: inline-block; width: 34%;"> Jio Link </button>
<button type="submit" id="generatelink1" name="generatelink1" data-i18n="Websocket Link" style="display: inline-block; width: 34%;"> Websocket Link </button>
<input type="text" id="sharelink" name="share" style="display:none" value=""/>
</div>
</div>
</form>
<form class="view-web-page-form"> <form class="view-web-page-form">
<div class="center"> <div class="center">
<div class="ui-field-contain"> <div class="ui-field-contain">
<label data-i18n="Title:">Title:</label> <label data-i18n="Title:">Title:</label>
<input type="text" name="title" value="{{title}}"> <input type="text" name="title" value="{{title}}">
</div> </div>
<div class="ui-field-contain">
<label data-i18n="Public Link:"> Public Link: </label>
<button type="submit" id="generatelink" name="generatelink" data-i18n="Generate Link" style="display:block;"> Generate Link </button>
<input type="text" id="sharelink" name="share" style="display:none" value=""/>
</div>
<button type="submit" data-i18n="Save" style="display:none;">Save</button> <button type="submit" data-i18n="Save" style="display:none;">Save</button>
</div> </div>
......
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.27768.8271.35532</string> </value> <value> <string>954.5706.38367.28381</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1471964256.18</float> <float>1474551059.28</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -28,6 +28,60 @@ ...@@ -28,6 +28,60 @@
return gadget.put(gadget.options.jio_key, doc); return gadget.put(gadget.options.jio_key, doc);
}); });
} }
function shareDoc (gadget, type) {
if(window.location.hash) {
var index = window.location.hash.indexOf('room=');
if (index === -1) {
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
var room = (S4()+S4()+"-"+S4()+S4());
return new RSVP.Queue()
.push(function () {
return gadget.declareGadget(
"gadget_officejs_page_share_text.html",
{
scope: "share_text_via_webrtc",
element: gadget.props.element.querySelector(".webrtc-gadget")
}
);
})
.push(function(g){
var config;
if (type === "jio") {
config = {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
"type": "dav",
"url": "https://softinst67513.host.vifib.net/share/",
"basic_login": btoa("admin:vowhkida")
}
}
};
} else {
config = {url: "ws://192.168.242.146:9999/"};
}
var sharelink = window.location.origin + window.location.pathname + '#page=webrtc_viewer&room='+room+'&type='+type+'&config='+encodeURIComponent(JSON.stringify(config));
gadget.props.element.querySelector('#sharelink').value = sharelink;
gadget.props.element.querySelector('#sharelink').style.display = 'block';
gadget.props.element.querySelector('#generatelink').remove();
gadget.props.element.querySelector('#generatelink1').remove();
if(config) {
return g.initiate(room, gadget, type, config);
} else {
throw new Error("Share config is missing");
}
})
}
}
}
function maximize(gadget) { function maximize(gadget) {
var iframe = gadget.props.element.querySelector('iframe'), var iframe = gadget.props.element.querySelector('iframe'),
...@@ -110,55 +164,6 @@ ...@@ -110,55 +164,6 @@
return gadget.props.deferred.resolve(); return gadget.props.deferred.resolve();
}); });
}) })
.declareMethod("shareDoc", function () {
var gadget = this;
if(window.location.hash) {
var index = window.location.hash.indexOf('room=');
if (index === -1) {
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
var room = (S4()+S4()+"-"+S4()+S4());
return new RSVP.Queue()
.push(function () {
return gadget.declareGadget(
"gadget_officejs_page_share_text.html",
{
scope: "share_text_via_webrtc",
element: gadget.props.element.querySelector(".webrtc-gadget")
}
);
})
.push(function(g){
var config = {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
//type: "indexeddb",
//"database": "handshake"
"type": "dav",
"url": "https://softinst67513.host.vifib.net/share/",
"basic_login": btoa("admin:vowhkida")
}
}
}
var sharelink = window.location.origin + window.location.pathname + '#page=webrtc_viewer&room='+room+'&config='+encodeURIComponent(JSON.stringify(config));
gadget.props.element.querySelector('#sharelink').value = sharelink;
gadget.props.element.querySelector('#sharelink').style.display = 'block';
gadget.props.element.querySelector('#generatelink').remove();
if(config) {
return g.initiate(room, gadget, config);
} else {
return g.initiate(room, gadget);
}
})
}
}
})
///////////////////////////////////////// /////////////////////////////////////////
// Render text content gadget // Render text content gadget
...@@ -208,19 +213,29 @@ ...@@ -208,19 +213,29 @@
.push(function () { .push(function () {
return gadget.props.deferred.promise; return gadget.props.deferred.promise;
}) })
.push(function () { .push(function () {
return loopEventListener( return RSVP.all([
gadget.props.element.querySelector('form'), loopEventListener(
'submit', gadget.props.element.querySelector('form.select-share-type'),
true, 'submit',
function (event) { true,
if (document.activeElement.name === "generatelink") { function (event) {
return gadget.shareDoc(); if (document.activeElement.name === "generatelink") {
} else { return shareDoc(gadget, "jio");
} else if (document.activeElement.name === "generatelink1") {
return shareDoc(gadget, "websocket");
}
}
),
loopEventListener(
gadget.props.element.querySelector('form.view-web-page-form'),
'submit',
true,
function (event) {
return saveContent(gadget, event); return saveContent(gadget, event);
} }
} )
); ]);
}); });
}); });
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.38231.58110.12526</string> </value> <value> <string>954.5702.26020.8277</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1472570624.98</float> <float>1474550862.46</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
</head> </head>
<body> <body>
<div class="gadget_webrtc_jio_bridge"></div> <div data-gadget-url="gadget_webrtc_jio_bridge.html"
data-gadget-scope="gadget_webrtc_jio_bridge.html"
data-gadget-sandbox="public"></div>
</body> </body>
</html> </html>
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.38184.65477.60859</string> </value> <value> <string>953.57026.12963.53469</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1472631749.27</float> <float>1473758929.92</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.29508.22380.37649</string> </value> <value> <string>954.5733.26518.27989</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1472047040.89</float> <float>1474552757.01</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -22,11 +22,9 @@ ...@@ -22,11 +22,9 @@
</div> </div>
<div class="ui-block-c"></div> <div class="ui-block-c"></div>
</div> </div>
<div class="gadget_websocket"> <div data-gadget-url="gadget_webrtc_jio_bridge.html"
<div data-gadget-url="gadget_websocket.html" data-gadget-scope="gadget_websocket.html"> data-gadget-scope="gadget_webrtc_jio_bridge.html"
</div> data-gadget-sandbox="public"></div>
</div>
<div class="gadget_webrtc_datachannel"></div>
</body> </body>
</html> </html>
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>romain</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>945.33680.60468.51660</string> </value> <value> <string>953.42397.2191.24098</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,8 +268,8 @@ ...@@ -268,8 +268,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1441358472.38</float> <float>1474364886.77</float>
<string>GMT</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
...@@ -17,13 +17,28 @@ ...@@ -17,13 +17,28 @@
}); });
} }
function declareSubGadget(gadget, url) {
var container_element = gadget.state_parameter_dict.element.querySelector("." + url.split(".")[0]),
element = document.createElement("div");
container_element.innerHTML = "";
container_element.appendChild(element);
return gadget.declareGadget(url, {
element: element,
scope: url,
sandbox: "public"
});
}
function getWebRTCScopeList(gadget) { function getWebRTCScopeList(gadget) {
var result_list = [], var result_list = [],
element_list = gadget.state_parameter_dict.element.querySelector(".gadget_webrtc_datachannel") element_list = gadget.state_parameter_dict.element.querySelector(".gadget_webrtc")
.childNodes, .childNodes,
i; i;
for (i = 0; i < element_list.length; i += 1) { for (i = 0; i < element_list.length; i += 1) {
result_list.push(element_list[i].getAttribute("data-gadget-scope")); if (element_list[i].getAttribute) {
result_list.push(element_list[i].getAttribute("data-gadget-scope"));
}
} }
return result_list; return result_list;
} }
...@@ -40,7 +55,7 @@ ...@@ -40,7 +55,7 @@
} }
function sendWebRTC(gadget, rtc_gadget, scope, message) { function sendWebRTC(gadget, rtc_gadget, scope, message) {
return rtc_gadget.send(message) return rtc_gadget.send(message, "webrtc"+gadget.state_parameter_dict.counter)
.push(undefined, function (error) { .push(undefined, function (error) {
if ((error instanceof DOMException) && (error.name === 'InvalidStateError')) { if ((error instanceof DOMException) && (error.name === 'InvalidStateError')) {
return dropSubGadget(gadget, scope) return dropSubGadget(gadget, scope)
...@@ -114,96 +129,70 @@ ...@@ -114,96 +129,70 @@
})); }));
}); });
}) })
/*
.allowPublicAcquisition("notifyWebSocketClosed", function () { .declareMethod("onOffer", function (options, offer) {
if (this.state_parameter_dict.user_type !== "user") { var gadget = this;
throw new Error("Unexpected Web Socket connection close"); gadget.state_parameter_dict.counter += 1;
} return new RSVP.Queue()
}) .push(function(response) {
*/ gadget.connecting = true;
.allowPublicAcquisition("notifyWebSocketMessage", function (argument_list) {
var json = JSON.parse(argument_list[0]), // https://github.com/diafygi/webrtc-ips
scope, var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/,
rtc_gadget, ip_list = [],
socket_gadget, ip_dict = {},
gadget = this; ip_addr,
line_list = JSON.parse(offer.data).sdp.split('\n'),
if (json.action === "offer") { i;
// XXX https://github.com/diafygi/webrtc-ips
return gadget.getDeclaredGadget("gadget_websocket.html") for (i = 0; i < line_list.length; i += 1) {
.push(function (gg) { if (line_list[i].indexOf('a=candidate:') === 0) {
gadget.state_parameter_dict.connecting = true; ip_addr = ip_regex.exec(line_list[i])[1];
gadget.state_parameter_dict.counter += 1; if (!ip_addr.match(/^[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}$/)) {
socket_gadget = gg; // Hide ipv6
var new_element = document.createElement("div"); if (!ip_dict[ip_addr]) {
gadget.state_parameter_dict.element.querySelector(".gadget_webrtc_datachannel").appendChild(new_element); ip_list.push(ip_addr);
scope = "webrtc" + gadget.state_parameter_dict.counter; ip_dict[ip_addr] = true;
return gadget.declareGadget("gadget_webrtc_datachannel.html", {
scope: scope,
element: new_element
});
})
.push(function (gg) {
rtc_gadget = gg;
// https://github.com/diafygi/webrtc-ips
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/,
ip_list = [],
ip_dict = {},
ip_addr,
line_list = JSON.parse(json.data).sdp.split('\n'),
i;
for (i = 0; i < line_list.length; i += 1) {
if (line_list[i].indexOf('a=candidate:') === 0) {
ip_addr = ip_regex.exec(line_list[i])[1];
if (!ip_addr.match(/^[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}$/)) {
// Hide ipv6
if (!ip_dict[ip_addr]) {
ip_list.push(ip_addr);
ip_dict[ip_addr] = true;
}
}
} }
} }
gadget.state_parameter_dict.scope_ip[scope] = ip_list; }
return rtc_gadget.createAnswer(json.from, json.data); }
})
.push(function (local_connection) { gadget.state_parameter_dict.scope_ip["webrtc"+gadget.state_parameter_dict.counter] = ip_list
return socket_gadget.send(JSON.stringify({to: json.from, action: "answer", data: local_connection})); options.to = offer.from;
}) return;
.push(function () { })
return RSVP.any([
RSVP.Queue()
.push(function () {
return RSVP.delay(10000);
})
.push(function () {
console.info('-- webrtc client disappears...');
return dropSubGadget(gadget, scope);
}),
rtc_gadget.waitForConnection()
]);
})
.push(function () {
gadget.state_parameter_dict.connecting = false;
return updateInfo(gadget);
});
}
}) })
.declareMethod('postConnection', function(options, offer) {
var gadget = this;
.declareService(function () { return new RSVP.Queue()
var sgadget, .push(function () {
gadget = this; gadget.state_parameter_dict.connecting = false;
return this.getDeclaredGadget('gadget_websocket.html') return updateInfo(gadget);
.push(function (socket_gadget) { });
sgadget = socket_gadget; })
return socket_gadget.createSocket("ws://127.0.0.1:9999/");
}) .declareMethod('initiate', function (roomid) {
.push(function () { var gadget = this,
// Wait for the gadget to be dropped from the page options = {
// and close the socket/rtc connections peerid: "master",
return RSVP.defer().promise; roomid: "/"+roomid+"/",
}) type: "websocket",
.push(undefined, function (error) { config: {'url': "ws://127.0.0.1:9999/"},
listner: true,
preConnection: gadget.onOffer.bind(gadget),
postConnection: gadget.postConnection.bind(gadget),
};
return gadget.getDeclaredGadget("gadget_webrtc_jio_bridge.html")
.push(function (rtc_gadget) {
options.rtc_gadget = rtc_gadget;
return rtc_gadget.connect(options);
});
/*.push(undefined, function (error) {
if (sgadget === undefined) { if (sgadget === undefined) {
return; return;
} }
...@@ -228,7 +217,7 @@ ...@@ -228,7 +217,7 @@
.push(function () { .push(function () {
throw error; throw error;
}); });
}); }); */
}); });
}(window, rJS, document, RSVP, console, DOMException)); }(window, rJS, document, RSVP, console, DOMException));
\ No newline at end of file
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>romain</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>945.33680.49983.21452</string> </value> <value> <string>954.5724.21109.37529</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,8 +260,8 @@ ...@@ -260,8 +260,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1441358513.14</float> <float>1474552150.73</float>
<string>GMT</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
...@@ -271,7 +271,7 @@ ...@@ -271,7 +271,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.35402.46528.58316</string> </value> <value> <string>953.57025.36062.60552</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -289,7 +289,7 @@ ...@@ -289,7 +289,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1472400667.43</float> <float>1473698013.89</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
}) })
.push(function(g){ .push(function(g){
if(gadget.props.options['config']) { if(gadget.props.options['config']) {
return g.slaveInitiate(room, gadget, gadget.props.options['config']); return g.slaveInitiate(room, gadget, gadget.props.options['type'], gadget.props.options['config']);
} else { } else {
return g.slaveInitiate(room, gadget) return g.slaveInitiate(room, gadget)
.push(null, function(error){ .push(null, function(error){
......
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.38233.8749.16844</string> </value> <value> <string>954.5557.49354.23227</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -285,7 +285,7 @@ ...@@ -285,7 +285,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1472570633.51</float> <float>1474542105.73</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
data-gadget-scope="jio_gadget" data-gadget-scope="jio_gadget"
data-gadget-sandbox="public"></div> data-gadget-sandbox="public"></div>
<div class="gadget_websocket"></div> <div data-gadget-url="gadget_webrtc_jio_bridge.html"
<div class="gadget_webrtc_datachannel"></div> data-gadget-scope="gadget_webrtc_jio_bridge.html"
data-gadget-sandbox="public"></div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -218,7 +218,7 @@ ...@@ -218,7 +218,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>romain</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>945.32246.38846.38144</string> </value> <value> <string>954.2812.41384.46984</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -250,8 +250,8 @@ ...@@ -250,8 +250,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1441283008.98</float> <float>1474377398.17</float>
<string>GMT</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"use strict"; "use strict";
var timeout = 60000, var timeout = 60000,
websocket_timeout = 5000; websocket_timeout = 500000;
function S4() { function S4() {
return ('0000' + Math.floor( return ('0000' + Math.floor(
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
if (!gadget.state_parameter_dict.jio_created) { if (!gadget.state_parameter_dict.jio_created) {
return gadget.redirect({page: 'setting'}); return gadget.redirect({page: 'setting'});
} }
return gadget.getDeclaredGadget('gadget_webrtc_datachannel.html') return gadget.getDeclaredGadget("gadget_webrtc_jio_bridge.html")
.push(function (rtc_gadget) { .push(function (rtc_gadget) {
gadget.state_parameter_dict.message_count += 1; gadget.state_parameter_dict.message_count += 1;
gadget.state_parameter_dict.message_dict[gadget.state_parameter_dict.message_count] = RSVP.defer(); gadget.state_parameter_dict.message_dict[gadget.state_parameter_dict.message_count] = RSVP.defer();
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
type: "jio_query", type: "jio_query",
method_name: method_name, method_name: method_name,
argument_list: Array.prototype.slice.call(argument_list) argument_list: Array.prototype.slice.call(argument_list)
})), }), 'webrtc0'),
RSVP.any([ RSVP.any([
RSVP.timeout(timeout), RSVP.timeout(timeout),
gadget.state_parameter_dict.message_dict[gadget.state_parameter_dict.message_count].promise gadget.state_parameter_dict.message_dict[gadget.state_parameter_dict.message_count].promise
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
.push(function (result_list) { .push(function (result_list) {
return result_list[1]; return result_list[1];
}); });
} }
function declareSubGadget(gadget, url) { function declareSubGadget(gadget, url) {
...@@ -105,58 +104,41 @@ ...@@ -105,58 +104,41 @@
.declareMethod('createJio', function (options) { .declareMethod('createJio', function (options) {
var context = this, var context = this,
socket_gadget, rtc_gadget,
rtc_gadget; rtc_options = {
type: "websocket",
roomid: "/ok/",
config: {url : options.socket_url},
initiator: true,
to: 'master'
};
//if ((options === undefined) || (options.socket_url === undefined)) {
// return context.redirect({page: 'setting'});
//}
if ((options === undefined) || (options.socket_url === undefined)) {
return context.redirect({page: 'setting'});
}
context.state_parameter_dict.jio_created = true; context.state_parameter_dict.jio_created = true;
return declareSubGadget(context, 'gadget_websocket.html') context.state_parameter_dict.uuid = UUID();
.push(function (gadget) { context.state_parameter_dict.answer_defer = RSVP.defer();
socket_gadget = gadget; context.state_parameter_dict.message_count = 0;
context.state_parameter_dict.message_dict = {};
context.state_parameter_dict.uuid = UUID(); // Send offer and expect answer in less than XXXms (arbitrary value...)
context.state_parameter_dict.answer_defer = RSVP.defer(); return RSVP.any([
context.state_parameter_dict.message_count = 0; RSVP.Queue()
context.state_parameter_dict.message_dict = {}; .push(function () {
// Send offer and expect answer in less than XXXms (arbitrary value...) return RSVP.timeout(websocket_timeout);
return RSVP.any([ })
RSVP.Queue() .push(undefined, function () {
.push(function () { //return context.redirect({page: 'setting'});
return RSVP.timeout(websocket_timeout); // throw new Error("No remote WebRTC connection available");
}) }),
.push(undefined, function () { context.getDeclaredGadget("gadget_webrtc_jio_bridge.html")
return context.redirect({page: 'setting'}); .push(function (rtc_gadget) {
// throw new Error("No remote WebRTC connection available"); rtc_options.peerid = context.state_parameter_dict.uuid;
}),
declareSubGadget(context, 'gadget_websocket.html') return rtc_gadget.connect(rtc_options);
.push(function (gadget) { })
socket_gadget = gadget; ]);
// XXX Drop hardcoded URL
return socket_gadget.createSocket(options.socket_url);
})
.push(function () {
return declareSubGadget(context, 'gadget_webrtc_datachannel.html');
})
.push(function (gadget) {
rtc_gadget = gadget;
return rtc_gadget.createOffer(context.state_parameter_dict.uuid);
})
.push(function (description) {
return RSVP.all([
socket_gadget.send(JSON.stringify({from: context.state_parameter_dict.uuid, action: "offer", data: description})),
context.state_parameter_dict.answer_defer.promise
]);
})
.push(function (response_list) {
return rtc_gadget.registerAnswer(response_list[1]);
})
.push(function () {
return socket_gadget.close();
})
]);
});
}) })
.declareMethod('allDocs', function () { .declareMethod('allDocs', function () {
return wrapJioAccess(this, 'allDocs', arguments); return wrapJioAccess(this, 'allDocs', arguments);
......
...@@ -216,7 +216,7 @@ ...@@ -216,7 +216,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>romain</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>945.39449.60302.38024</string> </value> <value> <string>954.5720.33596.8260</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,8 +248,8 @@ ...@@ -248,8 +248,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1441715721.23</float> <float>1474551874.29</float>
<string>GMT</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment