Example #1
0
func (server *Server) wsSubscribe(conn *websocket.Conn, p *proto.Proto) (userid int64, topics []int32, token string, err error) {
	if err = p.ReadWebsocket(conn); err != nil {
		return
	}
	if p.OpCode != define.OP_SUB_REQ {
		err = ErrOperation
		return
	}

	sub := new(proto.SubREQ)
	err = ffjson.Unmarshal(p.Body, sub)
	if err != nil {
		return
	}
	sub.Server = server.Config.Id
	if err = server.Subscribe(sub); err != nil {
		return
	}
	userid = sub.UserId
	topics = sub.Topics
	token = sub.Token
	p.Body = nil
	p.OpCode = define.OP_SUB_RES
	err = p.WriteWebsocket(conn)
	return
}
Example #2
0
func (server *Server) pushWebSocket(p *proto.Proto, conn *websocket.Conn) (err error) {

	err = p.WriteWebsocket(conn)
	//log.Debugln(p)
	if err == nil {
		if p.Ensure {
			// if failed : message will be send next time
			server.pushRpc.PushEnsure(p)
		}
	}
	return err
}