|
|
@@ -52,7 +52,7 @@ const LEGACY_OUTGOING_METHODS = [
|
|
52
|
52
|
*
|
|
53
|
53
|
* @type {string}
|
|
54
|
54
|
*/
|
|
55
|
|
-const POSTIS_METHOD_NAME = 'data';
|
|
|
55
|
+const POSTIS_METHOD_NAME = 'message';
|
|
56
|
56
|
|
|
57
|
57
|
/**
|
|
58
|
58
|
* Implements message transport using the postMessage API.
|
|
|
@@ -71,10 +71,10 @@ export default class PostMessageTransportBackend {
|
|
71
|
71
|
});
|
|
72
|
72
|
|
|
73
|
73
|
/**
|
|
74
|
|
- * If true PostMessageTransportBackend will process and send data using
|
|
75
|
|
- * the legacy format and in the same time the current format. Otherwise
|
|
76
|
|
- * all data received that is using the legacy format will be ignored and
|
|
77
|
|
- * no data with the legacy format will be sent.
|
|
|
74
|
+ * If true PostMessageTransportBackend will process and send messages
|
|
|
75
|
+ * using the legacy format and in the same time the current format.
|
|
|
76
|
+ * Otherwise all messages (outgoing and incoming) that are using the
|
|
|
77
|
+ * legacy format will be ignored.
|
|
78
|
78
|
*
|
|
79
|
79
|
* @type {boolean}
|
|
80
|
80
|
*/
|
|
|
@@ -85,7 +85,10 @@ export default class PostMessageTransportBackend {
|
|
85
|
85
|
LEGACY_INCOMING_METHODS.forEach(method =>
|
|
86
|
86
|
this.postis.listen(
|
|
87
|
87
|
method,
|
|
88
|
|
- params => this._legacyDataReceiveCallback(method, params)));
|
|
|
88
|
+ params =>
|
|
|
89
|
+ this._legacyMessageReceivedCallback(method, params)
|
|
|
90
|
+ )
|
|
|
91
|
+ );
|
|
89
|
92
|
}
|
|
90
|
93
|
|
|
91
|
94
|
this._receiveCallback = () => {
|
|
|
@@ -95,17 +98,17 @@ export default class PostMessageTransportBackend {
|
|
95
|
98
|
|
|
96
|
99
|
this.postis.listen(
|
|
97
|
100
|
POSTIS_METHOD_NAME,
|
|
98
|
|
- data => this._receiveCallback(data));
|
|
|
101
|
+ message => this._receiveCallback(message));
|
|
99
|
102
|
}
|
|
100
|
103
|
|
|
101
|
104
|
/**
|
|
102
|
|
- * Handles incoming legacy postis data.
|
|
|
105
|
+ * Handles incoming legacy postis messages.
|
|
103
|
106
|
*
|
|
104
|
|
- * @param {string} method - The method property from postis data object.
|
|
105
|
|
- * @param {Any} params - The params property from postis data object.
|
|
|
107
|
+ * @param {string} method - The method property from the postis message.
|
|
|
108
|
+ * @param {Any} params - The params property from the postis message.
|
|
106
|
109
|
* @returns {void}
|
|
107
|
110
|
*/
|
|
108
|
|
- _legacyDataReceiveCallback(method, params = {}) {
|
|
|
111
|
+ _legacyMessageReceivedCallback(method, params = {}) {
|
|
109
|
112
|
this._receiveCallback({
|
|
110
|
113
|
data: {
|
|
111
|
114
|
name: method,
|
|
|
@@ -115,12 +118,12 @@ export default class PostMessageTransportBackend {
|
|
115
|
118
|
}
|
|
116
|
119
|
|
|
117
|
120
|
/**
|
|
118
|
|
- * Sends the passed data via postis using the old format.
|
|
|
121
|
+ * Sends the passed message via postis using the old format.
|
|
119
|
122
|
*
|
|
120
|
|
- * @param {Object} data - The data to be sent.
|
|
|
123
|
+ * @param {Object} legacyMessage - The message to be sent.
|
|
121
|
124
|
* @returns {void}
|
|
122
|
125
|
*/
|
|
123
|
|
- _sendLegacyData({ data, name }) {
|
|
|
126
|
+ _sendLegacyMessage({ data, name }) {
|
|
124
|
127
|
if (name && LEGACY_OUTGOING_METHODS.indexOf(name) !== -1) {
|
|
125
|
128
|
this.postis.send({
|
|
126
|
129
|
method: name,
|
|
|
@@ -139,23 +142,23 @@ export default class PostMessageTransportBackend {
|
|
139
|
142
|
}
|
|
140
|
143
|
|
|
141
|
144
|
/**
|
|
142
|
|
- * Sends the passed data.
|
|
|
145
|
+ * Sends the passed message.
|
|
143
|
146
|
*
|
|
144
|
|
- * @param {Object} data - The data to be sent.
|
|
|
147
|
+ * @param {Object} message - The message to be sent.
|
|
145
|
148
|
* @returns {void}
|
|
146
|
149
|
*/
|
|
147
|
|
- send(data) {
|
|
|
150
|
+ send(message) {
|
|
148
|
151
|
this.postis.send({
|
|
149
|
152
|
method: POSTIS_METHOD_NAME,
|
|
150
|
|
- params: data
|
|
|
153
|
+ params: message
|
|
151
|
154
|
});
|
|
152
|
155
|
|
|
153
|
156
|
if (this._enableLegacyFormat) {
|
|
154
|
157
|
// For the legacy use case we don't need any new fields defined in
|
|
155
|
158
|
// Transport class. That's why we are passing only the original
|
|
156
|
159
|
// object passed by the consumer of the Transport class which is
|
|
157
|
|
- // data.data.
|
|
158
|
|
- this._sendLegacyData(data.data);
|
|
|
160
|
+ // message.data.
|
|
|
161
|
+ this._sendLegacyMessage(message.data);
|
|
159
|
162
|
}
|
|
160
|
163
|
}
|
|
161
|
164
|
|