-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathchannel_groups.html
More file actions
93 lines (77 loc) · 2.18 KB
/
channel_groups.html
File metadata and controls
93 lines (77 loc) · 2.18 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<html>
<head>
<script type="text/javascript" src="../eon-chart.js"></script>
</head>
<body>
<div id="chart"></div>
<script>
var pubnub = new PubNub({
publishKey: 'demo',
subscribeKey: 'demo'
});
var channels = ['pubnub-c3-1', 'pubnub-c3-2', 'pubnub-c3-3'];
// create channel group
pubnub.channelGroups.addChannels(
{
channels: channels,
channelGroup: "pubnub-c3-example"
},
function(status) {
if (status.error) {
console.log("operation failed w/ status: ", status);
} else {
console.log("operation done!")
// list channels
pubnub.channelGroups.listChannels(
{
channelGroup: "pubnub-c3-example"
},
function (status, response) {
if (status.error) {
console.log("operation failed w/ error:", status);
return;
}
console.log("listing push channel for device")
response.channels.forEach( function (channel) {
console.log(channel)
})
}
);
}
}
);
eon.chart({
channelGroups: ['pubnub-c3-example'],
history: true,
flow: true,
pubnub: pubnub,
connect: connect,
generate: {
bindto: '#chart',
data: {
type: 'spline',
labels: false
}
}
});
function publish(pointId, channel) {
var m = {
eon:{}
};
m.eon[pointId] = Math.floor(Math.random() * 99);
pubnub.publish({
channel: channel,
message: m
});
}
function connect() {
console.log('connect')
setInterval(function(){
publish('first', channels[0]);
publish('second', channels[1]);
publish('third', channels[2]);
}, 1000);
};
</script>
</body>
</html>