Hi,
I started using ionic (angular) for creating a simple mobile app with OpenVidu. I wanted to receive chat messages and display it to the user, but I encountered an error in the process:
ERROR in src/app/session/session.page.ts:152:37 - error TS2339: Property 'data' does not exist on type 'ConnectionEvent | PublisherSpeakingEvent | RecordingEvent | SessionDisconnectedEvent | SignalEvent | StreamEvent'.
Property 'data' does not exist on type 'ConnectionEvent'.
152 var data_split:string = event.data.split(",");
Code:
this.session.on('signal:singnal-type', (event) => {
var data_split:string = event.data.split(",");
console.log(data_split);
})
Where am I going wrong?
Thanks
I think the error is clear enough
The ConnectionEvent object doesn’t have any data field
1 Like
Hi,
Sorry for the late response
But when I log event, with this code:
this.session.on('signal:signal-type', (event) => {
console.log("NEW EVENT");
console.log(event);
}
I get:
NEW EVENT
SignalEvent
cancelable: false
data: "test"
from: Connection {session: Session, disposed: false, options: {…}, connectionId: "con_Pj4JEDxsQ8", creationTime: 1594636029968, …}
hasBeenPrevented: false
target: Session {userHandlerArrowHandler: WeakMap, ee: EventEmitter, streamManagers: Array(2), remoteStreamsCreated: {…}, isFirstIonicIosSubscriber: false, …}
type: "signal:signal-type"
__proto__: Event
I can see that there is a data attribute in it.
Anyway, according to the docs, here, to get the message, you use event.data
. Does that not work in ionic/typescript?
Thanks
I’m afraid that this error cannot be anything else that something wrong with your code. Let me explain: sending and receiving signals is probably one of the simplest parts of OpenVidu code. Doesn’t matter if you are using Ionic, Angular, React, Electron or whatever client framework you decide. It is a very straightforward process. I see in your log “Property ‘data’ does not exist on type ‘ConnectionEvent’.” You are subscribing to “ConnectionEvent”, not “SignalEvent”!! You are treating session.on('connectionCreated')
as session.on('signal')
.
Please, review your code.
1 Like
Hi,
Thanks for the tip,
I have solved it by this code:
this.session.on('signal:signal-type', (event: SignalEvent) => {
// access data from event.data
})
binding it to SignalEvent works like a charm 
Thanks again