Skip to content

Commit d7d65fd

Browse files
committed
Preparation for automatic websocket server time
1 parent be010a7 commit d7d65fd

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

push/WebsocketPush.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,5 @@ void CWebSocketPush::OnNotificationReceived(const std::string & Subject, const s
119119
}
120120

121121
// push message to websocket
122-
m_sock->OnMessage(Subject, Text, ExtraData, Priority, Sound, bFromNotification);
122+
m_sock->SendNotification(Subject, Text, ExtraData, Priority, Sound, bFromNotification);
123123
}

webserver/WebsocketHandler.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ namespace http {
169169
}
170170
}
171171

172-
void CWebsocketHandler::OnMessage(const std::string &Subject, const std::string &Text, const std::string &ExtraData, const int Priority, const std::string &Sound, const bool bFromNotification)
172+
void CWebsocketHandler::SendNotification(const std::string &Subject, const std::string &Text, const std::string &ExtraData, const int Priority, const std::string &Sound, const bool bFromNotification)
173173
{
174174
Json::Value json;
175175

@@ -184,5 +184,17 @@ namespace http {
184184
MyWrite(response);
185185
}
186186

187+
void CWebsocketHandler::SendDateTime(const std::string& ServerTime, const std::string& Sunrise, const std::string& Sunset)
188+
{
189+
Json::Value json;
190+
191+
json["event"] = "date_time";
192+
json["ServerTime"] = ServerTime;
193+
json["Sunrise"] = Sunrise;
194+
json["Sunset"] = Sunset;
195+
std::string response = json.toStyledString();
196+
MyWrite(response);
197+
}
198+
187199
}
188200
}

webserver/WebsocketHandler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace http {
1818
virtual void Start();
1919
virtual void Stop();
2020
virtual void OnDeviceChanged(const uint64_t DeviceRowIdx);
21-
virtual void OnMessage(const std::string &Subject, const std::string &Text, const std::string &ExtraData, const int Priority, const std::string &Sound, const bool bFromNotification);
21+
virtual void SendNotification(const std::string& Subject, const std::string& Text, const std::string& ExtraData, const int Priority, const std::string& Sound, const bool bFromNotification);
22+
virtual void SendDateTime(const std::string& ServerTime, const std::string& Sunrise, const std::string& Sunset);
2223
virtual void store_session_id(const request &req, const reply &rep);
2324
protected:
2425
boost::function<void(const std::string &packet_data)> MyWrite;

www/app/livesocket.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ define(['app', 'angular-websocket'], function (app) {
9494
case "notification":
9595
notifyBrowser.notify(msg.Subject, msg.Text);
9696
return;
97+
case "date_time":
98+
//alert("ServerTime: " + msg.ServerTime + ", Sunrise: " + msg.Sunrise + ", Sunset: " + msg.Sunset);
99+
$rootScope.SetTimeAndSun(msg.Sunrise, msg.Sunset, msg.ServerTime);
100+
return;
97101
}
98102
var requestid = msg.requestid;
99103
if (requestid >= 0) {

0 commit comments

Comments
 (0)