Skip to content

Commit 4bb8ae3

Browse files
committed
updating demo to use credentials
1 parent 332fd25 commit 4bb8ae3

File tree

1 file changed

+52
-17
lines changed

1 file changed

+52
-17
lines changed

demo/elements/demo-element.html

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
connected="{{connected}}"
2323
client="{{client}}"
2424
subscriptions="{{subscriptions}}"
25+
options='{{options}}'
2526
on-mqtt-message="_handelMqttMessage">
2627

2728
<!--create a mqtt subscription for every item in topics-->
@@ -59,6 +60,15 @@ <h3>Status:</h3>
5960
<!--buttons to connect or disconnect the connection-->
6061
<paper-button raised on-tap="connect">connect</paper-button>
6162
<paper-button raised on-tap="disconnect">disconnect</paper-button>
63+
<paper-icon-button on-tap="_showOptions"
64+
icon="icons:settings"
65+
alt="show options"
66+
title="show options"></paper-icon-button>
67+
</div>
68+
<div hidden$="{{!showOptions}}" class="horizontal-section-container">
69+
<h3>Credentials</h3>
70+
<paper-input label="username" value="{{username}}"></paper-input>
71+
<paper-input label="password" value="{{password}}"></paper-input>
6272
</div>
6373
</div>
6474

@@ -146,7 +156,10 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
146156
is: 'demo-element',
147157

148158
properties: {
149-
159+
showOptions: {
160+
type: Boolean,
161+
value: false,
162+
},
150163

151164
url: {
152165
type: String,
@@ -166,30 +179,60 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
166179
topics: {
167180
type: Array,
168181
value: function () {
169-
return [{topic: "foo/bar", qos:0}, {topic: "mqttjs/elements", qos:1}];
182+
return [];
170183
},
171184
},
172185

173-
publishTopics: {
174-
type: Array,
175-
value: function () {
176-
return ["foo/bar"];
177-
},
186+
options: {
187+
type: Object,
188+
computed: "_computeOptions(username, password)",
189+
},
190+
191+
username: {
192+
type: String,
193+
},
194+
195+
password: {
196+
type: String,
178197
},
179198
},
180199

200+
observers: [],
201+
202+
_computeOptions: function (username, password) {
203+
console.log("_computeOptions", arguments);
204+
var _options = {
205+
protocolId: "MQTT",
206+
protocolVersion: 4,
207+
keepalive: 10,
208+
reconnectPeriod: 1000,
209+
clientId: "",
210+
encoding: "string",
211+
};
212+
213+
if(username && username.length > 0 && password && password.length > 0) {
214+
_options.username = username;
215+
_options.password = password;
216+
}
217+
218+
return _options;
219+
},
220+
221+
_showOptions: function () {
222+
this.showOptions = !this.showOptions;
223+
},
224+
181225
_sendMessage: function (event) {
182226
this.$.pub.publish();
183227
},
184228

185229
_addSub: function () {
186-
if (this.newSubTopic.length > 0){
230+
if(this.newSubTopic.length > 0) {
187231
this.push("topics", {topic: this.newSubTopic, qos: this.subQos});
188232
}
189233
},
190234

191235
_handelMqttMessage: function (event, message) {
192-
193236
if(message && message.topic) {
194237
this.push('messages', {
195238
topic: message.topic,
@@ -198,14 +241,6 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
198241
}
199242
},
200243

201-
parseMessage: function (message) {
202-
return String.fromCharCode.apply(null, message.message.payload);
203-
},
204-
205-
toWsUrl: function (url, port) {
206-
return "ws://" + url + ":" + port;
207-
},
208-
209244
disconnect: function () {
210245
this.$.connection.disconnect();
211246
},

0 commit comments

Comments
 (0)