send method Null safety
- {dynamic data,
- RTCSessionDescription? jsep}
This method is crucial for communicating with Janus Server's APIs it takes in data and optionally jsep for negotiating with webrtc peers
Implementation
Future<dynamic> send({dynamic data, RTCSessionDescription? jsep}) async {
try {
String transaction = getUuid().v4();
Map<String, dynamic>? response;
var request = {
"janus": "message",
"body": data,
"transaction": transaction,
};
if (_context._token != null) request["token"] = _context._token;
if (_context._apiSecret != null) request["apisecret"] = _context._apiSecret;
if (jsep != null) {
_context._logger.fine("sending jsep");
_context._logger.fine(jsep.toMap());
request["jsep"] = jsep.toMap();
}
if (_transport is RestJanusTransport) {
RestJanusTransport rest = (_transport as RestJanusTransport);
response = (await rest.post(request, handleId: handleId)) as Map<String, dynamic>;
} else if (_transport is WebSocketJanusTransport) {
WebSocketJanusTransport ws = (_transport as WebSocketJanusTransport);
if (!ws.isConnected) {
return;
}
response = await ws.send(request, handleId: handleId);
}
return response;
} catch (e) {
print(e);
}
}