Files
chromanews/Modules/webSubManager.js

32 lines
867 B
JavaScript

import { error } from './logManager';
export async function subbWebSub(callback, topic, hub) {
const options = {
method: 'POST',
mode: 'cors',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ 'hub.mode': 'subscribe', 'hub.topic': topic, 'hub.callback': callback, 'hub.verify': 'sync' }),
};
return await fetch(hub, options)
.then(res => {
res.status === 204 ? true : false;
})
.catch(err => error(err));
}
export async function unsubWebSub(callback, topic, hub) {
const options = {
method: 'POST',
mode: 'cors',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ 'hub.mode': 'unsubscribe', 'hub.topic': topic, 'hub.callback': callback, 'hub.verify': 'sync' }),
};
return await fetch(hub, options)
.then(res => {
res.status === 204 ? true : false;
})
.catch(err => error(err));
}