Commit 5f6e57a8 authored by Hardik Juneja's avatar Hardik Juneja

erp5_webrtc_gadget: update webrtc module to support erp5 as a handshake option

parent e888d233
...@@ -45,14 +45,22 @@ ...@@ -45,14 +45,22 @@
g.props = {}; g.props = {};
}) })
.declareMethod('create_room', function(roomid) { .declareMethod('create_room', function(roomid, type) {
var gadget = this; var gadget = this;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.getDeclaredGadget("jio_gadget"); return gadget.getDeclaredGadget("jio_gadget");
}) })
.push(function (jio_gadget) { .push(function (jio_gadget) {
if (type === "erp5") {
return jio_gadget.post({
title: roomid,
portal_type: "Webrtc Room",
parent_relative_url: "webrtc_rooms_module"
});
} else {
return jio_gadget.put(roomid, {}); return jio_gadget.put(roomid, {});
}
}) })
.push(null, function(e){ .push(null, function(e){
console.log(e); console.log(e);
...@@ -60,19 +68,29 @@ ...@@ -60,19 +68,29 @@
}) })
.declareMethod('register', function(roomid, peerid, config) { .declareMethod('register', function(roomid, peerid, config) {
var gadget = this; var gadget = this,
id;
gadget.props.config = config;
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function() {
return createJio(gadget, config); return createJio(gadget, config);
}) })
.push(function() { .push(function() {
return gadget.create_room(roomid); return gadget.create_room(roomid, config.type);
}) })
.push(function () { .push(function (id) {
gadget.erp5_roomid = id;
return gadget.getDeclaredGadget("jio_gadget"); return gadget.getDeclaredGadget("jio_gadget");
}) })
.push(function (jio_gadget) { .push(function (jio_gadget) {
if (config.type === "erp5") {
var url = config.url + "/" + gadget.erp5_roomid + "/WebrtcRoom_storeOfferAnswer";
return jio_gadget.putAttachment(gadget.erp5_roomid,
url,
new Blob([JSON.stringify({roomid:roomid,
peerid: peerid,
data:'1'})]));
}
return jio_gadget.putAttachment(roomid, peerid, ''); return jio_gadget.putAttachment(roomid, peerid, '');
}); });
// TODO: create new function, show registered peers? // TODO: create new function, show registered peers?
...@@ -86,8 +104,27 @@ ...@@ -86,8 +104,27 @@
return gadget.getDeclaredGadget("jio_gadget"); return gadget.getDeclaredGadget("jio_gadget");
}) })
.push(function (jio_gadget) { .push(function (jio_gadget) {
return jio_gadget.putAttachment(roomid, options.name, options.data); if (gadget.props.config.type === "erp5") {
var url = gadget.props.config.url + "/" + gadget.erp5_roomid +
"/WebrtcRoom_storeOfferAnswer";
return new RSVP.Queue()
.push(function () {
if (options.data instanceof Blob) {
return jIO.util.readBlobAsText(options.data);
} else {
return {target:{result:options.data}};
}
}) })
.push(function (evt) {
return jio_gadget.putAttachment(gadget.erp5_roomid,
url,
new Blob([JSON.stringify({roomid:roomid,
peerid: options.name,
data: evt.target.result})]));
});
}
return jio_gadget.putAttachment(roomid, options.name, options.data);
});
}) })
.declareMethod('get_answer', function (roomid, attachment) { .declareMethod('get_answer', function (roomid, attachment) {
...@@ -98,6 +135,11 @@ ...@@ -98,6 +135,11 @@
return gadget.getDeclaredGadget("jio_gadget"); return gadget.getDeclaredGadget("jio_gadget");
}) })
.push(function (jio_gadget) { .push(function (jio_gadget) {
if (gadget.props.config.type === "erp5") {
var url = gadget.props.config.url + "/" + gadget.erp5_roomid +
"/WebrtcRoom_getOfferAnswer?roomid=" + roomid+"&name="+attachment;
return jio_gadget.getAttachment(gadget.erp5_roomid, url);
}
return jio_gadget.getAttachment(roomid, attachment); return jio_gadget.getAttachment(roomid, attachment);
}); });
}) })
...@@ -110,6 +152,23 @@ ...@@ -110,6 +152,23 @@
return gadget.getDeclaredGadget("jio_gadget"); return gadget.getDeclaredGadget("jio_gadget");
}) })
.push(function (jio_gadget) { .push(function (jio_gadget) {
if (gadget.props.config.type === "erp5") {
var url = gadget.props.config.url + "/" + gadget.erp5_roomid +
"/WebrtcRoom_getAllOfferAnswer?roomid="+roomid;
return jio_gadget.getAttachment(gadget.erp5_roomid, url)
.push(function(res) {
return jIO.util.readBlobAsText(res);
})
.push(function(evt) {
var res = evt.target.result.replace(/'/g, '"');
res = JSON.parse(res);
var offers = {}
for (var i in res) {
offers[res[i]] = '';
}
return offers;
});
}
return jio_gadget.allAttachments(roomid); return jio_gadget.allAttachments(roomid);
}); });
}) })
...@@ -184,6 +243,11 @@ ...@@ -184,6 +243,11 @@
return gadget.getDeclaredGadget("jio_gadget"); return gadget.getDeclaredGadget("jio_gadget");
}) })
.push(function (jio_gadget) { .push(function (jio_gadget) {
if (gadget.props.config.type === "erp5") {
var url = gadget.props.config.url + "/" + gadget.erp5_roomid +
"/WebrtcRoom_deleteOfferAnswer?roomid="+roomid+"&name="+peerid+"_"+to;
return jio_gadget.getAttachment(gadget.erp5_roomid, url);
}
return jio_gadget.removeAttachment(roomid, peerid+"_"+to); return jio_gadget.removeAttachment(roomid, peerid+"_"+to);
}); });
}); });
......
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>954.14301.62370.56661</string> </value> <value> <string>954.35891.65212.64409</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1475066759.35</float> <float>1476275774.45</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>954.14300.3742.31044</string> </value> <value> <string>954.35841.9537.7133</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1475066648.69</float> <float>1476272709.15</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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