Beispiel #1
0
func (h *hub) processReqEnqueue(req baps3.Message) (resps []*baps3.Message) {
	args := req.Args()
	if len(args) != 4 {
		return makeBadCommandMsgs()
	}
	iStr, hash, itemType, data := args[0], args[1], args[2], args[3]

	i, err := strconv.Atoi(iStr)
	if err != nil {
		return append(resps, baps3.NewMessage(baps3.RsWhat).AddArg("Bad index"))
	}

	if itemType != "file" && itemType != "text" {
		return append(resps, baps3.NewMessage(baps3.RsWhat).AddArg("Bad item type"))
	}

	oldSelection := h.pl.selection
	item := &PlaylistItem{Data: data, Hash: hash, IsFile: itemType == "file"}
	newIdx, err := h.pl.Enqueue(i, item)
	if err != nil {
		return append(resps, baps3.NewMessage(baps3.RsFail).AddArg(err.Error()))
	}
	if oldSelection != h.pl.selection {
		resps = append(resps, baps3.NewMessage(baps3.RsSelect).AddArg(strconv.Itoa(h.pl.selection)).AddArg(h.pl.items[h.pl.selection].Hash))
	}
	return append(resps, baps3.NewMessage(baps3.RsEnqueue).AddArg(strconv.Itoa(newIdx)).AddArg(item.Hash).AddArg(itemType).AddArg(item.Data))
}
Beispiel #2
0
func (h *hub) processReqSelect(req baps3.Message) (resps []*baps3.Message) {
	args := req.Args()
	if len(args) == 0 {
		if h.pl.HasSelection() {
			// Remove current selection
			h.cReqCh <- *baps3.NewMessage(baps3.RqEject)
			h.pl.selection = -1
			resps = append(resps, baps3.NewMessage(baps3.RsSelect))
		} else {
			// TODO: Should we care about there not being an existing selection?
			resps = append(resps, baps3.NewMessage(baps3.RsFail).AddArg("No selection to remove"))
		}
	} else if len(args) == 2 {
		iStr, hash := args[0], args[1]

		i, err := strconv.Atoi(iStr)
		if err != nil {
			return append(resps, baps3.NewMessage(baps3.RsWhat).AddArg("Bad index"))
		}

		newIdx, newHash, err := h.pl.Select(i, hash)
		if err != nil {
			return append(resps, baps3.NewMessage(baps3.RsFail).AddArg(err.Error()))
		}

		h.cReqCh <- *baps3.NewMessage(baps3.RqLoad).AddArg(h.pl.items[h.pl.selection].Data)
		resps = append(resps, baps3.NewMessage(baps3.RsSelect).AddArg(strconv.Itoa(newIdx)).AddArg(newHash))
	} else {
		resps = makeBadCommandMsgs()
	}
	return
}
Beispiel #3
0
func (h *hub) processReqDequeue(req baps3.Message) (resps []*baps3.Message) {
	args := req.Args()
	if len(args) != 2 {
		return makeBadCommandMsgs()
	}
	iStr, hash := args[0], args[1]

	i, err := strconv.Atoi(iStr)
	if err != nil {
		return append(resps, baps3.NewMessage(baps3.RsWhat).AddArg("Bad index"))
	}

	oldSelection := h.pl.selection
	rmIdx, rmHash, err := h.pl.Dequeue(i, hash)
	if err != nil {
		return append(resps, baps3.NewMessage(baps3.RsFail).AddArg(err.Error()))
	}
	if oldSelection != h.pl.selection {
		if !h.pl.HasSelection() {
			resps = append(resps, baps3.NewMessage(baps3.RsSelect))
		} else {
			resps = append(resps, baps3.NewMessage(baps3.RsSelect).AddArg(strconv.Itoa(h.pl.selection)).AddArg(h.pl.items[h.pl.selection].Hash))
		}
	}
	return append(resps, baps3.NewMessage(baps3.RsDequeue).AddArg(strconv.Itoa(rmIdx)).AddArg(rmHash))
}
Beispiel #4
0
func (h *hub) processReqAutoadvance(req baps3.Message) (msgs []*baps3.Message) {
	if len(req.Args()) != 1 {
		return makeBadCommandMsgs()
	}
	onoff, _ := req.Arg(0)
	switch onoff {
	case "on":
		h.autoAdvance = true
	case "off":
		h.autoAdvance = false
	default:
		return append(msgs, baps3.NewMessage(baps3.RsWhat).AddArg("Bad argument"))
	}
	return append(msgs, h.makeRsAutoAdvance())
}