-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample.cpp
76 lines (59 loc) · 1.41 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "pushcpp.h"
#include <iostream>
using namespace std;
void cn_ev(const pushcpp::ConnectionEvent ev);
void er_ev(const int code, const std::string &msg);
pushcpp pp("my-api-key", cn_ev, er_ev);
void cn_ev(const pushcpp::ConnectionEvent ev)
{
printf("ConnectEvent: %d\n", ev);
pp.send("channel", "pusher:subscribe", "lol");
}
void er_ev(const int code, const std::string &msg)
{
cout << "Error from pusher: " << code << " " << msg << endl;
}
void sub_ev(
const string &channel,
const string &event,
const string &data
)
{
// cout << pp.subscriptions().size() << endl;
printf("Received event %s on channel %s: %s\n",
event.c_str(), channel.c_str(), data.c_str());
auto cd = pp.subscriptions();
cout << "Subs: " << endl;
for (
auto it = cd.begin();
it != cd.end();
it++
) {
cout << "Subscription: " << it->first <<
" status: " << it->second.subscribed <<
" members: " << it->second.presenceMemberIds.size() <<
endl;
}
// for (auto it = ChannelData
pp.unsubscribe(channel);
cd = pp.subscriptions();
cout << "Subs: " << endl;
for (
auto it = cd.begin();
it != cd.end();
it++
) {
cout << "Subscription: " << it->first <<
" status: " << it->second.subscribed <<
" members: " << it->second.presenceMemberIds.size() <<
endl;
}
// cout << pp.subscriptions().size() << endl;
}
int main()
{
pp.subscribe("my_channel", sub_ev);
pp.connect();
pp.join();
return 0;
}