fromWire static method
Implementation
static ServerMessage fromWire(Map<String, dynamic> wire) {
final type = wire['type'];
switch (type) {
case 'welcome':
_requireOnly(wire, {'type', 'peer', 'peers'});
return ServerWelcome(
wire['peer'] as int,
(wire['peers'] as List).cast<int>(),
);
case 'peer-joined':
_requireOnly(wire, {'type', 'peer'});
return ServerPeerJoined(wire['peer'] as int);
case 'peer-left':
_requireOnly(wire, {'type', 'peer'});
return ServerPeerLeft(wire['peer'] as int);
case 'offer':
_requireOnly(wire, {'type', 'from', 'sdp'});
return ServerOffer(wire['from'] as int, wire['sdp'] as String);
case 'answer':
_requireOnly(wire, {'type', 'from', 'sdp'});
return ServerAnswer(wire['from'] as int, wire['sdp'] as String);
case 'ice':
_requireOnly(wire, {'type', 'from', 'candidate'});
return ServerIce(wire['from'] as int, wire['candidate'] as String);
case 'relay':
_requireOnly(wire, {'type', 'from', 'payload'});
return ServerRelay(wire['from'] as int, wire['payload'] as Object);
case 'error':
_requireOnly(wire, {'type', 'code', 'message'});
return ServerError(wire['code'] as String, wire['message'] as String);
default:
throw FormatException('unknown ServerMessage type: $type');
}
}