Working message sending

This commit is contained in:
Fabrice Mouhartem 2025-09-25 17:07:39 +03:00
parent e413b7c384
commit 1471dd8959
No known key found for this signature in database
GPG Key ID: 90579C24FD123C93
2 changed files with 21 additions and 3 deletions

View File

@ -24,7 +24,8 @@ define([
let onFrameworkReady = function (framework) {
let content = { updates: [] };
let myName = window.webxdc.selfName = framework._.sfCommon.getMetadataMgr().getUserData().name;
let myName = window.webxdc.selfName = framework._.sfCommon.getMetadataMgr().getUserData().name || "Guest";
let myAddr = window.webxdc.selfAddr = framework._.sfCommon.getMetadataMgr().getUserData().uid || "Guest";
console.log("Document is ready. My name is:", myName);
window.webxdc.sendUpdate = (update) => {
@ -39,19 +40,30 @@ define([
href: update.href,
document: update.document,
serial: serial,
max_serial: serial,
};
content.updates.push(_update);
if (!window.cp_updateListener) {
console.log('pushing3', _update);
window.cp_pendingUpdates ||= [];
window.cp_pendingUpdates.push(_update);
}
else {
window.cp_updateListener(_update);
}
framework.localChange();
};
framework.onContentUpdate(function (newContent) {
if (!newContent.updates) { return; }
console.log('New content received from others', newContent.content);
console.log('New content received from others', newContent);
const length = content.updates.length;
const newUpdates = newContent.updates.slice(length);
newUpdates.forEach(update => {
console.log('pushing', update);
content.updates.push(update);
if (!window.cp_updateListener) {
console.log('pushing2', update);
window.cp_pendingUpdates ||= [];
window.cp_pendingUpdates.push(update);
return;

View File

@ -30,7 +30,13 @@ window.webxdc = (() => {
// });
window.cp_updateListener = cb;
if (window.cp_pendingUpdates) {
window.cp_pendingUpdates.forEach(cb);
console.log('pending', window.cp_pendingUpdates);
const a = window.cp_pendingUpdates;
const maxSerial = a[a.length-1].serial;
window.cp_pendingUpdates.forEach(update => {
update.max_serial = maxSerial;
cb(update);
});
}
return Promise.resolve();
},