Skip to content

Commit 5f3a11e

Browse files
committed
2 parents 47f4ea8 + abd286e commit 5f3a11e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/App.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ export default {
4949
connected: false,
5050
},
5151
connection: {
52+
protocol: location.protocol == "https:" ? "wss" : "ws",
5253
host: location.hostname,
53-
port: 9001,
54+
port: location.protocol == "https:" ? 9002 : 9001,
5455
endpoint: "/",
5556
connectTimeout: 4000,
5657
reconnectPeriod: 4000,
@@ -157,16 +158,17 @@ export default {
157158
* Establishes a connection to the configured broker
158159
*/
159160
createConnection() {
160-
console.debug("connecting to broker...");
161161
// Connect string, and specify the connection method used through protocol
162162
// ws not encrypted WebSocket connection
163163
// wss encrypted WebSocket connection
164164
// mqtt not encrypted TCP connection
165165
// mqtts encrypted TCP connection
166166
// wxs WeChat mini app connection
167167
// alis Alipay mini app connection
168-
const { host, port, endpoint, ...options } = this.connection;
169-
const connectUrl = `ws://${host}:${port}${endpoint}`;
168+
const { protocol, host, port, endpoint, ...options } =
169+
this.connection;
170+
const connectUrl = `${protocol}://${host}:${port}${endpoint}`;
171+
console.debug("connecting to broker:", connectUrl);
170172
try {
171173
this.client = mqtt.connect(connectUrl, options);
172174
} catch (error) {

0 commit comments

Comments
 (0)