func discover(flags *Args) { port := fmt.Sprintf("%d", *flags.discoveryPort) if mgr, err := sonos.Discover(*flags.discoveryDevice, port); nil != err { panic(err) } else { query := ssdp.ServiceQueryTerms{ ssdp.ServiceKey(sonos.MUSIC_SERVICES): -1, ssdp.ServiceKey(sonos.RECIVA_RADIO): -1, } res := mgr.QueryServices(query) if dev_list, has := res[sonos.MUSIC_SERVICES]; has { for _, dev := range dev_list { if sonos.SONOS == dev.Product() { fmt.Printf("%s %s\n", string(dev.UUID()), dev.Location()) CONFIG.AddBookmark(string(dev.UUID()), dev.Product(), dev.Location(), dev.UUID()) } } } if dev_list, has := res[sonos.RECIVA_RADIO]; has { for _, dev := range dev_list { if sonos.RADIO == dev.Product() { fmt.Printf("%s %s\n", string(dev.UUID()), dev.Location()) CONFIG.AddBookmark(string(dev.UUID()), dev.Product(), dev.Location(), dev.UUID()) } } } } }
func TestIssue_4(t *testing.T) { log.SetFlags(log.Ltime | log.Lshortfile) log.Printf("Discovery: Starting") mgr, err := sonos.Discover(13104) if nil != err { panic(err) } log.Printf("Discovery: Done; Reactor: Starting") reactor := sonos.MakeReactor(13106) go read_events(reactor.Channel()) ///// <------------ log.Printf("Reactor: Running; Query: Starting") qry := ssdp.ServiceQueryTerms{ ssdp.ServiceKey(sonos.MUSIC_SERVICES): -1, } res := mgr.QueryServices(qry) log.Printf("Query: Done; Connect: Starting") if dev_list, has := res[sonos.MUSIC_SERVICES]; has { for _, dev := range dev_list { if sonos.SONOS == dev.Product() { if _, err := upnp.Describe(dev.Location()); nil != err { panic(err) } else { sonos.Connect(dev, reactor, sonos.SVC_ALL) log.Printf("Connect: Done") break } } } } }
func ConnectAnyReciva(mgr ssdp.Manager, reactor upnp.Reactor, flags int) (reciva []*Reciva) { qry := ssdp.ServiceQueryTerms{ ssdp.ServiceKey(RECIVA_RADIO): -1, } res := mgr.QueryServices(qry) if dev_list, has := res[RECIVA_RADIO]; has { for _, dev := range dev_list { if RADIO == dev.Product() { if svc_map, err := upnp.Describe(dev.Location()); nil != err { panic(err) } else { reciva = append(reciva, MakeReciva(svc_map, reactor, flags)) } break } } } return }
func ConnectAny(mgr ssdp.Manager, reactor upnp.Reactor, flags int) (sonos []*Sonos) { qry := ssdp.ServiceQueryTerms{ ssdp.ServiceKey(MUSIC_SERVICES): -1, } res := mgr.QueryServices(qry) if dev_list, has := res[MUSIC_SERVICES]; has { for _, dev := range dev_list { if SONOS == dev.Product() { if svc_map, err := upnp.Describe(dev.Location()); nil != err { panic(err) } else { sonos = append(sonos, MakeSonos(svc_map, reactor, flags)) } break } } } return }