kopia lustrzana https://gitlab.com/rysiekpl/libresilient
service-worker: bugfix - client.postMessage() only when client not null
rodzic
4dd6840e8d
commit
2d9c27e8e7
|
@ -177,9 +177,11 @@ let decrementActiveFetches = (clientId) => {
|
||||||
// (and new fetches will fire in a moment, because a CSS file just
|
// (and new fetches will fire in a moment, because a CSS file just
|
||||||
// got fetched) or not
|
// got fetched) or not
|
||||||
self.clients.get(clientId).then((client)=>{
|
self.clients.get(clientId).then((client)=>{
|
||||||
client.postMessage({
|
if (client !== null) {
|
||||||
allFetched: true
|
client.postMessage({
|
||||||
})
|
allFetched: true
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(()=>{
|
.then(()=>{
|
||||||
self.log('service-worker', 'all-fetched message sent.')
|
self.log('service-worker', 'all-fetched message sent.')
|
||||||
|
@ -255,8 +257,10 @@ let LibResilientResourceInfo = class {
|
||||||
self.clients.get(clientId).then((client)=>{
|
self.clients.get(clientId).then((client)=>{
|
||||||
// set the client
|
// set the client
|
||||||
this.client = client
|
this.client = client
|
||||||
// Send a message to the client.
|
// Send a message to the client
|
||||||
this.client.postMessage(this.values);
|
if (this.client !== null) {
|
||||||
|
this.client.postMessage(this.values);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,7 +291,7 @@ let LibResilientResourceInfo = class {
|
||||||
})
|
})
|
||||||
self.log('service-worker', msg)
|
self.log('service-worker', msg)
|
||||||
// send the message to the client
|
// send the message to the client
|
||||||
if (this.client && changed) {
|
if (this.client && changed && (this.client !== null)) {
|
||||||
this.client.postMessage(this.values);
|
this.client.postMessage(this.values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,10 +501,12 @@ let getResourceThroughLibResilient = (request, clientId, useStashed=true, doStas
|
||||||
// inform!
|
// inform!
|
||||||
self.log('service-worker', 'fetched version method or ETag differs from stashed for:', url)
|
self.log('service-worker', 'fetched version method or ETag differs from stashed for:', url)
|
||||||
self.clients.get(reqInfo.clientId).then((client)=>{
|
self.clients.get(reqInfo.clientId).then((client)=>{
|
||||||
client.postMessage({
|
if (client !== null) {
|
||||||
url: url,
|
client.postMessage({
|
||||||
fetchedDiffers: true
|
url: url,
|
||||||
})
|
fetchedDiffers: true
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -582,7 +588,7 @@ self.addEventListener('fetch', event => {
|
||||||
// if event.resultingClientId is available, we need to use this
|
// if event.resultingClientId is available, we need to use this
|
||||||
// otherwise event.clientId is what we want
|
// otherwise event.clientId is what we want
|
||||||
// ref. https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId
|
// ref. https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId
|
||||||
var clientId = event.clientId
|
var clientId = (event.clientId !== null) ? event.clientId : 'unknown-client'
|
||||||
if (event.resultingClientId) {
|
if (event.resultingClientId) {
|
||||||
clientId = event.resultingClientId
|
clientId = event.resultingClientId
|
||||||
// yeah, we seem to have to send the client their clientId
|
// yeah, we seem to have to send the client their clientId
|
||||||
|
@ -595,11 +601,13 @@ self.addEventListener('fetch', event => {
|
||||||
self.clients
|
self.clients
|
||||||
.get(clientId)
|
.get(clientId)
|
||||||
.then((client)=>{
|
.then((client)=>{
|
||||||
client.postMessage({
|
if (client !== null) {
|
||||||
clientId: clientId,
|
client.postMessage({
|
||||||
plugins: self.LibResilientPlugins.filter(p=>(!p.indirect)).map((p)=>{return p.name}),
|
clientId: clientId,
|
||||||
serviceWorker: 'COMMIT_UNKNOWN'
|
plugins: self.LibResilientPlugins.filter(p=>(!p.indirect)).map((p)=>{return p.name}),
|
||||||
})
|
serviceWorker: 'COMMIT_UNKNOWN'
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue