commandMap;
130 |
131 | private MessageHandler() {
132 | this.commandMap = new HashMap<>();
133 | commandMap.put("init", new CreateOfferCommand());
134 | commandMap.put("offer", new CreateAnswerCommand());
135 | commandMap.put("answer", new SetRemoteSDPCommand());
136 | commandMap.put("candidate", new AddIceCandidateCommand());
137 | }
138 |
139 | private Emitter.Listener onMessage = new Emitter.Listener() {
140 | @Override
141 | public void call(Object... args) {
142 | JSONObject data = (JSONObject) args[0];
143 | try {
144 | String from = data.getString("from");
145 | String type = data.getString("type");
146 | JSONObject payload = null;
147 | if (!type.equals("init")) {
148 | payload = data.getJSONObject("payload");
149 | }
150 | Log.d(TAG, "onMessage data=" + data);
151 | // if peer is unknown, try to add him
152 | if (!peers.containsKey(from)) {
153 | // if MAX_PEER is reach, ignore the call
154 | int endPoint = findEndPoint();
155 | if (endPoint != MAX_PEER) {
156 | Peer peer = addPeer(from, endPoint);
157 | commandMap.get(type).execute(from, payload);
158 | }
159 | } else {
160 | commandMap.get(type).execute(from, payload);
161 | }
162 | } catch (JSONException e) {
163 | e.printStackTrace();
164 | }
165 | }
166 | };
167 |
168 | private Emitter.Listener onId = new Emitter.Listener() {
169 | @Override
170 | public void call(Object... args) {
171 | String id = (String) args[0];
172 | Log.d(TAG, "onId data=" + id);
173 |
174 | mListener.onCallReady(id);
175 | }
176 | };
177 | }
178 |
179 | private class Peer implements SdpObserver, PeerConnection.Observer {
180 | private DataChannel channel;
181 | private PeerConnection pc;
182 | private String id;
183 | private int endPoint;
184 |
185 | @Override
186 | public void onCreateSuccess(final SessionDescription sdp) {
187 | // TODO: modify sdp to use pcParams prefered codecs
188 | try {
189 | JSONObject payload = new JSONObject();
190 | payload.put("type", sdp.type.canonicalForm());
191 | payload.put("sdp", sdp.description);
192 | Log.i(TAG, "onCreateSuccess" + sdp);
193 | sendMessage(id, sdp.type.canonicalForm(), payload);
194 | pc.setLocalDescription(Peer.this, sdp);
195 | } catch (JSONException e) {
196 | e.printStackTrace();
197 | }
198 | }
199 |
200 | @Override
201 | public void onSetSuccess() {
202 | Log.i(TAG, "Peer onSetSuccess");
203 |
204 | }
205 |
206 | @Override
207 | public void onCreateFailure(String s) {
208 | Log.i(TAG, "Peer onCreateFailure " + s);
209 |
210 | }
211 |
212 | @Override
213 | public void onSetFailure(String s) {
214 | Log.i(TAG, "Peer onSetFailure " + s);
215 |
216 | }
217 |
218 | @Override
219 | public void onSignalingChange(PeerConnection.SignalingState signalingState) {
220 | Log.i(TAG, "Peer onSignalingChange " + signalingState);
221 | mListener.onStatusChanged("onSignalingChange " + signalingState.name());
222 |
223 | }
224 |
225 | @Override
226 | public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
227 | mListener.onStatusChanged("onIceConnectionChange " + iceConnectionState.name());
228 |
229 | if (iceConnectionState == PeerConnection.IceConnectionState.DISCONNECTED) {
230 | removePeer(id);
231 | } else if (iceConnectionState == PeerConnection.IceConnectionState.CONNECTED) {//连接成功
232 | mListener.onStatusChanged("连接成功");
233 | }
234 | Log.i(TAG, "Peer onIceConnectionChange " + iceConnectionState);
235 | }
236 |
237 | @Override
238 | public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringState) {
239 | Log.i(TAG, "Peer onIceGatheringChange " + iceGatheringState);
240 | mListener.onStatusChanged("onIceGatheringChange " + iceGatheringState.name());
241 |
242 |
243 | }
244 |
245 | @Override
246 | public void onIceCandidate(final IceCandidate candidate) {
247 | try {
248 | JSONObject payload = new JSONObject();
249 | payload.put("label", candidate.sdpMLineIndex);
250 | payload.put("id", candidate.sdpMid);
251 | payload.put("candidate", candidate.sdp);
252 | sendMessage(id, "candidate", payload);
253 |
254 | // Log.i(TAG,"onIceCandidate "+candidate);
255 |
256 | } catch (JSONException e) {
257 | e.printStackTrace();
258 | }
259 | }
260 |
261 | @Override
262 | public void onAddStream(MediaStream mediaStream) {
263 | Log.d(TAG, "onAddStream " + mediaStream.label());
264 | // remote streams are displayed from 1 to MAX_PEER (0 is localStream)
265 | }
266 |
267 | @Override
268 | public void onRemoveStream(MediaStream mediaStream) {
269 | Log.d(TAG, "onRemoveStream " + mediaStream.label());
270 | removePeer(id);
271 | }
272 |
273 | @Override
274 | public void onDataChannel(final DataChannel dataChannel) {
275 | Log.i(TAG, "Peer onDataChannel=" + dataChannel);
276 | channel=dataChannel;
277 | mListener.onDataChannel(dataChannel);
278 | mListener.onStatusChanged("DataChannel " + channel.state());
279 |
280 | }
281 |
282 | @Override
283 | public void onRenegotiationNeeded() {
284 | Log.i(TAG, "Peer onRenegotiationNeeded=");
285 |
286 | }
287 |
288 | public Peer(String id, int endPoint) {
289 | Log.d(TAG, "new Peer: " + id + " " + endPoint);
290 | this.pc = factory.createPeerConnection(iceServers, pcConstraints, this);
291 | // pc.createDataChannel()
292 | this.id = id;
293 | this.endPoint = endPoint;
294 |
295 | // pc.addStream(localMS); //, new MediaConstraints()
296 |
297 | mListener.onStatusChanged("CONNECTING");
298 |
299 | channel = pc.createDataChannel("sendDataChannel", new DataChannel.Init());
300 | Log.i(TAG, "createDataChannel " + channel);
301 | channel.registerObserver(new DataChannel.Observer() {
302 |
303 | byte[] mReceiveSrcData;
304 |
305 | @Override
306 | public void onStateChange() {
307 | Log.d(TAG, "registerObserver onStateChange" + channel.state());
308 | mListener.onStatusChanged("DataChannel " + channel.state());
309 | }
310 |
311 | @Override
312 | public void onMessage(DataChannel.Buffer buffer) {
313 | Log.d(TAG, "registerObserver onMessage" + buffer + " data=" + buffer.data + " isBinary=" + buffer.binary);
314 |
315 | int capacity = buffer.data.capacity();
316 | byte[] bytes = new byte[capacity];
317 | buffer.data.get(bytes);
318 |
319 | int index = (int) getValue(bytes, 0, 2);
320 | long packSize = getValue(bytes, 2, 4);//总包数
321 | long packType = getValue(bytes, 4, 5);//包所在类型
322 | int totalDataLength = (int) getValue(bytes, 5, 10);//总数据长度
323 | int dataLength = (int) getValue(bytes, 10, 13);//当前包data长度
324 | int type = (int) getValue(bytes, 13, 14);//type
325 |
326 | if (index == 0)
327 | mReceiveSrcData = new byte[totalDataLength];
328 |
329 | System.arraycopy(bytes, PACK_DATA_START_INDEX, mReceiveSrcData, index * MAX_PACK_DATA_SIZE, dataLength);
330 |
331 | if (iMessageReceiver != null) {
332 | if (packType == 0 || index==0) {
333 | iMessageReceiver.onReceiverStart();
334 | }
335 | if (packType == 1) {
336 | iMessageReceiver.onReceiverProcess((float) ((double) index*100 / packSize));
337 | }
338 | if (packType == 2) {
339 | iMessageReceiver.onReceiverSuccess(mReceiveSrcData,type);
340 | mReceiveSrcData =null;
341 | }
342 | }
343 |
344 | }
345 | });
346 |
347 |
348 | }
349 | }
350 |
351 | private Peer addPeer(String id, int endPoint) {
352 | Peer peer = new Peer(id, endPoint);
353 | peers.put(id, peer);
354 |
355 | endPoints[endPoint] = true;
356 | return peer;
357 | }
358 |
359 | private void removePeer(String id) {
360 | Peer peer = peers.get(id);
361 | peer.pc.close();
362 | peers.remove(peer.id);
363 | endPoints[peer.endPoint] = false;
364 | }
365 |
366 | public WebRtcClient(RtcListener listener, String host, EGLContext mEGLcontext) {
367 | mListener = listener;
368 | PeerConnectionFactory.initializeAndroidGlobals(listener, true, true,
369 | true, mEGLcontext);
370 | factory = new PeerConnectionFactory();
371 | MessageHandler messageHandler = new MessageHandler();
372 |
373 | try {
374 | client = IO.socket(host);
375 | } catch (URISyntaxException e) {
376 | e.printStackTrace();
377 | }
378 | client.on("id", messageHandler.onId);
379 | client.on("message", messageHandler.onMessage);
380 | client.connect();
381 | iceServers.add(new PeerConnection.IceServer("stun:39.104.185.143:3478"));
382 |
383 | // stun 打洞服务器 turn 打洞不行后中继服务服务器
384 | iceServers.add(new PeerConnection.IceServer("turn:39.104.185.143:3478?transport=udp", "webrtc", "webrtc"));
385 | iceServers.add(new PeerConnection.IceServer("turn:39.104.185.143:3478?transport=tcp", "webrtc", "webrtc"));
386 |
387 | /*
388 | iceServers.add(new PeerConnection.IceServer("stun:23.21.150.121"));
389 | iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302"));
390 | iceServers.add(new PeerConnection.IceServer("stun:stun.services.mozilla.com"));
391 |
392 | //免费的turn服务
393 | iceServers.add(new PeerConnection.IceServer("turn:numb.viagenie.ca", "", ""));//这个网站可以自己去申请账号密码
394 | iceServers.add(new PeerConnection.IceServer("turn:192.158.29.39:3478?transport=udp", "28224511:1379330808", "JZEOEt2V3Qb0y27GRntt2u2PAYA="));
395 | iceServers.add(new PeerConnection.IceServer("turn:192.158.29.39:3478?transport=tcp", "28224511:1379330808", "JZEOEt2V3Qb0y27GRntt2u2PAYA="));
396 |
397 | iceServers.add(new PeerConnection.IceServer("turn:turn.bistri.com:80", "homeo", "homeo"));
398 | iceServers.add(new PeerConnection.IceServer("turn:turn.anyfirewall.com:443?transport=tcp", "webrtc", "webrtc"));
399 |
400 | */
401 | pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "false"));
402 | pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "false"));
403 |
404 | pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
405 | }
406 |
407 | /**
408 | * Call this method in Activity.onPause()
409 | */
410 | public void onPause() {
411 | }
412 |
413 | /**
414 | * Call this method in Activity.onResume()
415 | */
416 | public void onResume() {
417 | }
418 |
419 | /**
420 | * Call this method in Activity.onDestroy()
421 | */
422 | public void onDestroy() {
423 | for (Peer peer : peers.values()) {
424 | peer.pc.dispose();
425 | }
426 | factory.dispose();
427 | client.disconnect();
428 | client.close();
429 | }
430 |
431 | private int findEndPoint() {
432 | for (int i = 0; i < MAX_PEER; i++) if (!endPoints[i]) return i;
433 | return MAX_PEER;
434 | }
435 |
436 | /**
437 | * Start the client.
438 | *
439 | * Set up the local stream and notify the signaling server.
440 | * Call this method after onCallReady.
441 | *
442 | * @param name client name
443 | */
444 | public void start(String name) {
445 | try {
446 | JSONObject message = new JSONObject();
447 | message.put("name", name);
448 | client.emit("readyToStream", message);
449 | } catch (JSONException e) {
450 | e.printStackTrace();
451 | }
452 | }
453 |
454 | public static final int MAX_PACK_SIZE = 66528;//每个包最大size
455 | public static final int MAX_PACK_DATA_SIZE = 65536;//每个包中数据体最大size
456 | public static final int PACK_DATA_START_INDEX = MAX_PACK_SIZE - MAX_PACK_DATA_SIZE;//包中data体前剩余空间,用于存放索引、总长度等
457 |
458 | //2^14-1=16383
459 | public static final int MAX_INDEX = (int) (Math.pow(2, 14) - 1);
460 |
461 | /**
462 | * 发送数据
463 | * @param channel 和peer 形成的数据通道
464 | * @param data 数据
465 | * @param type 数据类型,自定义
466 | * @return
467 | */
468 | public boolean sendData(DataChannel channel, @NonNull byte[] data,int type) {
469 | DataChannel.State state = null;
470 | if (channel == null || (state = channel.state()) != DataChannel.State.OPEN) {
471 | Log.d(TAG, "channel = " + channel + " and state is " + state);
472 | return false;
473 | }
474 | int len = data.length;
475 | if (len > 1073676288) {
476 | throw new RuntimeException("data.length range 1 ~ 16383 *$MAX_PACK_DATA_SIZE");
477 | }
478 | int quotient = len / MAX_PACK_DATA_SIZE;//商
479 | int remainder = len % MAX_PACK_DATA_SIZE;//余数
480 |
481 | int packSize = (remainder == 0 ? quotient : quotient + 1);//总包数
482 |
483 | Log.d(TAG, "arrays.len=" + len + " quotient=" + quotient + " remainder=" + remainder);
484 | for (int i = 0; i < quotient; i++) {
485 | byte[] dest = new byte[MAX_PACK_SIZE];
486 | int start = i * MAX_PACK_DATA_SIZE;
487 | System.arraycopy(data, start, dest, PACK_DATA_START_INDEX, MAX_PACK_DATA_SIZE);
488 | setValue(dest, 0, 2, i);//index
489 | setValue(dest, 2, 4, packSize);//总包数
490 | setValue(dest, 4, 5, buildType(quotient, remainder, i));//包所在类型
491 | setValue(dest, 5, 10, len);//总数据长度
492 | setValue(dest, 10, 13, MAX_PACK_DATA_SIZE);//当前包data长度
493 | setValue(dest, 13, 14, type);//自定义type
494 |
495 | // Log.d(TAG, "i" + i + " start " + start + " length=" + dest.length);
496 | channel.send(new DataChannel.Buffer(ByteBuffer.wrap(dest), true));
497 | }
498 |
499 | if (remainder != 0) {//不够packSize 的end
500 |
501 | byte[] dest = new byte[remainder + PACK_DATA_START_INDEX];
502 | System.arraycopy(data, len - remainder, dest, PACK_DATA_START_INDEX, remainder);
503 |
504 | setValue(dest, 0, 2, packSize-1);//index
505 | setValue(dest, 2, 4, packSize);//总包数
506 | setValue(dest, 4, 5, 2);//包所在类型
507 | setValue(dest, 5, 10, len);//总数据长度
508 | setValue(dest, 10, 13, remainder);//当前包data长度
509 | setValue(dest, 13, 14, type);//自定义type
510 |
511 | // Log.d(TAG, "remainder=" + remainder);
512 | channel.send(new DataChannel.Buffer(ByteBuffer.wrap(dest), true));
513 | }
514 | return true;
515 | }
516 |
517 | /**
518 | * 把long 型 value 值 转换成byte数组 表示
519 | * 如 setValue(data,0,2,333) 表示在数组中0,1两个byte 中分隔存放 333
520 | *
521 | * @param data
522 | * @param firstPosition 数据存放开始索引
523 | * @param endPosition 数据存放结束索引位置,在数组不包含此位置,如 firstPosition=0,endPosition=2,表示 0,1索引
524 | * @param value 要表示的int值
525 | */
526 | private static void setValue(byte[] data, int firstPosition, int endPosition, long value) {
527 | if (endPosition - firstPosition < 1)
528 | throw new IndexOutOfBoundsException("end - first must > 0 " + endPosition + " - " + firstPosition);
529 |
530 | if (value <= Byte.MAX_VALUE) {//byte -128~127
531 | for (int i = firstPosition; i < endPosition - 1; i++) {
532 | data[i] = 0;
533 | }
534 | data[endPosition - 1] = (byte) value;
535 | } else {
536 | String binary = Long.toBinaryString(value);//二进制
537 | int len = binary.length();
538 | int maxBit = (endPosition - firstPosition) * 7;
539 | if (len > maxBit) {//超出最大可表示数
540 | throw new IndexOutOfBoundsException(value + "--> " + binary + " out of " + maxBit + " bit byte value");
541 | }
542 |
543 | for (int i = endPosition - 1; i >= firstPosition; i--) {
544 | long newValue = value >> 7;//去除后七位
545 | data[i] = (byte) (value - (newValue << 7));//加上七位0,相减就是后七位值
546 | value = newValue;
547 | }
548 | }
549 | }
550 |
551 | /**
552 | * 把fir~end 位的数转换为对应value
553 | *
554 | * @param data
555 | * @param firstPosition
556 | * @param endPosition 如fir=0,end=2,表示0,1两位,不包含索引2
557 | * @return
558 | */
559 | private static long getValue(byte[] data, int firstPosition, int endPosition) {
560 | if (endPosition - firstPosition < 1)
561 | throw new IndexOutOfBoundsException("end - first must > 0 " + endPosition + " - " + firstPosition);
562 |
563 | long value = 0;
564 | int bit = endPosition - firstPosition - 1;
565 | for (int i = firstPosition; i < endPosition; i++, bit--) {
566 | long bitValue = (long) data[i] << (7 * bit);
567 | // System.out.println("bit: " + bit + " bitV=" + bitValue);
568 | value += bitValue;
569 | }
570 | return value;
571 | }
572 |
573 | private int buildType(int size, int footer, int i) {
574 | int type;
575 | if (i == 0)
576 | type = 0;//头
577 | else if (footer == 0) {
578 | if (i != size - 1)
579 | type = 1;//中间部分
580 | else
581 | type = 2;//尾
582 | } else {
583 | type = 1;
584 | }
585 | return type;
586 | }
587 |
588 | public interface IMessageReceiver {
589 | void onReceiverStart();
590 |
591 | void onReceiverProcess(float process);
592 |
593 | void onReceiverSuccess(byte[] data,int type);
594 | }
595 |
596 | }
597 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/aaa.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/drawable/aaa.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
18 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
26 |
27 |
35 |
36 |
37 |
45 |
53 |
54 |
58 |
59 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | P2p控制端
3 | 39.104.185.143
4 | 3000
5 | Options
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jul 31 16:52:20 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/img/aa.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zihao-Wu/AndroidP2pTest/53ac2be5315096ffc4e803c2b2aa892df3a85243/img/aa.png
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Tue Jul 31 16:52:20 CST 2018
11 | ndk.dir=/Users/wzh/Library/Android/sdk/ndk-bundle
12 | sdk.dir=/Users/wzh/Library/Android/sdk
13 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------