func Session(s stream.Stream) (err error) { iq := entity.IQ(entity.SET, &entity.SessionPrototype) if err = s.Write(entity.ProduceStatic(iq)); err == nil { s.Ring(func(b *bytes.Buffer) (done bool) { var _e entity.Entity if _e, err = entity.ConsumeStatic(b); err == nil { switch e := _e.(type) { case *entity.Iq: switch { case e.Id == iq.Id && e.Type == entity.RESULT: done = true } default: log.Println(reflect.TypeOf(e)) } } return }, 0) } return }
func Starter(s stream.Stream) (err error) { if err = s.Write(entity.Open(s.Server()).Produce()); err == nil { s.Ring(func(b *bytes.Buffer) (done bool) { _e, e := entity.ConsumeStatic(b) if _e != nil { switch e := _e.(type) { case *entity.Stream: s.Id(e.Id) done = true default: log.Println(reflect.TypeOf(e)) } } else if e == nil { err = errors.New(fmt.Sprint("unknown entity ", string(b.Bytes()))) } else { err = e } return }, 0) } return }
func InitialPresence(s stream.Stream) (err error) { err = s.Write(entity.ProduceStatic(&entity.PresencePrototype)) return }