This issue only occurs when I switch Unity Editor to WebGL ,on other platforms it works fine ( Ios, Android, Standalone, WebPlayer ).
This issue is that:
The extension sends and UtfStringArray where each string is Json serialized data. But when clients api receive the SfsObject and tries to get the data this error is logged:
InvalidCastException: Cannot cast from source type to destination type.
Sfs2X.Entities.Data.SFSArray.GetValue[String] (Int32 index)
Sfs2X.Entities.Data.SFSArray.GetUtfString (Int32 index)
Sfs2X.Entities.Data.SFSObjectLite.GetUtfStringArray (System.String key)
In order to find out what was happening I realise that instead of receive an UtfStringArray I receive a SfsArray that each element is a SfsObject with the data of the json the server sends. So is like SfsClient Api detects that the strings are Json data and deserialize them.
Here is the code on Extension Side:
Code: Select all
List<String> playersInfo;
playersInfo.add("{/"name/": /"Player A/" ,/"score/": 100}");
playersInfo.add("{/"name/": /"Player B/" ,/"score/": 150}");
ISFSObject response = SFSObject.newInstance();
response.putUtfStringArray("dataAlias", playersInfo);
send("playerInfoRequest" response, sender);
Here is the code on client side (WEBGL):
Code: Select all
ISFSObject sfsResponse = (ISFSObject) evt.Params [ExtensionParamsTypes.PARAMS];
Debug.Log(sfsResponse.GetSFSArray("dataAlias").GetSFSObject(0).GetUtfString("name")) // Player A
Debug.Log(sfsResponse.GetSFSArray("dataAlias").GetSFSObject(0).GetInt("score")) // 100
Debug.Log(sfsResponse.GetSFSArray("dataAlias").GetSFSObject(1).GetUtfString("name")) // Player B
Debug.Log(sfsResponse.GetSFSArray("dataAlias").GetSFSObject(1).GetInt("score")) // 150
Debug.Log(sfsResponse.GetUtfStringArray("dataAlias")) // ERROR - Throws message above
And Here is the code on client side (Other Platforms):
Code: Select all
ISFSObject sfsResponse = (ISFSObject) evt.Params [ExtensionParamsTypes.PARAMS];
Debug.Log(sfsResponse.GetUtfStringArray("dataAlias")[0]) // {"name": "Player A" , "score": 100}
Debug.Log(sfsResponse.GetUtfStringArray("dataAlias")[1]) // {"name": "Player B" , "score": 150}
Debug.Log(sfsResponse.GetSFSArray("dataAlias")) // ERROR
Thanks