addMessageListener("socket-server-msg", function (msg) { if (mockSocket) {
mockSocket.serverSendMsg(msg);
} else {
serverMsgs.push(msg);
}
});
var MockService = {
requestID: 1,
resolvers: new Map(),
sendRequest(name, params) { returnnew Promise((resolve, reject) => {
let id = this.requestID++; this.resolvers.set(id, { resolve, reject });
sendAsyncMessage("service-request", {
name,
id, // The request params from the real push service may contain a // principal, which cannot be passed to the unprivileged // mochitest scope, and will cause the message to be dropped if // present. The mochitest scope fortunately does not need the // principal, though, so set it to null before sending.
params: Object.assign({}, params, { principal: null }),
});
});
},
handleResponse(response) { if (!this.resolvers.has(response.id)) {
console.error(`Unexpected response for request ${response.id}`); return;
}
let resolver = this.resolvers.get(response.id); this.resolvers.delete(response.id); if (response.error) {
resolver.reject(response.error);
} else {
resolver.resolve(response.result);
}
},
async function replaceService(service) { // `?.` because `service` can be null // (either by calling this function with null, or the push module doesn't have the // field at all e.g. in GeckoView) // Passing null here resets it to the default implementation on desktop // (so `.service` never becomes null there) but not for GeckoView. // XXX(krosylight): we need to remove this deviation.
await pushService.service?.uninit();
pushService.service = service;
await pushService.service?.init();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.