Skip to content

Commit 1d902fb

Browse files
committedMar 12, 2018
Send support
1 parent 3fdf6be commit 1d902fb

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed
 

‎README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
TODO:
22
- Support server response
33
- Figure out nice send (params in c#)
4+
- Stream support
5+
- .On() callbacks
46
- Add Protocol layer (but only have json support for now)
5-
- Move project to library with sample application
7+
- Move project to library with sample application
8+
- Headers
9+
- Logging
10+
- Tests

‎src/signalrcorelib/HubConnection.cpp

+22-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace signalr
99
enum MessageType
1010
{
1111
Negotiation = 0,
12-
Invocation,
12+
Invocation = 1,
1313
StreamInvocation,
1414
StreamItem,
1515
Completion,
@@ -28,22 +28,29 @@ namespace signalr
2828
switch (messageType.as_integer())
2929
{
3030
case MessageType::Negotiation:
31+
// unused...
3132
break;
3233
case MessageType::Invocation:
3334
{
3435
auto method = value[L"target"];
3536
auto args = value[L"arguments"];
37+
_ASSERT(args.is_array());
3638
break;
3739
}
3840
case MessageType::StreamInvocation:
39-
break;
41+
// Sent to server only, should not be received by client
42+
throw std::runtime_error("Received unexcepted message type 'StreamInvocation'.");
4043
case MessageType::StreamItem:
44+
// TODO
4145
break;
4246
case MessageType::Completion:
47+
// TODO
4348
break;
4449
case MessageType::CancelInvocation:
45-
break;
50+
// Sent to server only, should not be received by client
51+
throw std::runtime_error("Received unexcepted message type 'CancelInvocation'.");
4652
case MessageType::Ping:
53+
// TODO
4754
break;
4855
}
4956
});
@@ -63,16 +70,20 @@ namespace signalr
6370
return mTransport->Stop();
6471
}
6572

66-
pplx::task<void> HubConnection::SendCore(const utility::string_t& message)
73+
pplx::task<void> HubConnection::Send(const utility::string_t& target, const utility::string_t& arguments)
6774
{
68-
//_ASSERT(message.is_array());
69-
//web::json::value invocation;
70-
//invocation[L"type"] = web::json::value::value(1);
71-
//invocation[L"target"] = web::json::value::string(target);
72-
//invocation[L"arguments"] = message;
75+
auto args = web::json::value::parse(arguments);
76+
_ASSERT(args.is_array());
7377

74-
//auto request = web::websockets::client::websocket_outgoing_message();
75-
//request.set_utf8_message(utility::conversions::to_utf8string(invocation.serialize()) + "\x1e");
78+
web::json::value invocation;
79+
invocation[L"type"] = web::json::value::value(MessageType::Invocation);
80+
invocation[L"target"] = web::json::value::string(target);
81+
invocation[L"arguments"] = args;
82+
return SendCore(invocation.serialize() + L"\x1e");
83+
}
84+
85+
pplx::task<void> HubConnection::SendCore(const utility::string_t& message)
86+
{
7687
return mTransport->Send(message);
7788
}
7889

‎src/signalrcorelib/HubConnection.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ namespace signalr
1212
class HubConnection
1313
{
1414
public:
15-
HubConnection(const utility::string_t& url, Transport transport);
15+
HubConnection(const utility::string_t& url, Transport transport = Transport::WebSockets);
1616
pplx::task<void> Start();
1717
pplx::task<void> Stop();
1818
//On
1919
//Stream
2020
//Invoke
21-
//pplx::task<void> Send(const utility::string_t& method, );
21+
pplx::task<void> Send(const utility::string_t& target, const utility::string_t& arguments = L"");
2222

2323
~HubConnection();
2424
private:

‎src/signalrcorelib/Source.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main(void)
1818
web::json::value args{};
1919
args[0] = web::json::value(utility::conversions::to_string_t(msg));
2020

21-
//hubConnection.Send(L"Send", args);
21+
hubConnection.Send(L"Send", args.serialize());
2222
}
2323

2424
hubConnection.Stop().wait();

‎src/signalrcorelib/WebSocketsTransport.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace signalr
1818
{
1919
uri.set_scheme(L"wss");
2020
}
21+
else
22+
{
23+
//???
24+
}
2125
mUrl = uri.to_string();
2226
}
2327

0 commit comments

Comments
 (0)
Please sign in to comment.