triniwiz / nativescript-socketio

Socket.IO for nativescript
Apache License 2.0
71 stars 31 forks source link

Android - emit object inside array #37

Closed odubuc closed 7 years ago

odubuc commented 7 years ago

v2.3.1 sending an object inside an array will crash on Android. I did not yet test on IOS. ie: .emit('oops', { 'this': [ { 'will': 'crash' } ] } );

Stacktrace

JS: EXCEPTION: Uncaught (in promise): Error: Cannot convert object to Ljava/lang/Object; at index 0
JS: ORIGINAL STACKTRACE:
JS: Error: Uncaught (in promise): Error: Cannot convert object to Ljava/lang/Object; at index 0
JS:     at resolvePromise (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:416:31)
JS:     at resolvePromise (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:401:17)
JS:     at file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:449:17
JS:     at ZoneDelegate.invokeTask (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:223:37)
JS:     at Object.onInvokeTask (file:///data/data/org.nativescript.app/files/app/tns_modules/@angular/core/bundles/core.umd.js:3971:41)
JS:     at ZoneDelegate.invokeTask (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:222:42)
JS:     at Zone.runTask (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:123:47)
JS:     at drainMicroTaskQueue (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:355:35)
JS: Unhandled Promise rejection: Cannot convert object to Ljava/lang/Object; at index 0 ; Zone: angular ; Task: Promise.then ; Value: Error: Cannot convert object to Ljava/lang/Object; at index 0 Error: Cannot convert object to Ljava/lang/Object; at index 0
JS:     at file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-socketio/socketio.js:120:31
JS:     at Array.forEach (native)
JS:     at Function.SocketIO.serialize (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-socketio/socketio.js:119:27)
JS:     at file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-socketio/socketio.js:127:45
JS:     at Array.forEach (native)
JS:     at SocketIO.serialize (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-socketio/socketio.js:125:36)
JS:     at Array.map (native)
JS:     at SocketIO.emit (file:///data/data/org.nativescript.app/files/app/tns_modules/nativescript-socketio/socketio.js:66:27)
JS:     at WebSocketService.emit (file:///data/data/org.nativescript.app/files/app/provider/websocket.service.js:22:24)
JS: Error: Uncaught (in promise): Error: Cannot convert object to Ljava/lang/Object; at index 0
roblav96 commented 7 years ago

@odubuc You need to JSON.stringify any data object.

odubuc commented 7 years ago

Alright, thanks, this is what I ended up doing, just wanted confirm this is as designed. :)