Пример #1
0
func (r *Reader) readObjectValue() (*amf.Object, error) {
	if v, err := r.Read7BitValue32(); err != nil {
		return nil, errors.New("amf3.read object.head")
	} else {
		if (v & 0x01) == 0 {
			if o, err := r.getObjectRef(int(v >> 1)); err != nil {
				return nil, err
			} else if obj, ok := o.(*amf.Object); ok {
				return obj, nil
			} else {
				return nil, errors.New("amf3.ref not object")
			}
		} else {
			if t, err := r.loadTraits(v); err != nil {
				return nil, err
			} else {
				o := amf.NewObject()
				r.addObjectRef(o)
				for e := t.infos.Front(); e != nil; e = e.Next() {
					s := e.Value.(string)
					if v, err := r.Read(); err != nil {
						return nil, errors.New("amf3.read object.body")
					} else if err := o.Set(s, v); err != nil {
						return nil, err
					}
				}
				return o, nil
			}
		}
	}
}
Пример #2
0
func (h *streamHandler) newPublishSuccessResponse(stream string, callback float64) error {
	if w, err := newAmfMessageWriter("onStatus", callback); err != nil {
		return err
	} else {
		obj := amf.NewObject()
		obj.SetString("level", "status")
		obj.SetString("code", "NetStream.Publish.Start")
		obj.SetString("description", stream+" is now published")
		if err := w.WriteObject(obj); err != nil {
			return err
		}
		h.fw.AddFragments(true, split(w.Bytes())...)
		return nil
	}
}
Пример #3
0
func (h *streamHandler) newPlayResetResponse(stream string, callback float64) error {
	if w, err := newAmfMessageWriter("onStatus", callback); err != nil {
		return err
	} else {
		obj := amf.NewObject()
		obj.SetString("level", "status")
		obj.SetString("code", "NetStream.Play.Reset")
		obj.SetString("description", "Playing and resetting "+stream)
		if err := w.WriteObject(obj); err != nil {
			return err
		}
		h.fw.AddFragments(true, split(w.Bytes())...)
		return nil
	}
}
Пример #4
0
func (h *connHandler) newCallFailedResponse(name string, callback float64) error {
	if w, err := newAmfMessageWriter("_error", callback); err != nil {
		return err
	} else {
		obj := amf.NewObject()
		obj.SetString("level", "error")
		obj.SetString("code", "NetConnection.Call.Failed")
		obj.SetString("description", "Method '"+name+"' not found")
		if err := w.WriteObject(obj); err != nil {
			return err
		}
		h.fw.AddFragments(true, split(w.Bytes())...)
		return nil
	}
}
Пример #5
0
func (h *connHandler) newAmf0RejectResponse(callback float64) error {
	if w, err := newAmfMessageWriter("_error", callback); err != nil {
		return err
	} else {
		obj := amf.NewObject()
		obj.SetString("level", "error")
		obj.SetString("code", "NetConnection.Connect.Rejected")
		obj.SetString("description", "ObjectEncoding client must be in a AMF3 format (not AMF0)")
		if err := w.WriteObject(obj); err != nil {
			return err
		}
		h.fw.AddFragments(true, split(w.Bytes())...)
		return nil
	}
}
Пример #6
0
func (h *connHandler) newSuccessResponse(callback float64, xid uint32, raddr *net.UDPAddr) error {
	if w, err := newAmfMessageWriter("_result", callback); err != nil {
		return err
	} else {
		obj := amf.NewObject()
		obj.SetString("level", "status")
		obj.SetString("code", "NetConnection.Connect.Success")
		obj.SetString("description", "Connection succeeded")
		obj.SetNumber("objectEncoding", 3.0)
		if xid != 0 {
			obj.SetNumber("sessionId", float64(xid))
		}
		if raddr != nil {
			obj.SetString("address", raddr.String())
		}
		if err := w.WriteObject(obj); err != nil {
			return err
		}
		h.fw.AddFragments(true, split(w.Bytes())...)
		return nil
	}
}
Пример #7
0
func (r *Reader) readObjectValue() (*amf.Object, error) {
	o := amf.NewObject()
	r.addObjectRef(o)
	for {
		if s, err := r.readStringValue(); err != nil {
			return nil, errors.New("amf0.read traits.info")
		} else {
			if len(s) == 0 {
				break
			}
			if v, err := r.Read(); err != nil {
				return nil, errors.New("amf0.read object.body")
			} else if err := o.Set(s, v); err != nil {
				return nil, err
			}
		}
	}
	if t, err := r.Read8(); err != nil {
		return nil, errors.New("amf0.read object.end")
	} else if t != Amf0ObjectEnd {
		return nil, errors.New("amf0.not object end")
	}
	return o, nil
}