Comments (5)
Do you mean Stream.[sS]end()? If so, it's not quite as simple as making send() public as the Stream instance is hidden behind the an XMPP's In and Out channels.
I have no real objection to allowing a []byte stanza if it's useful. Do you have a particular use case for it? Note that it does give the application the ability to really mess up the underlying XML stream, but that's the application's fault ;).
from go-xmpp-atomatt.
My need is to provide in my component a "console mode" that sends custom XML stanza read from STDIN. Very useful to dev/debug.
Here the code to do that in my app:
go func() {
fmt.Printf("Console = On\n")
reader := bufio.NewReader(os.Stdin)
lines := []string{}
for {
line, err := reader.ReadString('\n')
if err != nil {
fmt.Printf(err.Error())
lines = []string{}
continue
}
if line == "\n" { // empty line found, sends XML stanza !
stanza := strings.Join(lines, "")
lines = []string{}
if strings.Trim(stanza, "\n") != "" {
go stream.SendRaw([]byte(stanza))
}
} else {
lines = append(lines, line)
}
}
}()
With this simple change in go-xmpp/src/xmpp/stream.go
func (stream *Stream) SendRaw(b []byte) error {
return stream.send(b)
}
I agree with the application's responsibility in case of invalid stanza, but hey, "With great power comes great responsibility" ! :-)
from go-xmpp-atomatt.
Sorry for sitting on this for so long. I think you're right - it won't hurt to expose a method to send a complete stanza. However the current code is slightly wrong (mostly in terms of debug logging) at the moment. I'll see what I can do.
Just something I noticed about the above example … a XML stream is inherently sequential and xmpp.Stream does nothing to serialise access to the stream, so starting a new goroutine for each stanza - go stream.SendRaw([]byte(stanza)) - could result in things getting mixed up.
from go-xmpp-atomatt.
I see. We may change the Stream.Send()
method to handle []byte
type for v
parameter in addition to classic stanza structures ? In this case the outgoing stanza flow will be preserved.
Below a patch proposal in go-xmpp/src/xmpp/stream.go
// Send a stanza. Used to write a complete, top-level element.
func (stream *Stream) Send(v interface{}) error {
bytes, ok := v.([]byte)
if ok {
return stream.send(bytes)
}
if stream.config.LogStanzas {
bytes, err := xml.Marshal(v)
if err != nil {
return err
}
return stream.send(bytes)
}
enc := xml.NewEncoder(stream.conn)
return enc.Encode(v)
}
Then i could use comp.Out <- []byte(stanza)
insted of go stream.SendRaw([]byte(stanza))
from go-xmpp-atomatt.
Opened issue for too long. I close it since I do not work with this library any more.
from go-xmpp-atomatt.
Related Issues (8)
- Scale with more CPU HOT 4
- throughput.go terminates with high load HOT 1
- Iq.PayloadName() fails if payload starts with \n HOT 1
- Dealing with <message> XEPs HOT 1
- Fatal error when incoming stanza has a xml:lang attribute and LogStanzas is true HOT 1
- JID parsing allows invalid JIDs
- SCRAM-SHA-1(-PLUS) + SCRAM-SHA-224(-PLUS) + SCRAM-SHA-256(-PLUS) + SCRAM-SHA-384(-PLUS) + SCRAM-SHA-512(-PLUS) + SCRAM-SHA3-512(-PLUS) supports HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-xmpp-atomatt.