Skip to content

Commit 09c47a4

Browse files
cordova-angular: test sending many arguments
Adds tests to check many arguments can be sent as the events data.
1 parent ecdc59f commit 09c47a4

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

cordova-angularjs/src/client/app/app.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,16 @@ function($rootScope, $http, $timeout, theSocket) {
154154
checkHttp();
155155
});
156156

157-
nodejs.channel.on('test-type', (msg) => {
157+
nodejs.channel.on('test-type', (msg, secondMsg, ...other_args) => {
158158
// Report the message payload type and contents.
159-
appendToLog('Received type "' + (typeof msg) + '" with contents : ' + JSON.stringify(msg) , true);
159+
let report_msg = 'Received type "' + (typeof msg) + '" with contents : ' + JSON.stringify(msg);
160+
if (typeof secondMsg !== 'undefined') {
161+
report_msg += ' . Also received type "' + (typeof secondMsg) + '" with contents : ' + JSON.stringify(secondMsg);
162+
}
163+
if (other_args.length > 0) {
164+
report_msg += ' . Further arguments received: ' + JSON.stringify(other_args);
165+
}
166+
appendToLog(report_msg , true);
160167
});
161168

162169
nodejs.start('main.js',
@@ -317,6 +324,9 @@ function($rootScope, $http, $timeout, theSocket) {
317324
nodejs.channel.post('test-type', [1, 2, 3]);
318325
nodejs.channel.post('test-type', []);
319326
nodejs.channel.post('test-type', [2, _testobj, null, "other string"]);
327+
// Send many arguments in the same event.
328+
nodejs.channel.post('test-type', 'two-args', _testobj);
329+
nodejs.channel.post('test-type', 'many-args', false, true, null, 1, 0, -1.3, [1, 2, 3], _testobj);
320330
}
321331

322332
function testMessageTypesReceived() {

cordova-angularjs/src/server/main.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,16 @@ if (isMobile) {
176176
});
177177
});
178178

179-
cordova.channel.on('test-type', (msg) => {
179+
cordova.channel.on('test-type', (msg, secondMsg, ...other_args) => {
180180
// Report the message payload type and contents.
181-
cordova.channel.post('angular-log','Received type "' + (typeof msg) + '" with contents : ' + JSON.stringify(msg) );
181+
let report_msg = 'Received type "' + (typeof msg) + '" with contents : ' + JSON.stringify(msg);
182+
if (typeof secondMsg !== 'undefined') {
183+
report_msg += ' . Also received type "' + (typeof secondMsg) + '" with contents : ' + JSON.stringify(secondMsg);
184+
}
185+
if (other_args.length > 0) {
186+
report_msg += ' . Further arguments received: ' + JSON.stringify(other_args);
187+
}
188+
cordova.channel.post('angular-log', report_msg);
182189
});
183190

184191
function sendMessageTypesToCordova() {
@@ -215,6 +222,9 @@ if (isMobile) {
215222
cordova.channel.post('test-type', [1, 2, 3]);
216223
cordova.channel.post('test-type', []);
217224
cordova.channel.post('test-type', [2, _testobj, null, "other string"]);
225+
// Send many arguments in the same event.
226+
cordova.channel.post('test-type', 'two-args', _testobj);
227+
cordova.channel.post('test-type', 'many-args', false, true, null, 1, 0, -1.3, [1, 2, 3], _testobj);
218228
}
219229

220230
function startActions() {

0 commit comments

Comments
 (0)