PR to fix media server sleep issue (#3189)

* fix media-server sleep wake up issue

we now use waku v2 and hence messenger was nil.
Since it was nil, the logic in place responsible for triggering app state events was not firing and hence media server would become un-responsive after a sleep event.

this commit fixes that.

Co-Authored-By: Andrea Maria Piana <andrea.maria.piana@gmail.com>


---------

Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Siddarth Kumar 2023-02-15 13:44:00 +05:30 committed by GitHub
parent b69042e7d7
commit cf84c40320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 15 deletions

View File

@ -1 +1 @@
0.131.2
0.131.3

View File

@ -1289,30 +1289,37 @@ func (b *GethStatusBackend) ConnectionChange(typ string, expensive bool) {
// AppStateChange handles app state changes (background/foreground).
// state values: see https://facebook.github.io/react-native/docs/appstate.html
func (b *GethStatusBackend) AppStateChange(state string) {
var messenger *protocol.Messenger
s, err := parseAppState(state)
if err != nil {
log.Error("AppStateChange failed, ignoring", "error", err)
return // and do nothing
return
}
b.log.Info("App State changed", "new-state", s)
b.appState = s
if b.statusNode != nil {
wakuext := b.statusNode.WakuExtService()
if b.statusNode == nil {
log.Warn("statusNode nil, not reporting app state change")
return
}
if wakuext != nil {
messenger := wakuext.Messenger()
if b.statusNode.WakuExtService() != nil {
messenger = b.statusNode.WakuExtService().Messenger()
}
if messenger != nil {
if s == appStateForeground {
messenger.ToForeground()
} else {
messenger.ToBackground()
}
}
}
if b.statusNode.WakuV2ExtService() != nil {
messenger = b.statusNode.WakuV2ExtService().Messenger()
}
if messenger == nil {
log.Warn("messenger nil, not reporting app state change")
return
}
if s == appStateForeground {
messenger.ToForeground()
} else {
messenger.ToBackground()
}
// TODO: put node in low-power mode if the app is in background (or inactive)

View File

@ -4444,6 +4444,7 @@ func (m *Messenger) prepareMessage(msg *common.Message, s *server.MediaServer) {
if msg.ContentType == protobuf.ChatMessage_IMAGE {
msg.ImageLocalURL = s.MakeImageURL(msg.ID)
}
if msg.ContentType == protobuf.ChatMessage_DISCORD_MESSAGE {
dm := msg.GetDiscordMessage()

View File

@ -80,6 +80,7 @@ func (s *ServerURLSuite) TestServer_MakeImageURL() {
s.Require().Equal(
"https://127.0.0.1:1337/messages/images?messageId=0x10aded70ffee",
s.server.MakeImageURL("0x10aded70ffee"))
s.testNoPort(
"https://127.0.0.1:80/messages/images?messageId=0x10aded70ffee",
s.serverNoPort.MakeImageURL("0x10aded70ffee"))