Files
goSam/sessions.go

46 lines
848 B
Go
Raw Normal View History

package goSam
import (
"fmt"
// "math"
"math/rand"
2015-02-05 11:52:28 +01:00
"time"
)
2015-02-05 11:52:28 +01:00
func init() {
rand.Seed(time.Now().UnixNano())
}
2014-02-14 12:05:13 +01:00
// CreateStreamSession creates a new STREAM Session.
// Returns the Id for the new Client.
func (c *Client) CreateStreamSession(id int32, dest string) (string, error) {
if dest == "" {
dest = "TRANSIENT"
}
c.id = id
2019-02-24 23:08:01 -05:00
r, err := c.sendCmd(
2019-03-28 00:21:04 -04:00
"SESSION CREATE STYLE=STREAM ID=%d %s %s DESTINATION=%s %s %s\n",
c.id,
2019-04-25 23:45:24 -04:00
c.from(),
c.to(),
2019-02-24 23:08:01 -05:00
dest,
c.sigtype(),
c.allOptions(),
)
if err != nil {
return "", err
}
2015-03-25 22:03:05 +01:00
// TODO: move check into sendCmd()
if r.Topic != "SESSION" || r.Type != "STATUS" {
return "", fmt.Errorf("Unknown Reply: %+v\n", r)
}
result := r.Pairs["RESULT"]
if result != "OK" {
return "", ReplyError{ResultKeyNotFound, r}
}
c.destination = r.Pairs["DESTINATION"]
return c.destination, nil
}