Skip to main content

Set Up Search Notifications

Last updated on

A search notification function can be used to display the current progress of the Matchmaking service to players while they are waiting to be matched. The sendNotificationSearching function will find the WebSocket message containing the word searching and will be sent to players via the FreeFormNotificationByUserId function from the Lobby service, which will hit the Freeform endpoint through our Cloud Golang SDK.

// GO-SDK lobby service
func sendNotificationSearching(namespace, userId string) error {
message := "searching"
topic := constants.MatchmakingNotificationTopic
body := lobbyclientmodels.ModelFreeFormNotificationRequest{
Message: &message,
Topic: &topic,
}
input := &notification.FreeFormNotificationByUserIDParams{
Body: &body,
Namespace: namespace,
UserID: userId,
}
gameNotificationService := lobby.NotificationService{
Client: factory.NewLobbyClient(&configImpl),
TokenRepository: &tokenRepositoryImpl,
}
//lint:ignore SA1019 Ignore the deprecation warnings
sendNotificationSearchingErr := gameNotificationService.FreeFormNotificationByUserID(input)
if sendNotificationSearchingErr != nil {
log.Printf("Unable to send notification match searching to lobby. userId : %+v", userId)
log.Print(sendNotificationSearchingErr.Error())
return sendNotificationSearchingErr
}

return nil
}