Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webrtc 2360 generate flutter stats #70

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .lh/packages/telnyx_webrtc/lib/peer/peer.dart.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 1,
"activePatchIndex": 7,
"patches": [
{
"date": 1730809569544,
Expand All @@ -12,6 +12,30 @@
{
"date": 1730809600452,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -273,9 +273,9 @@\n userAgent: \"Flutter-1.0\");\n var answerMessage = InviteAnswerMessage(\n id: const Uuid().v4(),\n jsonrpc: JsonRPCConstant.jsonrpc,\n- method: SocketMethod.ANSWER,\n+ method: isAttach ? SocketMethod.ATTACH : SocketMethod.ANSWER,\n params: inviteParams);\n \n String jsonAnswerMessage = jsonEncode(answerMessage);\n _send(jsonAnswerMessage);\n"
},
{
"date": 1732094808505,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -284,8 +284,20 @@\n _logger.e(\"Peer :: $e\");\n }\n }\n \n+ Future<void> getStats(RTCPeerConnection peerConnection) async {\n+ peerConnection.getStats(null).then((value) {\n+ value.forEach((report) {\n+ _logger.i(\"Stats: {\");\n+ report.values.forEach((key, value) {\n+ _logger.i(\"$key: $value\");\n+ });\n+ _logger.i(\"}\");\n+ });\n+ });\n+ }\n+\n void closeSession() {\n var sess = _sessions[_selfId];\n if (sess != null) {\n _logger.d(\"Session end success\");\n"
},
{
"date": 1732103558178,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -201,9 +201,10 @@\n String destinationNumber,\n String clientState,\n String callId,\n IncomingInviteParams invite,\n- Map<String, String> customHeaders,bool isAttach) async {\n+ Map<String, String> customHeaders,\n+ bool isAttach) async {\n var sessionId = _selfId;\n Session session = await _createSession(null,\n peerId: \"0\", sessionId: sessionId, media: \"audio\");\n _sessions[sessionId] = session;\n@@ -211,9 +212,9 @@\n await session.peerConnection\n ?.setRemoteDescription(RTCSessionDescription(invite.sdp, \"offer\"));\n \n _createAnswer(session, \"audio\", callerName, callerNumber, destinationNumber,\n- clientState, callId, customHeaders,isAttach);\n+ clientState, callId, customHeaders, isAttach);\n \n onCallStateChange?.call(session, CallState.active);\n }\n \n@@ -224,9 +225,10 @@\n String callerNumber,\n String destinationNumber,\n String clientState,\n String callId,\n- Map<String, String> customHeaders,bool isAttach) async {\n+ Map<String, String> customHeaders,\n+ bool isAttach) async {\n try {\n session.peerConnection?.onIceCandidate = (candidate) async {\n if (session.peerConnection != null) {\n _logger.i(\"Peer :: Add Ice Candidate!\");\n"
},
{
"date": 1732103618535,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -372,8 +372,11 @@\n switch (state) {\n case RTCIceConnectionState.RTCIceConnectionStateFailed:\n peerConnection.restartIce();\n return;\n+ case RTCIceConnectionState.RTCIceConnectionStateConnected:\n+ getStats(peerConnection);\n+ return;\n default:\n return;\n }\n };\n"
},
{
"date": 1732194107233,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -5,8 +5,9 @@\n import 'package:flutter_webrtc/flutter_webrtc.dart';\n import 'package:telnyx_webrtc/config.dart';\n import 'package:telnyx_webrtc/model/socket_method.dart';\n import 'package:telnyx_webrtc/model/verto/send/invite_answer_message_body.dart';\n+import 'package:telnyx_webrtc/stats/statsmanager.dart';\n import 'package:telnyx_webrtc/tx_socket.dart'\n if (dart.library.js) 'package:telnyx_webrtc/tx_socket_web.dart';\n import 'package:uuid/uuid.dart';\n import 'package:logger/logger.dart';\n@@ -38,8 +39,10 @@\n final String _selfId = randomNumeric(6);\n \n final TxSocket _socket;\n \n+ StatsManager? _statsManager;\n+\n final Map<String, Session> _sessions = {};\n MediaStream? _localStream;\n final List<MediaStream> _remoteStreams = <MediaStream>[];\n \n@@ -112,9 +115,9 @@\n Map<String, String> customHeaders) async {\n var sessionId = _selfId;\n \n Session session = await _createSession(null,\n- peerId: \"0\", sessionId: sessionId, media: \"audio\");\n+ peerId: \"0\", sessionId: sessionId,callId: callId, media: \"audio\");\n \n _sessions[sessionId] = session;\n \n _createOffer(session, \"audio\", callerName, callerNumber, destinationNumber,\n@@ -205,9 +208,9 @@\n Map<String, String> customHeaders,\n bool isAttach) async {\n var sessionId = _selfId;\n Session session = await _createSession(null,\n- peerId: \"0\", sessionId: sessionId, media: \"audio\");\n+ peerId: \"0\", sessionId: sessionId,callId: callId, media: \"audio\");\n _sessions[sessionId] = session;\n \n await session.peerConnection\n ?.setRemoteDescription(RTCSessionDescription(invite.sdp, \"offer\"));\n@@ -284,19 +287,8 @@\n _logger.e(\"Peer :: $e\");\n }\n }\n \n- Future<void> getStats(RTCPeerConnection peerConnection) async {\n- peerConnection.getStats(null).then((value) {\n- value.forEach((report) {\n- _logger.i(\"Stats: {\");\n- report.values.forEach((key, value) {\n- _logger.i(\"$key: $value\");\n- });\n- _logger.i(\"}\");\n- });\n- });\n- }\n \n void closeSession() {\n var sess = _sessions[_selfId];\n if (sess != null) {\n@@ -321,8 +313,9 @@\n \n Future<Session> _createSession(Session? session,\n {required String peerId,\n required String sessionId,\n+ required String callId,\n required String media}) async {\n var newSession = session ?? Session(sid: sessionId, pid: peerId);\n if (media != 'data') _localStream = await createStream(media);\n \n@@ -373,9 +366,10 @@\n case RTCIceConnectionState.RTCIceConnectionStateFailed:\n peerConnection.restartIce();\n return;\n case RTCIceConnectionState.RTCIceConnectionStateConnected:\n- getStats(peerConnection);\n+ _statsManager = StatsManager(_socket, peerConnection,callId);\n+ _statsManager?.startTimer();\n return;\n default:\n return;\n }\n"
},
{
"date": 1732194650698,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -38,8 +38,9 @@\n \n final String _selfId = randomNumeric(6);\n \n final TxSocket _socket;\n+ bool isDebugStats = false;\n \n StatsManager? _statsManager;\n \n final Map<String, Session> _sessions = {};\n@@ -365,9 +366,8 @@\n case RTCIceConnectionState.RTCIceConnectionStateFailed:\n peerConnection.restartIce();\n return;\n case RTCIceConnectionState.RTCIceConnectionStateConnected:\n- _statsManager = StatsManager(_socket, peerConnection, callId);\n _statsManager?.startTimer();\n return;\n default:\n return;\n@@ -397,8 +397,14 @@\n session.dc = channel;\n onDataChannel?.call(session, channel);\n }\n \n+ void startStats(String debugReportId) {\n+ isDebugStats = true;\n+ _statsManager = StatsManager(_socket, peerConnection, callId);\n+ _statsManager?.startStats(debugReportId);\n+ }\n+\n /*Future<void> _createDataChannel(Session session,\n {label = 'fileTransfer'}) async {\n RTCDataChannelInit dataChannelDict = RTCDataChannelInit()\n ..maxRetransmits = 30;\n"
},
{
"date": 1732195341173,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -41,8 +41,9 @@\n final TxSocket _socket;\n bool isDebugStats = false;\n \n StatsManager? _statsManager;\n+ RTCPeerConnection? peerConnection;\n \n final Map<String, Session> _sessions = {};\n MediaStream? _localStream;\n final List<MediaStream> _remoteStreams = <MediaStream>[];\n@@ -318,40 +319,40 @@\n required String media}) async {\n var newSession = session ?? Session(sid: sessionId, pid: peerId);\n if (media != 'data') _localStream = await createStream(media);\n \n- RTCPeerConnection peerConnection = await createPeerConnection({\n+ peerConnection = await createPeerConnection({\n ..._iceServers,\n ...{'sdpSemantics': sdpSemantics}\n }, _dcConstraints);\n if (media != 'data') {\n switch (sdpSemantics) {\n case 'plan-b':\n- peerConnection.onAddStream = (MediaStream stream) {\n+ peerConnection?.onAddStream = (MediaStream stream) {\n onAddRemoteStream?.call(newSession, stream);\n _remoteStreams.add(stream);\n };\n- await peerConnection.addStream(_localStream!);\n+ await peerConnection?.addStream(_localStream!);\n break;\n case 'unified-plan':\n // Unified-Plan\n- peerConnection.onTrack = (event) {\n+ peerConnection?.onTrack = (event) {\n if (event.track.kind == 'video') {\n onAddRemoteStream?.call(newSession, event.streams[0]);\n } else if (event.track.kind == 'audio') {\n onAddRemoteStream?.call(newSession, event.streams[0]);\n }\n };\n _localStream!.getTracks().forEach((track) {\n- peerConnection.addTrack(track, _localStream!);\n+ peerConnection?.addTrack(track, _localStream!);\n });\n break;\n }\n }\n- peerConnection.onIceCandidate = (candidate) async {\n+ peerConnection?.onIceCandidate = (candidate) async {\n if (!candidate.candidate.toString().contains(\"127.0.0.1\")) {\n _logger.i(\"Peer :: Adding ICE candidate :: ${candidate.toString()}\");\n- peerConnection.addCandidate(candidate);\n+ peerConnection?.addCandidate(candidate);\n } else {\n _logger.i(\"Peer :: Local candidate skipped!\");\n }\n if (candidate.candidate == null) {\n@@ -359,30 +360,30 @@\n return;\n }\n };\n \n- peerConnection.onIceConnectionState = (state) {\n+ peerConnection?.onIceConnectionState = (state) {\n _logger.i(\"Peer :: ICE Connection State change :: $state\");\n switch (state) {\n case RTCIceConnectionState.RTCIceConnectionStateFailed:\n- peerConnection.restartIce();\n+ peerConnection?.restartIce();\n return;\n- case RTCIceConnectionState.RTCIceConnectionStateConnected:\n- _statsManager?.startTimer();\n+ case RTCIceConnectionState.RTCIceConnectionStateDisconnected:\n+ _statsManager?.stopTimer();\n return;\n default:\n return;\n }\n };\n \n- peerConnection.onRemoveStream = (stream) {\n+ peerConnection?.onRemoveStream = (stream) {\n onRemoveRemoteStream?.call(newSession, stream);\n _remoteStreams.removeWhere((it) {\n return (it.id == stream.id);\n });\n };\n \n- peerConnection.onDataChannel = (channel) {\n+ peerConnection?.onDataChannel = (channel) {\n _addDataChannel(newSession, channel);\n };\n \n newSession.peerConnection = peerConnection;\n@@ -397,12 +398,12 @@\n session.dc = channel;\n onDataChannel?.call(session, channel);\n }\n \n- void startStats(String debugReportId) {\n+ void startStats(String callId) {\n isDebugStats = true;\n- _statsManager = StatsManager(_socket, peerConnection, callId);\n- _statsManager?.startStats(debugReportId);\n+ _statsManager = StatsManager(_socket, peerConnection!, callId);\n+ _statsManager?.startTimer();\n }\n \n /*Future<void> _createDataChannel(Session session,\n {label = 'fileTransfer'}) async {\n"
}
],
"date": 1730809569544,
Expand Down
18 changes: 18 additions & 0 deletions .lh/packages/telnyx_webrtc/lib/stats/stats_params.dart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sourceFile": "packages/telnyx_webrtc/lib/stats/stats_params.dart",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 0,
"patches": [
{
"date": 1732172924923,
"content": "Index: \n===================================================================\n--- \n+++ \n"
}
],
"date": 1732172924923,
"name": "Commit-0",
"content": "import 'package:uuid/uuid.dart';\n\nclass StatParams {\n final String type;\n final String debugReportId;\n final Map<String, dynamic> reportData;\n final int debugReportVersion;\n final String id;\n final String jsonrpc;\n\n StatParams({\n this.type = \"debug_report_data\",\n required this.debugReportId,\n required this.reportData,\n this.debugReportVersion = 1,\n String? id,\n this.jsonrpc = \"2.0\",\n }) : id = id ?? const Uuid().v4();\n\n Map<String, dynamic> toJson() {\n return {\n \"type\": type,\n \"debug_report_id\": debugReportId,\n \"debug_report_data\": reportData,\n \"debug_report_version\": debugReportVersion,\n \"id\": id,\n \"jsonrpc\": jsonrpc,\n };\n }\n}\n\nclass InitiateOrStopStatParams {\n final String type;\n final String debugReportId;\n final int debugReportVersion;\n final String id;\n final String jsonrpc;\n\n InitiateOrStopStatParams({\n required this.type,\n required this.debugReportId,\n this.debugReportVersion = 1,\n String? id,\n this.jsonrpc = \"2.0\",\n }) : id = id ?? Uuid().v4();\n\n Map<String, dynamic> toJson() {\n return {\n \"type\": type,\n \"debug_report_id\": debugReportId,\n \"debug_report_version\": debugReportVersion,\n \"id\": id,\n \"jsonrpc\": jsonrpc,\n };\n }\n}\n"
}
]
}
Loading
Loading