-
Notifications
You must be signed in to change notification settings - Fork 3
/
meteor-connection.html
78 lines (68 loc) · 1.71 KB
/
meteor-connection.html
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
<!--
This element manage and inspect the network connection between the Meteor client and server.
Example:
<meteor-connection connected={{conn}} on-server-disconnected="_onDisconnect"></meteor-connection>
<template is="dom-if" if="{{conn}}">
<div>Meteor server is connected</div>
</template>
-->
<script>
Polymer({
is: 'meteor-connection',
/**
* Fired when the connection is established.
*
* @event server-connected
*/
/**
* Fired when the server is disconnected.
*
* @event server-disconnected
*/
properties: {
/**
* Meteor status object.
*/
status: {
type: Object,
notify: true,
readOnly: true
},
/**
* the connected field from the status object.
*/
connected: {
type: Boolean,
notify: true,
readOnly: true,
value: false
}
},
/**
* Disconnect the client from the server.
*/
disconnect: function() {
Meteor.disconnect();
},
/**
* Force an immediate reconnection attempt if the client is not connected to the server.
*/
reconnect: function() {
Meteor.reconnect();
},
ready: function() {
this._computation = Tracker.autorun(function() {
var status = Meteor.status();
if (this.connected != status.connected) {
this.fire(status.connected ? 'server-connected' : 'server-disconnected', { status: status });
}
this._setStatus(status);
this._setConnected(status.connected);
}.bind(this));
},
detached: function() {
if (this._computation)
this._computation.stop();
},
});
</script>