I'm trying to send a signal to our OpenTok Signalling Server from my iOS device.
However, the payload, when sent from the browser, is converted to JSON string by OpenTok's SDK. However, when I send a signal back with the payload (in a string format) I convert my NSDictionary (with the following block):
NSString *jsonString;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
if (!jsonData) {
NSLog(@"error: %@", error.localizedDescription);
jsonString = @"{}";
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF16StringEncoding];
}
return jsonString;
and send this string, which is received on my browser.
[_session signalWithType:VC_WebRTC_Signal_Chat string:jsonString connection:nil error:&error];
However, OpenTok doesn't automatically convert this JSONString back into a JSON object, and the payload returned is returned as a String. Are there NSJSONSerialization options that I should be using to handle this?
The signal interface only takes and spits out strings. You are responsible for performing your own encoding/decoding of higher order data.
In your case, I think you probably want to be using JSONObjectWithData:options:error:
to convert the string you receive from the delegate callback session:receivedSignalType:fromConnection:withString:
back into a dictionary/array/whatever.
Full disclosure: I work for TokBox.