@@ -70,31 +70,21 @@ private class CreateOfferCommand implements Command {
70
70
@ Override public void execute (String peerId , JSONObject payload ) throws JSONException {
71
71
72
72
Peer peer = peers .get (peerId );
73
- peer .pc .createOffer (peer ,pcConstraints );
73
+ peer .pc .createOffer (peer , pcConstraints );
74
74
75
75
76
76
}
77
77
}
78
78
79
79
80
-
81
-
82
-
83
-
84
-
85
-
86
- private class Peer implements SdpObserver ,PeerConnection .Observer {
80
+ private class Peer implements SdpObserver , PeerConnection .Observer {
87
81
88
82
private PeerConnection pc ;
89
83
private String id ;
90
84
private int endPoint ;
91
85
92
- @ Override public void onSignalingChange (final PeerConnection .SignalingState sdp ) {
86
+ @ Override public void onSignalingChange (PeerConnection .SignalingState signalingState ) {
93
87
94
- try {
95
- JSONObject payload = new JSONObject ();
96
- payload .put ("type" ,sdp )
97
- }
98
88
99
89
}
100
90
@@ -126,7 +116,20 @@ private class Peer implements SdpObserver,PeerConnection.Observer{
126
116
127
117
}
128
118
129
- @ Override public void onCreateSuccess (SessionDescription sessionDescription ) {
119
+ @ Override public void onCreateSuccess (SessionDescription sdp ) {
120
+
121
+ try {
122
+ JSONObject payload = new JSONObject ();
123
+ payload .put ("type" , sdp .type .canonicalForm ());
124
+ payload .put ("sdp" , sdp .description );
125
+ sendMessage (id , sdp .type .canonicalForm (), payload );
126
+ pc .setLocalDescription (Peer .this , sdp );
127
+
128
+
129
+ } catch (JSONException e ) {
130
+ e .printStackTrace ();
131
+ }
132
+
130
133
131
134
}
132
135
@@ -144,6 +147,15 @@ private class Peer implements SdpObserver,PeerConnection.Observer{
144
147
}
145
148
146
149
150
+ public void sendMessage (String to , String type , JSONObject payload ) throws JSONException {
151
+
152
+ JSONObject message = new JSONObject ();
153
+ message .put ("to" , to );
154
+ message .put ("type" , type );
155
+ message .put ("payload" , payload );
156
+ client .emit ("message" , message );
157
+
158
+ }
147
159
148
160
149
161
}
0 commit comments