@@ -68,14 +68,16 @@ class Signaling {
68
68
}
69
69
70
70
void invite (String peer_id, String media) {
71
- String sessionId = this ._self_id + '-' + peer_id;
72
- _send ('invite' , {
73
- 'session_id' : sessionId,
74
- 'id' : _self_id,
75
- 'to' : peer_id,
76
- 'media' : media,
71
+ this ._session_id = this ._self_id + '-' + peer_id;
72
+
73
+ if (this .onStateChange != null ) {
74
+ this .onStateChange (SignalingState .CallStateNew );
75
+ }
76
+
77
+ _createPeerConnection (peer_id, media).then ((pc) {
78
+ _peerConnections[peer_id] = pc;
79
+ _createOffer (peer_id, pc, media);
77
80
});
78
- this ._session_id = sessionId;
79
81
}
80
82
81
83
void bye () {
@@ -102,24 +104,10 @@ class Signaling {
102
104
}
103
105
}
104
106
break ;
105
- case 'ringing' :
106
- {
107
- var id = data['id' ];
108
- var media = data['media' ];
109
-
110
- if (this .onStateChange != null ) {
111
- this .onStateChange (SignalingState .CallStateNew );
112
- }
113
-
114
- _createPeerConnection (id, media).then ((pc) {
115
- _peerConnections[id] = pc;
116
- _createOffer (id, pc);
117
- });
118
- }
119
- break ;
120
- case 'invite' :
107
+ case 'offer' :
121
108
{
122
109
var id = data['from' ];
110
+ var description = data['description' ];
123
111
var media = data['media' ];
124
112
var session_id = data['session_id' ];
125
113
this ._session_id = session_id;
@@ -130,20 +118,10 @@ class Signaling {
130
118
131
119
_createPeerConnection (id, media).then ((pc) {
132
120
_peerConnections[id] = pc;
133
- });
134
- }
135
- break ;
136
- case 'offer' :
137
- {
138
- var id = data['from' ];
139
- var description = data['description' ];
140
-
141
- RTCPeerConnection pc = _peerConnections[id];
142
- if (pc != null ) {
143
- await pc.setRemoteDescription (
121
+ pc.setRemoteDescription (
144
122
new RTCSessionDescription (description['sdp' ], description['type' ]));
145
123
_createAnswer (id, pc);
146
- }
124
+ });
147
125
}
148
126
break ;
149
127
case 'answer' :
@@ -327,14 +305,15 @@ class Signaling {
327
305
_addDataChannel (id, channel);
328
306
}
329
307
330
- _createOffer (String id, RTCPeerConnection pc) async {
308
+ _createOffer (String id, RTCPeerConnection pc, String media ) async {
331
309
try {
332
310
RTCSessionDescription s = await pc.createOffer (_constraints);
333
311
pc.setLocalDescription (s);
334
312
_send ('offer' , {
335
313
'to' : id,
336
314
'description' : {'sdp' : s.sdp, 'type' : s.type},
337
315
'session_id' : this ._session_id,
316
+ 'media' : media,
338
317
});
339
318
} catch (e) {
340
319
print (e.toString ());
0 commit comments