opentok / cordova-plugin-opentok

Cordova Plugin for OpenTok - add webrtc video to your iOS or Android App
MIT License
30 stars 80 forks source link

Signal event crashes the app on iOS #137

Closed IvoPelayo closed 5 years ago

IvoPelayo commented 5 years ago

When running app on iOS device, the signal event causes an exception:

Terminating app due to uncaught exception "NSInvalidArgumentException". Reason: [__NSDictionaryM setObject:forKey:]: object cannot be nil (key:data);

i was able to locate the bug on this method:

-(void) session:(OTSession *)session receivedSignalType:(NSString *)type fromConnection: 
  (OTConnection *)connection withString:(NSString *)string{

  NSLog(@"iOS Session Received signal from Connection: %@ with id %@", connection, [connection connectionId]); 
  NSMutableDictionary* data = [[NSMutableDictionary alloc] init]; 
  [data setObject: type forKey: @"type"]; 
  [data setObject: string forKey: @"data"]; -->HERE 
  if (connection.connectionId) { 
    [data setObject: connection.connectionId forKey: @"connectionId"]; 
    [self triggerJSEvent: @"sessionEvents" withType: @"signalReceived" withData: data]; 
  } 
}

I was able to fix this exception by changing this line [data setObject: string forKey: @"data"]; to this [data setObject: (string == nil) ? @"":string forKey: @"data"];

Now its working, but if I try to catch the signal using this code:

session.on("signal", function(event) {
      console.log("Signal sent from connection " + event.from.id);
      // Process the event.data property, if there is any data.
});

the signal type always says 'signal'. I had to use single subscribers for every signal type like this:

session.on("signal:foo", function(event) {
 console.log("Signal sent from connection " + event.from.id);
 // Process the event.data property, if there is any data.
});
msach22 commented 5 years ago

@IvoPelayo Thanks for filing this issue, could you please share the version of this plugin that you're using? Is this happening when you're sending a signal from the server side instead of a connected client?

IvoPelayo commented 5 years ago

Hi @msach22 i´m currently using 3.4.1 (latest), and I´m sending a signal from a web browser (opentok.js) to a iOS device. With this mods and usign individual signal events, the plugin works like a charm, its just something to have in mind when moving from opentok.js to cordova plugin

msach22 commented 5 years ago

Thanks @IvoPelayo - I will update you as we get this fix in

msach22 commented 5 years ago

Thanks @IvoPelayo - I'm able to reproduce this issue. The crash happens when either type or data are nil. If you'd like to make a PR with your fix, please include it for type as well. I'd be happy to review it. If not, I'll patch the plugin.

msach22 commented 5 years ago

This has been released with v3.4.3