Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf022066

Browse files
authored
Merge pull requestFirebaseExtended#294 from proppy/fix-stream
FirebaseArduino: allow mixing stream and non-stream commands
2 parentsc73ca0e +d62b9cb commitf022066

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

‎src/Firebase.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth,
9292
constchar* method,const std::string& path,
9393
const std::string& data, FirebaseHttpClient* http) : http_(http) {
9494
std::string path_with_auth =makeFirebaseURL(path, auth);
95+
if ((method =="STREAM") && (path == http->getStreamingPath())){
96+
// already streaming requested path.
97+
return;
98+
}
99+
if (http_->isStreaming()) {
100+
// closing streaming connection.
101+
http_->setReuseConnection(false);
102+
http_->end();
103+
}
95104
http_->setReuseConnection(true);
96105
http_->begin(host, path_with_auth);
97106

@@ -130,11 +139,14 @@ FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth,
130139
// if not streaming.
131140
if (!followRedirect) {
132141
response_ = http_->getString();
142+
http_->setStreaming("");
143+
}else {
144+
http_->setStreaming(path);
133145
}
134146
}
135147

136148
FirebaseCall::~FirebaseCall() {
137-
if (http_) {
149+
if (http_ && !http_->isStreaming()) {
138150
http_->end();
139151
}
140152
}
@@ -189,6 +201,9 @@ FirebaseStream::FirebaseStream(const std::string& host, const std::string& auth,
189201
}
190202

191203
boolFirebaseStream::available() {
204+
if (http_->getStreamPtr() ==nullptr) {
205+
returnfalse;
206+
}
192207
return http_->getStreamPtr()->available();
193208
}
194209

‎src/FirebaseArduino.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ void FirebaseArduino::stream(const String& path) {
131131
}
132132

133133
boolFirebaseArduino::available() {
134+
if (http_->getStreamPtr() ==nullptr) {
135+
returnfalse;
136+
}
134137
return http_->getStreamPtr()->available();
135138
}
136139

‎src/FirebaseArduino.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ class FirebaseArduino {
189189
* You should check success() after calling.
190190
* This changes the state of this object. Once this is called you may start
191191
* monitoring available() and calling readEvent() to get new events.
192-
* WARNING: Currently you cannot make another call while the stream is
193-
* running, otherwise you will crash due to memory issues. See:
194-
* https://github.com/googlesamples/firebase-arduino/issues/48
195192
* \param path The path inside of your db to the node you wish to monitor.
196193
*/
197194
voidstream(const String& path);

‎src/FirebaseHttpClient.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,18 @@ class FirebaseHttpClient {
3333

3434
virtual std::stringerrorToString(int error_code) = 0;
3535

36+
boolisStreaming()const {
37+
return _streaming !="";
38+
}
39+
std::stringgetStreamingPath()const {
40+
return _streaming;
41+
}
42+
voidsetStreaming(const std::string& path) {
43+
_streaming = path;
44+
}
3645
protected:
46+
std::string _streaming ="";
47+
3748
staticconstuint16_tkFirebasePort =443;
3849
};
3950

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp