Commit eae1877f authored by Zeng Jie's avatar Zeng Jie Committed by Andrei Mihu
Browse files

Allow sending arbitrary messages instead of StreamData to stream. (#260)

parent 2614febc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -309,6 +309,7 @@ type NakamaModule interface {
	StreamCount(mode uint8, subject, descriptor, label string) (int, error)
	StreamClose(mode uint8, subject, descriptor, label string) error
	StreamSend(mode uint8, subject, descriptor, label, data string) error
	StreamSendRaw(mode uint8, subject, descriptor, label string, msg *rtapi.Envelope) error

	MatchCreate(ctx context.Context, module string, params map[string]interface{}) (string, error)
	MatchList(ctx context.Context, limit int, authoritative bool, label string, minSize, maxSize int, query string) ([]*api.Match, error)
+27 −0
Original line number Diff line number Diff line
@@ -627,6 +627,33 @@ func (n *RuntimeGoNakamaModule) StreamSend(mode uint8, subject, descriptor, labe
	return nil
}

func (n *RuntimeGoNakamaModule) StreamSendRaw(mode uint8, subject, descriptor, label string, msg *rtapi.Envelope) error {
	stream := PresenceStream{
		Mode:  mode,
		Label: label,
	}
	var err error
	if subject != "" {
		stream.Subject, err = uuid.FromString(subject)
		if err != nil {
			return errors.New("stream subject must be a valid identifier")
		}
	}
	if descriptor != "" {
		stream.Descriptor, err = uuid.FromString(descriptor)
		if err != nil {
			return errors.New("stream descriptor must be a valid identifier")
		}
	}
	if msg == nil {
		return errors.New("expects a valid message")
	}

	n.router.SendToStream(n.logger, stream, msg)

	return nil
}

func (n *RuntimeGoNakamaModule) MatchCreate(ctx context.Context, module string, params map[string]interface{}) (string, error) {
	if module == "" {
		return "", errors.New("expects module name")