Commit 6ee093ae authored by Eugene Shen's avatar Eugene Shen

Synchronize text posts across Dropbox and WebDAV

Allow users to configure storage synchronization options during login,
with the choice of ERP5, Dropbox, WebDAV, or no remote storage.
Remove gadget_erp5_chat_login by merging it with the main page.
Use mapping storage and remove peer_source from messages.
parent f5c87f9c
...@@ -11,6 +11,9 @@ img { ...@@ -11,6 +11,9 @@ img {
max-width: 100%; max-width: 100%;
max-height: 100%; max-height: 100%;
} }
input[type="text"] {
width: 360px;
}
.chat { .chat {
border: 1px solid; border: 1px solid;
width: 680px; width: 680px;
......
...@@ -6,16 +6,69 @@ ...@@ -6,16 +6,69 @@
<title>OfficeJS Chat</title> <title>OfficeJS Chat</title>
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="gadget_global.js" ></script>
<script src="gadget_erp5_chat.js"></script> <script src="gadget_erp5_chat.js"></script>
<link rel="stylesheet" href="gadget_erp5_chat.css"> <link rel="stylesheet" href="gadget_erp5_chat.css" />
</head> </head>
<body> <body>
<h1>OfficeJS Chat</h1> <h1>OfficeJS Chat</h1>
<div data-gadget-url="gadget_jio.html"
data-gadget-scope="storage_gadget" <form class="login-form">
data-gadget-sandbox="public"></div> <label>Name:</label>
<div data-gadget-url="gadget_erp5_chat_login.html" <br />
data-gadget-scope="login_gadget" <input type="text" name="name" required="required" />
data-gadget-sandbox="public"></div> <br />
<label>Folder:</label>
<br />
<input type="text" name="folder" required="required" />
<br />
<label>Room:</label>
<br />
<input type="text" name="room" required="required" />
<br />
<label>Role:</label>
<br />
<input type="radio" name="role" value="host" required="required" />
<label>Host</label>
<br />
<input type="radio" name="role" value="guest" checked="checked" />
<label>Guest</label>
<br />
<label>Remote Storage:</label>
<br />
<input type="radio" name="remote" value="erp5" required="required" />
<label>ERP5</label>
<br />
<input type="radio" name="remote" value="dav" required="required" />
<label>DAV Storage</label>
<br />
<input type="radio" name="remote" value="dropbox" required="required" />
<label>Dropbox</label>
<br />
<input type="radio" name="remote" value="local" checked="checked" />
<label>Local is Enough</label>
<br />
<a href="https://www.dropbox.com/1/oauth2/authorize?client_id=igeiyv4pkt0y0mm&response_type=token&redirect_uri=https://softinst75770.host.vifib.net/erp5/web_site_module/web_chat/">
Log in to Dropbox first, if you wish to use Dropbox.
</a>
<br />
<label>Fill out ERP5 URL first, if you wish to use ERP5.</label>
<br />
<input type="text" name="erp5_url" value="https://softinst75770.host.vifib.net/erp5/web_site_module/" />
<br />
<label>Enter WebDAV parameters first, if you wish to use DAV.</label>
<br />
<label>URL: </label>
<input type="text" name="dav_url" value="https://softinst75722.host.vifib.net/share" />
<br />
<label>Username: </label>
<input type="text" name="dav_user" value="eyqs" />
<br />
<label>Password: </label>
<input type="text" name="dav_pass" value="Aoeuidhtns" />
<br />
<input type="submit" value="Login!" />
</form>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
<value> <value>
<tuple> <tuple>
<string>classification/collaborative/team</string> <string>classification/collaborative/team</string>
<string>contributor/person_module/1</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
(function (window, rJS, RSVP) { (function (window, document, loopEventListener, rJS, RSVP) {
function cleanId(input_id) {
var reserved = ["_", "&", "=", ",", ";"];
for (var i = 0, i_len = reserved.length; i < i_len; i++) {
input_id = input_id.replace(reserved[i], "-");
}
return input_id;
}
function getQueryValue(query, value) {
if (document.URL.indexOf(query + "=") != -1) {
var start = document.URL.indexOf(query + "=") + query.length + 1;
var end = document.URL.indexOf("&", start);
if (end === -1) {
end = document.URL.length;
}
return decodeURIComponent(document.URL.slice(start, end));
} else {
return value || "";
}
}
function login(my_gadget) {
return new RSVP.Queue()
.push(function () {
return my_gadget.declareGadget(
"gadget_erp5_chat_webrtc.html", {scope: "webrtc_gadget"}
);
})
.push(function (webrtc_gadget) {
var form = my_gadget.state_parameter_dict.element
.querySelector(".login-form").elements;
webrtc_gadget.state_parameter_dict.name = cleanId(form.name.value);
webrtc_gadget.state_parameter_dict.folder = cleanId(form.folder.value);
webrtc_gadget.state_parameter_dict.room = cleanId(form.room.value);
webrtc_gadget.state_parameter_dict.role = form.role.value;
webrtc_gadget.state_parameter_dict.remote = form.remote.value;
webrtc_gadget.state_parameter_dict.auth = getQueryValue("auth");
webrtc_gadget.state_parameter_dict.erp5_url = form.erp5_url.value;
webrtc_gadget.state_parameter_dict.dav_url = form.dav_url.value;
webrtc_gadget.state_parameter_dict.dav_user = form.dav_user.value;
webrtc_gadget.state_parameter_dict.dav_pass = form.dav_pass.value;
var element = my_gadget.state_parameter_dict.element;
while (element.firstChild) {
element.removeChild(element.firstChild);
}
element.appendChild(webrtc_gadget.state_parameter_dict.element);
return webrtc_gadget.render();
});
}
rJS(window) rJS(window)
.ready(function (gadget) { .ready(function (gadget) {
...@@ -6,53 +56,43 @@ ...@@ -6,53 +56,43 @@
return gadget.getElement() return gadget.getElement()
.push(function (element) { .push(function (element) {
gadget.state_parameter_dict.element = element; gadget.state_parameter_dict.element = element;
fields = gadget.state_parameter_dict.element
.querySelector(".login-form").elements;
fields.folder.value = getQueryValue("folder");
fields.room.value = getQueryValue("room");
fields.name.value = getQueryValue("name");
fields.erp5_url.value = getQueryValue(
"erp5_url", fields.erp5_url.value);
fields.dav_url.value = getQueryValue(
"dav_url", fields.dav_url.value);
fields.dav_user.value = getQueryValue(
"dav_user", fields.dav_user.value);
fields.dav_pass.value = getQueryValue(
"dav_pass", fields.dav_pass.value);
var role = getQueryValue("role");
if (role === "host" || role === "guest") {
fields.role.value = role;
}
var remote = getQueryValue("remote");
if (remote === "dav" || remote === "dropbox"
|| remote === "erp5" || remote === "local") {
fields.remote.value = remote;
}
if (getQueryValue("submit")) {
return login(gadget);
}
}); });
}) })
.ready(function (gadget) {
return new RSVP.Queue() .declareMethod('render', function () {})
.push(function () {
return gadget.getDeclaredGadget("storage_gadget");
})
.push(function (my_gadget) {
return my_gadget.createJio({
type: "replicate",
query: {
query: 'portal_type: "Text Post"',
limit: [0, 1000000000]
},
local_sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "officejs_chat"
}
}
},
remote_sub_storage: {
type: "erp5",
url: "https://softinst75770.host.vifib.net/erp5/web_site_module/web_chat/hateoas/",
default_view_reference: "view"
},
conflict_handling: 2,
use_remote_post: true
});
});
})
.allowPublicAcquisition('jioApply', function (param_list) { .declareService(function () {
var gadget = this; var gadget = this;
return new RSVP.Queue() return loopEventListener(
.push(function () { gadget.state_parameter_dict.element, "submit", false, function () {
return gadget.getDeclaredGadget("storage_gadget"); return login(gadget);
}) }
.push(function (jio_gadget) { );
return jio_gadget[param_list[0]] });
.apply(jio_gadget, param_list.slice(1));
});
})
.declareMethod('render', function () {});
}(window, rJS, RSVP)); }(window, document, loopEventListener, rJS, RSVP));
\ No newline at end of file \ No newline at end of file
...@@ -10,11 +10,9 @@ ...@@ -10,11 +10,9 @@
<key> <string>_Access_contents_information_Permission</string> </key> <key> <string>_Access_contents_information_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Anonymous</string>
<string>Assignee</string> <string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Associate</string> <string>Associate</string>
<string>Auditor</string>
<string>Manager</string> <string>Manager</string>
<string>Owner</string> <string>Owner</string>
</tuple> </tuple>
...@@ -24,7 +22,6 @@ ...@@ -24,7 +22,6 @@
<key> <string>_Add_portal_content_Permission</string> </key> <key> <string>_Add_portal_content_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Manager</string> <string>Manager</string>
</tuple> </tuple>
...@@ -43,8 +40,6 @@ ...@@ -43,8 +40,6 @@
<key> <string>_Modify_portal_content_Permission</string> </key> <key> <string>_Modify_portal_content_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string> <string>Manager</string>
</tuple> </tuple>
</value> </value>
...@@ -53,11 +48,9 @@ ...@@ -53,11 +48,9 @@
<key> <string>_View_Permission</string> </key> <key> <string>_View_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Anonymous</string>
<string>Assignee</string> <string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Associate</string> <string>Associate</string>
<string>Auditor</string>
<string>Manager</string> <string>Manager</string>
<string>Owner</string> <string>Owner</string>
</tuple> </tuple>
......
...@@ -10,11 +10,9 @@ ...@@ -10,11 +10,9 @@
<key> <string>_Access_contents_information_Permission</string> </key> <key> <string>_Access_contents_information_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Anonymous</string>
<string>Assignee</string> <string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Associate</string> <string>Associate</string>
<string>Auditor</string>
<string>Manager</string> <string>Manager</string>
<string>Owner</string> <string>Owner</string>
</tuple> </tuple>
...@@ -24,7 +22,6 @@ ...@@ -24,7 +22,6 @@
<key> <string>_Add_portal_content_Permission</string> </key> <key> <string>_Add_portal_content_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Manager</string> <string>Manager</string>
</tuple> </tuple>
...@@ -43,8 +40,6 @@ ...@@ -43,8 +40,6 @@
<key> <string>_Modify_portal_content_Permission</string> </key> <key> <string>_Modify_portal_content_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string> <string>Manager</string>
</tuple> </tuple>
</value> </value>
...@@ -53,11 +48,9 @@ ...@@ -53,11 +48,9 @@
<key> <string>_View_Permission</string> </key> <key> <string>_View_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Anonymous</string>
<string>Assignee</string> <string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Associate</string> <string>Associate</string>
<string>Auditor</string>
<string>Manager</string> <string>Manager</string>
<string>Owner</string> <string>Owner</string>
</tuple> </tuple>
......
...@@ -6,11 +6,17 @@ ...@@ -6,11 +6,17 @@
<title>OfficeJS Chat</title> <title>OfficeJS Chat</title>
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="jiodev.js"></script>
<script src="jio_mappingstorage.js"></script>
<script src="gadget_global.js" ></script> <script src="gadget_global.js" ></script>
<script src="fast_priority_queue.js"></script> <script src="fast_priority_queue.js"></script>
<script src="gadget_erp5_chat_panel.js"></script> <script src="gadget_erp5_chat_panel.js"></script>
</head> </head>
<body> <body>
<div data-gadget-url="gadget_jio.html"
data-gadget-scope="storage_gadget"
data-gadget-sandbox="public"></div>
<h3>Chat List</h3> <h3>Chat List</h3>
<p class="error"> <p class="error">
</p> </p>
...@@ -20,5 +26,8 @@ ...@@ -20,5 +26,8 @@
<input type="text" name="content" /> <input type="text" name="content" />
<input type="submit" value="Send!" /> <input type="submit" value="Send!" />
</form> </form>
<form class="sync-form">
<input type="submit" value="Synchronize!" />
</form>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -142,8 +142,95 @@ ...@@ -142,8 +142,95 @@
} }
} }
function createJio(my_gadget) {
return new RSVP.Queue()
.push(function () {
return my_gadget.getDeclaredGadget("storage_gadget");
})
.push(function (storage_gadget) {
var remote_config = {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "officejs-chat"
}
}
}
var remote_post = true;
// We want the remote ERP5 storage to be canonical, so true for ERP5.
// Post is not implemented in drivetojiomapping, so false for others.
switch (my_gadget.state_parameter_dict.remote) {
case "dropbox":
var start = document.URL.indexOf("access_token=") + 13;
var end = document.URL.indexOf("&", start);
var token = document.URL.slice(start, end);
remote_config = {
type: "query",
sub_storage: {
type: "drivetojiomapping",
sub_storage: {
type: "dropbox",
access_token: token,
root: "dropbox"
}
}
};
remote_post = false;
break;
case "dav":
remote_config = {
type: "query",
sub_storage: {
type: "drivetojiomapping",
sub_storage: {
type: "dav",
url: my_gadget.state_parameter_dict.dav_url,
basic_login: btoa(my_gadget.state_parameter_dict.dav_user
+ ":" + my_gadget.state_parameter_dict.dav_pass),
with_credentials: true
}
}
};
remote_post = false;
break;
case "erp5":
remote_config = {
type: "erp5",
url: (new URI("hateoas"))
.absoluteTo(my_gadget.state_parameter_dict.erp5_url).toString(),
default_view_reference: "view"
};
remote_post = true;
break;
}
return storage_gadget.createJio({
type: "replicate",
use_remote_post: remote_post,
conflict_handling: 2,
query: {
query: 'portal_type: "Text Post"',
limit: [0, 1000000000]
},
local_sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "officejs-chat"
}
}
},
remote_sub_storage: remote_config
});
})
.push(null, logError);
}
// Create new message from its type and content // Create new message from its type and content
function createMessage(gadget, type, content, peer_source) { function createMessage(gadget, type, content) {
return { return {
type: type, type: type,
name: gadget.state_parameter_dict.name, name: gadget.state_parameter_dict.name,
...@@ -151,7 +238,6 @@ ...@@ -151,7 +238,6 @@
room: gadget.state_parameter_dict.room, room: gadget.state_parameter_dict.room,
time: new Date(), time: new Date(),
content: content, content: content,
peer_source: peer_source
} }
} }
...@@ -290,6 +376,11 @@ ...@@ -290,6 +376,11 @@
name: null, name: null,
folder: null, folder: null,
room: null, room: null,
remote: null,
erp5_url: null,
dav_url: null,
dav_user: null,
dav_pass: null,
message_list: [], message_list: [],
guest_amount: 0, guest_amount: 0,
last_message_dict: {}, last_message_dict: {},
...@@ -301,9 +392,10 @@ ...@@ -301,9 +392,10 @@
}) })
.push(function (element) { .push(function (element) {
gadget.state_parameter_dict.element = element; gadget.state_parameter_dict.element = element;
}); })
.push(null, logError);
}) })
// Initialize gadget, after initializing name, folder, and room outside // Initialize gadget, after initializing name, folder, and room outside
.declareMethod('render', function () { .declareMethod('render', function () {
var gadget = this; var gadget = this;
...@@ -313,11 +405,8 @@ ...@@ -313,11 +405,8 @@
.querySelector("input").onfocus = function () { .querySelector("input").onfocus = function () {
return changeFavicon(gadget.state_parameter_dict.default_icon); return changeFavicon(gadget.state_parameter_dict.default_icon);
}; };
return createJio(gadget);
}) })
.push(function () {
return gadget.jioApply('repair');
})
.push(null, logError)
.push(function () { .push(function () {
return gadget.getLocalArchive(); return gadget.getLocalArchive();
}) })
...@@ -327,23 +416,26 @@ ...@@ -327,23 +416,26 @@
.push(null, logError); .push(null, logError);
}) })
.declareAcquiredMethod('jioApply', 'jioApply')
.declareAcquiredMethod('sendMessage', 'sendMessage') .declareAcquiredMethod('sendMessage', 'sendMessage')
// Get all messages stored in archive and add them to the list in order, // Get all messages stored in archive and add them to the list in order,
// using storeList because the messages are already in the archive // using storeList because the messages are already in the archive
.declareMethod('getLocalArchive', function () { .declareMethod('getLocalArchive', function () {
console.log('get local');
var gadget = this; var gadget = this;
var storage_gadget;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.jioApply('allDocs'); return gadget.getDeclaredGadget("storage_gadget");
})
.push(function (jio_gadget) {
storage_gadget = jio_gadget;
return storage_gadget.allDocs();
}) })
.push(function (document_list) { .push(function (document_list) {
var list = document_list.data.rows; var list = document_list.data.rows;
var promise_list = []; var promise_list = [];
for (var i = 0, i_len = list.length; i < i_len; i++) { for (var i = 0, i_len = list.length; i < i_len; i++) {
promise_list.push(gadget.jioApply('get', list[i].id)); promise_list.push(storage_gadget.get(list[i].id));
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
...@@ -372,13 +464,14 @@ ...@@ -372,13 +464,14 @@
} }
} }
gadget.state_parameter_dict.initialized = true; gadget.state_parameter_dict.initialized = true;
console.log("Received local archive. Number of messages: " +
gadget.state_parameter_dict.message_list.length);
}) })
.push(null, logError); .push(null, logError);
}) })
// Send all requested messages in the list, in sorted order, to peer // Send all requested messages in the list, in sorted order, to peer
.declareMethod('sendLocalArchive', function (request) { .declareMethod('sendLocalArchive', function (request, source) {
console.log('send archive');
var gadget = this; var gadget = this;
var request_list = []; var request_list = [];
var list = gadget.state_parameter_dict.message_list; var list = gadget.state_parameter_dict.message_list;
...@@ -388,9 +481,11 @@ ...@@ -388,9 +481,11 @@
request_list.push(list[i]); request_list.push(list[i]);
} }
} }
console.log(request_list); console.log("Sent local archive. Number of messages sent: "
+ request_list.length + " of "
+ gadget.state_parameter_dict.message_list.length);
return logQueue(gadget.sendMessage(createMessage( return logQueue(gadget.sendMessage(createMessage(
gadget, "bundle", request_list, request.peer_source))); gadget, "bundle", request_list), source));
}) })
// Get all new messages from the sorted list of peer, // Get all new messages from the sorted list of peer,
...@@ -398,7 +493,8 @@ ...@@ -398,7 +493,8 @@
// and refresh, dedupe, and resort the list using refreshChat // and refresh, dedupe, and resort the list using refreshChat
.declareMethod('getRemoteArchive', function (bundle) { .declareMethod('getRemoteArchive', function (bundle) {
var gadget = this; var gadget = this;
console.log('get archive'); console.log("Received remote archive. Number of messages received: " +
bundle.content.length);
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var list = gadget.state_parameter_dict.message_list; var list = gadget.state_parameter_dict.message_list;
...@@ -459,31 +555,36 @@ ...@@ -459,31 +555,36 @@
var gadget = this; var gadget = this;
var id = message.folder + "_" + message.room + "_" var id = message.folder + "_" + message.room + "_"
+ message.name + "_" + getTime(message).toString(); + message.name + "_" + getTime(message).toString();
return logQueue(gadget.jioApply('put', id, { return new RSVP.Queue()
portal_type: "Text Post", .push(function () {
parent_relative_url: "post_text_module", return gadget.getDeclaredGadget("storage_gadget");
reference: id, // XXX use uuid here })
author: message.name, .push(function (storage_gadget) {
date_ms: getTime(message), return logQueue(storage_gadget.put(id, {
content: JSON.stringify(message) portal_type: "Text Post",
})); parent_relative_url: "post_text_module",
reference: id, // XXX use uuid here
author: message.name,
date_ms: getTime(message),
content: JSON.stringify(message)
}));
});
}) })
// Ask a peer to send over a request // Ask a peer to send over a request
.declareMethod('requestRequest', function () { .declareMethod('requestRequest', function () {
console.log('send doubler');
var gadget = this; var gadget = this;
console.log("Sent request for a request.");
return logQueue(gadget.sendMessage(createMessage(gadget, "doubler", ""))); return logQueue(gadget.sendMessage(createMessage(gadget, "doubler", "")));
}) })
// Send a request to update the local archive // Send a request to update the local archive
.declareMethod('sendRequest', function () { .declareMethod('sendRequest', function () {
console.log('send request');
var gadget = this; var gadget = this;
return pollUntilNotNull(gadget, 1000, 30000, function () { return pollUntilNotNull(gadget, 1000, 30000, function () {
return gadget.state_parameter_dict.initialized; return gadget.state_parameter_dict.initialized;
}, function () { }, function () {
console.log(JSON.stringify(gadget.state_parameter_dict.last_message_dict)); console.log("Sent request for messages.");
return gadget.sendMessage(createMessage( return gadget.sendMessage(createMessage(
gadget, "request", gadget.state_parameter_dict.last_message_dict)); gadget, "request", gadget.state_parameter_dict.last_message_dict));
}); });
...@@ -502,6 +603,21 @@ ...@@ -502,6 +603,21 @@
} else { } else {
return gadget.deployMessage("message", content); return gadget.deployMessage("message", content);
} }
case "sync-form":
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget("storage_gadget");
})
.push(function (storage_gadget) {
return storage_gadget.repair();
})
.push(function () {
return gadget.getLocalArchive();
})
.push(function () {
return gadget.requestRequest();
})
.push(null, logError);
} }
} }
return loopEventListener( return loopEventListener(
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Chat WebRTC</title> <title>>WebRTC Gadget</title>
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="adapter.js"></script> <script src="adapter.js"></script>
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
<script src="gadget_erp5_chat_webrtc.js"></script> <script src="gadget_erp5_chat_webrtc.js"></script>
</head> </head>
<body> <body>
<h1>OfficeJS Chat</h1>
<p class="timeout-alert"> <p class="timeout-alert">
</p> </p>
......
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
erp5_gadget = jio_gadget; erp5_gadget = jio_gadget;
return erp5_gadget.createJio({ return erp5_gadget.createJio({
type: "erp5", type: "erp5",
url: url, url: (new URI("hateoas")).absoluteTo(url).toString(),
default_view_reference: "view" default_view_reference: "view"
}); });
}) })
...@@ -231,8 +231,8 @@ ...@@ -231,8 +231,8 @@
function resetErp5Content(erp5_gadget, param_dict) { function resetErp5Content(erp5_gadget, param_dict) {
var folder = param_dict.folder; var folder = param_dict.folder;
var url = param_dict.url; var url = param_dict.url;
return logQueue(erp5_gadget.putAttachment(folder, return logQueue(erp5_gadget.putAttachment(
url + "WebrtcRoom_resetContent", "/", url + "WebrtcRoom_resetContent",
new Blob([JSON.stringify({folder: folder})]))); new Blob([JSON.stringify({folder: folder})])));
} }
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
var action = param_dict.action; var action = param_dict.action;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return erp5_gadget.putAttachment(folder, url + action, return erp5_gadget.putAttachment("/", url + action,
new Blob([JSON.stringify({folder: folder, room: room, name: name})])); new Blob([JSON.stringify({folder: folder, room: room, name: name})]));
}) })
.push(function (response) { .push(function (response) {
...@@ -265,8 +265,9 @@ ...@@ -265,8 +265,9 @@
var folder = param_dict.folder; var folder = param_dict.folder;
var name = param_dict.name; var name = param_dict.name;
var url = param_dict.url; var url = param_dict.url;
return logQueue(erp5_gadget.putAttachment(folder, return logQueue(erp5_gadget.putAttachment(
url + "WebrtcRoom_putContent", new Blob([JSON.stringify( "/", url + "WebrtcRoom_putContent",
new Blob([JSON.stringify(
{folder: folder, name: name, content: content})]))); {folder: folder, name: name, content: content})])));
} }
...@@ -274,12 +275,14 @@ ...@@ -274,12 +275,14 @@
var folder = param_dict.folder; var folder = param_dict.folder;
var name = param_dict.name; var name = param_dict.name;
var url = param_dict.url; var url = param_dict.url;
return logQueue(erp5_gadget.putAttachment(folder, return logQueue(erp5_gadget.putAttachment(
url + "WebrtcRoom_deleteContent", "/", url + "WebrtcRoom_deleteContent",
new Blob([JSON.stringify({folder: folder, name: name})]))); new Blob([JSON.stringify({folder: folder, name: name})])));
} }
function authenticateErp5(my_gadget) { function authenticateErp5(my_gadget) {
var erp5_folder_url =
"https://softinst75770.host.vifib.net/erp5/webrtc_rooms_module/";
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return createErp5Jio( return createErp5Jio(
...@@ -289,21 +292,20 @@ ...@@ -289,21 +292,20 @@
.push(function (folder_id) { .push(function (folder_id) {
var lastIndex = folder_id.indexOf("/") + 1; var lastIndex = folder_id.indexOf("/") + 1;
my_gadget.state_parameter_dict.erp5_folder = folder_id.slice(lastIndex); my_gadget.state_parameter_dict.erp5_folder = folder_id.slice(lastIndex);
my_gadget.state_parameter_dict.erp5_url = erp5_folder_url += my_gadget.state_parameter_dict.erp5_folder + "/";
my_gadget.state_parameter_dict.erp5_url + "webrtc_rooms_module/"
+ my_gadget.state_parameter_dict.erp5_folder + "/";
return my_gadget.getDeclaredGadget("erp5_gadget"); return my_gadget.getDeclaredGadget("erp5_gadget");
}) })
.push(function (erp5_gadget) { .push(function (erp5_gadget) {
return resetErp5Content(erp5_gadget, { return resetErp5Content(erp5_gadget, {
folder: my_gadget.state_parameter_dict.erp5_folder, folder: my_gadget.state_parameter_dict.erp5_folder,
url: my_gadget.state_parameter_dict.erp5_url url: erp5_folder_url
}); });
}) })
.push(function () { .push(function () {
var erp5_params = [ var erp5_params = [
my_gadget, "erp5_gadget", my_gadget, "erp5_gadget",
my_gadget.state_parameter_dict.erp5_folder, { my_gadget.state_parameter_dict.erp5_folder, {
erp5_folder_url: erp5_folder_url,
resetContent: resetErp5Content, resetContent: resetErp5Content,
getOffer: function (erp5_gadget, param_dict) { getOffer: function (erp5_gadget, param_dict) {
param_dict.action = "WebrtcRoom_getOffer"; param_dict.action = "WebrtcRoom_getOffer";
...@@ -330,7 +332,7 @@ ...@@ -330,7 +332,7 @@
my_gadget, jio_gadget_name, folder, jio_function_dict) { my_gadget, jio_gadget_name, folder, jio_function_dict) {
var room = my_gadget.state_parameter_dict.room; var room = my_gadget.state_parameter_dict.room;
var name; var name;
var url = my_gadget.state_parameter_dict.erp5_url; var url = jio_function_dict.erp5_folder_url;
var jio_gadget; var jio_gadget;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -400,7 +402,7 @@ ...@@ -400,7 +402,7 @@
my_gadget, jio_gadget_name, folder, jio_function_dict) { my_gadget, jio_gadget_name, folder, jio_function_dict) {
var room = my_gadget.state_parameter_dict.room; var room = my_gadget.state_parameter_dict.room;
var name; var name;
var url = my_gadget.state_parameter_dict.erp5_url; var url = jio_function_dict.erp5_folder_url;
var jio_gadget; var jio_gadget;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -517,7 +519,8 @@ ...@@ -517,7 +519,8 @@
window.location.reload(); window.location.reload();
} }
} }
console.log("connected guests: " + my_gadget.state_parameter_dict.guest_amount); console.log("A guest is now " + peer_connection.iceConnectionState +
". Number of guests: " + my_gadget.state_parameter_dict.guest_amount);
}; };
} }
} }
...@@ -544,6 +547,16 @@ ...@@ -544,6 +547,16 @@
my_gadget.state_parameter_dict.folder; my_gadget.state_parameter_dict.folder;
chat_gadget.state_parameter_dict.room = chat_gadget.state_parameter_dict.room =
my_gadget.state_parameter_dict.room; my_gadget.state_parameter_dict.room;
chat_gadget.state_parameter_dict.remote =
my_gadget.state_parameter_dict.remote;
chat_gadget.state_parameter_dict.erp5_url =
my_gadget.state_parameter_dict.erp5_url;
chat_gadget.state_parameter_dict.dav_url =
my_gadget.state_parameter_dict.dav_url;
chat_gadget.state_parameter_dict.dav_user =
my_gadget.state_parameter_dict.dav_user;
chat_gadget.state_parameter_dict.dav_pass =
my_gadget.state_parameter_dict.dav_pass;
my_gadget.state_parameter_dict.element.appendChild( my_gadget.state_parameter_dict.element.appendChild(
chat_gadget.state_parameter_dict.element); chat_gadget.state_parameter_dict.element);
return chat_gadget.render(); return chat_gadget.render();
...@@ -568,9 +581,9 @@ ...@@ -568,9 +581,9 @@
} }
data_channel.onmessage = function (my_event) { data_channel.onmessage = function (my_event) {
var message = JSON.parse(my_event.data); var message = JSON.parse(my_event.data);
var source = my_event.srcElement;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
message.peer_source = my_event.srcElement;
return my_gadget.getDeclaredGadget("chat_gadget"); return my_gadget.getDeclaredGadget("chat_gadget");
}) })
.push(function (chat_gadget) { .push(function (chat_gadget) {
...@@ -581,7 +594,7 @@ ...@@ -581,7 +594,7 @@
}) })
.push(function () { .push(function () {
if (my_gadget.state_parameter_dict.role === "host") { if (my_gadget.state_parameter_dict.role === "host") {
return my_gadget.sendMessage(message); return my_gadget.sendMessage(message, source);
} else if (my_gadget.state_parameter_dict.role === "guest") { } else if (my_gadget.state_parameter_dict.role === "guest") {
return; return;
} }
...@@ -590,8 +603,9 @@ ...@@ -590,8 +603,9 @@
} else if (message.type === "bundle") { } else if (message.type === "bundle") {
if (my_gadget.state_parameter_dict.role === "host") { if (my_gadget.state_parameter_dict.role === "host") {
my_gadget.state_parameter_dict.archive_amount += 1; my_gadget.state_parameter_dict.archive_amount += 1;
console.log("guest amount: " + my_gadget.state_parameter_dict.guest_amount); console.log("Received archive number: " +
console.log("archive amount: " + my_gadget.state_parameter_dict.archive_amount); my_gadget.state_parameter_dict.archive_amount +
" of " + my_gadget.state_parameter_dict.guest_amount);
if (my_gadget.state_parameter_dict.archive_amount >= if (my_gadget.state_parameter_dict.archive_amount >=
my_gadget.state_parameter_dict.guest_amount) { my_gadget.state_parameter_dict.guest_amount) {
my_gadget.state_parameter_dict.archive_amount = 0; my_gadget.state_parameter_dict.archive_amount = 0;
...@@ -609,10 +623,10 @@ ...@@ -609,10 +623,10 @@
return chat_gadget.getRemoteArchive(message); return chat_gadget.getRemoteArchive(message);
} }
} else if (message.type === "request") { } else if (message.type === "request") {
console.log("get request"); console.log("Received request for messages.");
return chat_gadget.sendLocalArchive(message); return chat_gadget.sendLocalArchive(message, source);
} else if (message.type === "doubler") { } else if (message.type === "doubler") {
console.log("get doubler"); console.log("Received request for a request.");
return chat_gadget.sendRequest(); return chat_gadget.sendRequest();
} }
}) })
...@@ -660,6 +674,7 @@ ...@@ -660,6 +674,7 @@
folder: null, folder: null,
room: null, room: null,
role: null, role: null,
remote: null,
candidate: null, candidate: null,
connected: false, connected: false,
offer_ready: false, offer_ready: false,
...@@ -669,8 +684,10 @@ ...@@ -669,8 +684,10 @@
archive_amount: 0, archive_amount: 0,
// full path including user folder, e.g. "/Apps/OfficeJS Chat/nexedi/" // full path including user folder, e.g. "/Apps/OfficeJS Chat/nexedi/"
dropbox_folder: "/Apps/OfficeJS Chat", dropbox_folder: "/Apps/OfficeJS Chat",
erp5_url: "https://softinst75770.host.vifib.net/erp5/" erp5_url: null,
+ "web_site_module/web_chat/hateoas/", dav_url: null,
dav_user: null,
dav_pass: null,
erp5_folder: null, erp5_folder: null,
ice_config: { ice_config: {
iceServers: [{url: "stun:stun.1.google.com:19302"}] iceServers: [{url: "stun:stun.1.google.com:19302"}]
...@@ -704,9 +721,8 @@ ...@@ -704,9 +721,8 @@
return gadget.sendMessage.apply(gadget, param_dict); return gadget.sendMessage.apply(gadget, param_dict);
}) })
.declareMethod('sendMessage', function (message) { .declareMethod('sendMessage', function (message, source) {
var gadget = this; var gadget = this;
var source = message.peer_source;
var message_string = JSON.stringify(message); var message_string = JSON.stringify(message);
var channel_list = gadget.state_parameter_dict.data_channel_list; var channel_list = gadget.state_parameter_dict.data_channel_list;
return new RSVP.Queue() return new RSVP.Queue()
...@@ -758,6 +774,13 @@ ...@@ -758,6 +774,13 @@
} }
return createInitialOffer(gadget); return createInitialOffer(gadget);
}) })
.push(function () {
if (gadget.state_parameter_dict.auth === "dropbox") {
return authenticateDropbox(gadget);
} else if (gadget.state_parameter_dict.auth === "erp5") {
return authenticateErp5(gadget);
}
})
.push(null, logError); .push(null, logError);
}) })
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>classification/collaborative/team</string>
<string>contributor/person_module/1</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>jio_mappingstorage.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jio_mappingstorage_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>JIO Mapping Storage JS</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
web_page_module/adapter_js web_page_module/adapter_js
web_page_module/fast_priority_queue_js web_page_module/fast_priority_queue_js
web_page_module/gadget_erp5_chat* web_page_module/gadget_erp5_chat*
web_page_module/jio_mappingstorage_js
web_site_module/web_chat/** web_site_module/web_chat/**
\ No newline at end of file
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