forked from JTMCaplin/DamJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubscriberElement.js
61 lines (58 loc) · 1.65 KB
/
SubscriberElement.js
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
define(["lib/react"], function (React) {
return React.createClass({
subscribe: function () {
var streamlink;
// >= StreamLinkTS 7.1.12
if (window.caplin.streamlink.getVersion) {
streamlink = caplin.streamlink;
// <= StreamLinkJS 7.0.4
} else {
if (typeof damJSStreamLink === "undefined") {
alert("Make a real subscription first!");
return;
}
streamlink = window.damJSStreamLink;
}
streamlink.subscribe(this.state.subject, {
onSubscriptionStatus: function (subscription, event) {
console.log(
subscription.getSubject() + " is now " + event.getStatus()
);
},
onSubscriptionError: function (subscription, event) {
console.log(
"Error: Subject " +
subscription.getSubject() +
" is " +
event.getError()
);
},
onRecordUpdate: function (subscription, event) {
console.log(
event.getSubject(),
JSON.parse(JSON.stringify(event.getFields()))
);
},
});
},
getInitialState: function () {
return { subject: "/FX/EURUSD/SPOT/EUR/100" };
},
setSubject: function (e) {
this.setState({
subject: e.target.value,
});
},
render: function () {
return React.DOM.div(
{},
React.DOM.button({ onClick: this.props.back }, "Back"),
React.DOM.input({
value: this.state.subject,
onChange: this.setSubject,
}),
React.DOM.button({ onClick: this.subscribe }, "Subscribe")
);
},
});
});