Beispiel #1
0
func (h *streamHandler) onDefault(name string, callback float64, r *amf0.Reader) error {
	if p := h.publish.p; p == nil {
		xlog.OutLog.Printf("[session]: xid = %d, reader.fid = %d, writer.fid = %d, message on non-published stream\n", h.session.xid, h.fr.fid, h.fw.fid)
		return nil
	} else if p.rpc {
		xlog.OutLog.Printf("[session]: xid = %d, reader.fid = %d, writer.fid = %d, unhandled call on rpc stream\n", h.session.xid, h.fr.fid, h.fw.fid)
		return nil
	} else {
		if w, err := newAmfBytesWriter(name); err != nil {
			return errors.New("stream.onAmfData.write name")
		} else if err := w.WriteBytes(r.Bytes()); err != nil {
			return errors.New("stream.onAmfData.write body")
		} else {
			data := split(w.Bytes())
			call := func(x *streamHandler) {
				s := x.session
				s.Lock()
				defer s.Unlock()
				if s.closed || x.play.p != p {
					return
				}
				defer s.flush()
				x.fw.AddFragments(p.reliable, data...)
			}
			async.Call(p.gid, func() {
				if l, ok := p.list(); ok && l != nil {
					for e := l.Front(); e != nil; e = e.Next() {
						call(e.Value.(*streamHandler))
					}
				}
			})
		}
		return nil
	}
}
Beispiel #2
0
func (h *streamHandler) onBroadcastByXid(callback float64, r *amf0.Reader, reliable bool) error {
	if s, err := r.ReadString(); err != nil {
		return errors.New("stream.onBroadcastByXid.read xids")
	} else if len(s) == 0 {
		return nil
	} else {
		xids := make([]uint32, 0, 32)
		for _, v := range strings.Split(s, "_") {
			if x, err := strconv.ParseInt(v, 10, 64); err != nil {
				return errors.New("stream.onBroadcastByXid.parse xid")
			} else {
				xids = append(xids, uint32(x))
			}
		}
		BroadcastByXid(xids, r.Bytes(), h.session.xid, reliable)
		return nil
	}
}
Beispiel #3
0
func (h *connHandler) onRelay(callback float64, r *amf0.Reader) error {
	if pidss, err := r.ReadString(); err != nil {
		return errors.New("conn.onRelay.read pid")
	} else if pidbs, err := hex.DecodeString(pidss); err != nil || len(pidbs) != 0x20 {
		return errors.New("conn.onRelay.decode pid")
	} else if bs, err := newRelayMessage(h.session.pid, r.Bytes()); err != nil {
		return errors.New("conn.onRelay.generate response")
	} else {
		async.Call(uint64(h.session.xid), func() {
			if s := FindByPid(string(pidbs)); s != nil {
				s.Lock()
				defer s.Unlock()
				if s.closed {
					return
				}
				defer s.flush()
				if fw := s.mainfw; fw != nil {
					fw.AddFragments(true, split(bs)...)
				}
			}
		})
		return nil
	}
}
Beispiel #4
0
func (h *streamHandler) onProxySend(callback float64, r *amf0.Reader, reliable bool) error {
	rpc.Call(h.session.xid, h.session.raddr, 0, r.Bytes(), reliable)
	return nil
}
Beispiel #5
0
func (h *connHandler) onRequest(callback float64, r *amf0.Reader) error {
	rpc.Call(h.session.xid, h.session.raddr, callback, r.Bytes(), true)
	return nil
}