github.com/anycable/anycable-go@v1.5.1/identity/public.go (about)

     1  package identity
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/anycable/anycable-go/common"
     7  )
     8  
     9  // PublicIdentifier identifies all clients and use their sid as the only identifier
    10  type PublicIdentifier struct {
    11  }
    12  
    13  var _ Identifier = (*PublicIdentifier)(nil)
    14  
    15  func NewPublicIdentifier() *PublicIdentifier {
    16  	return &PublicIdentifier{}
    17  }
    18  
    19  func (pi *PublicIdentifier) Identify(sid string, env *common.SessionEnv) (*common.ConnectResult, error) {
    20  	return &common.ConnectResult{
    21  		Identifier:    publicIdentifiers(sid),
    22  		Transmissions: []string{actionCableWelcomeMessage(sid)},
    23  		Status:        common.SUCCESS,
    24  	}, nil
    25  }
    26  
    27  func publicIdentifiers(sid string) string {
    28  	return fmt.Sprintf(`{"sid":"%s"}`, sid)
    29  }