send method
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;
Map<String, dynamic> request = {
"janus": "message",
"body": data,
"transaction": transaction,
..._context._apiMap,
..._context._tokenMap
};
if (jsep != null) {
_context._logger.finest("sending jsep");
_context._logger.finest(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) {
this._context._logger.fine(e);
}
}