Skip to content

Commit eae1877

Browse files
zengjiezyro
authored andcommitted
Allow sending arbitrary messages instead of StreamData to stream. (heroiclabs#260)
1 parent 2614feb commit eae1877

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

runtime/runtime.go

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ type NakamaModule interface {
309309
StreamCount(mode uint8, subject, descriptor, label string) (int, error)
310310
StreamClose(mode uint8, subject, descriptor, label string) error
311311
StreamSend(mode uint8, subject, descriptor, label, data string) error
312+
StreamSendRaw(mode uint8, subject, descriptor, label string, msg *rtapi.Envelope) error
312313

313314
MatchCreate(ctx context.Context, module string, params map[string]interface{}) (string, error)
314315
MatchList(ctx context.Context, limit int, authoritative bool, label string, minSize, maxSize int, query string) ([]*api.Match, error)

server/runtime_go_nakama.go

+27
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,33 @@ func (n *RuntimeGoNakamaModule) StreamSend(mode uint8, subject, descriptor, labe
627627
return nil
628628
}
629629

630+
func (n *RuntimeGoNakamaModule) StreamSendRaw(mode uint8, subject, descriptor, label string, msg *rtapi.Envelope) error {
631+
stream := PresenceStream{
632+
Mode: mode,
633+
Label: label,
634+
}
635+
var err error
636+
if subject != "" {
637+
stream.Subject, err = uuid.FromString(subject)
638+
if err != nil {
639+
return errors.New("stream subject must be a valid identifier")
640+
}
641+
}
642+
if descriptor != "" {
643+
stream.Descriptor, err = uuid.FromString(descriptor)
644+
if err != nil {
645+
return errors.New("stream descriptor must be a valid identifier")
646+
}
647+
}
648+
if msg == nil {
649+
return errors.New("expects a valid message")
650+
}
651+
652+
n.router.SendToStream(n.logger, stream, msg)
653+
654+
return nil
655+
}
656+
630657
func (n *RuntimeGoNakamaModule) MatchCreate(ctx context.Context, module string, params map[string]interface{}) (string, error) {
631658
if module == "" {
632659
return "", errors.New("expects module name")

0 commit comments

Comments
 (0)