1

I have to serialize some WebRTC-related dart objects to send them over a signaling channel. As example I have to encode RtcSessionDescription and RtcIceCandidate instances. Both classes offer a constructor to build them in context of a given map, but no one offers a method to create such a Map out of the original object.

How can I generate strings? Do I have to make a detour over Map-objects?

As Example:

RtcSessionDescription -> Map -> String -(send_over_signalingChannel)-> String -> Map -> RtcSessionDescription

NaN
  • 3,501
  • 8
  • 44
  • 77
  • possible duplicate of [Can I automatically serialize a Dart object to send over a Web Socket?](http://stackoverflow.com/questions/18423318/can-i-automatically-serialize-a-dart-object-to-send-over-a-web-socket) – Günter Zöchbauer Feb 10 '14 at 15:54

2 Answers2

1

You can easily convert between Map and String using the dart:convert package.

https://www.dartlang.org/articles/json-web-service/

I don't know about RtcSessionDescription <-> Map though.

See also this question: Can I automatically serialize a Dart object to send over a Web Socket?

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
1

Finally I found a solution (using dart:convert as Günther Zöchbauer suggested):

RtcSessionDescription original = ...;

//serialize
final String serialized_sdp = JSON.encode({
    'sdp':original.sdp,
    'type':original.type
});


//decode
final Map sdp_map = JSON.decode(serialized_sdp);    
RtcSessionDescription sdp = new RtcSessionDescription(sdp_map);
NaN
  • 3,501
  • 8
  • 44
  • 77