SCRtcPeers.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SCRtcPeers
  5. {
  6. private Dictionary<string, SCRtcPeer> mSCRtcPeers = new Dictionary<string, SCRtcPeer>();
  7. private List<string> paixuPeer = new List<string>();
  8. public virtual SCRtcPeer addPeers(string pid)
  9. {
  10. if (!mSCRtcPeers.ContainsKey(pid))
  11. {
  12. SCRtcPeer sp = new SCRtcPeer();
  13. sp.peerId = pid;
  14. mSCRtcPeers.Add(pid, sp);
  15. paixuPeer.Add(pid);
  16. return sp;
  17. }
  18. return null;
  19. }
  20. public virtual SCRtcPeer addPeers(SCRtcPeer scp)
  21. {
  22. if (!mSCRtcPeers.ContainsKey(scp.peerId))
  23. {
  24. SCRtcPeer sp = scp;
  25. mSCRtcPeers.Add(scp.peerId, sp);
  26. paixuPeer.Add(scp.peerId);
  27. return sp;
  28. }
  29. return null;
  30. }
  31. public void updateTextures()
  32. {
  33. foreach (SCRtcPeer value in getPeers().Values)
  34. {
  35. value.updateTexture();
  36. }
  37. }
  38. public virtual void removePeers(string name)
  39. {
  40. if (mSCRtcPeers.ContainsKey(name))
  41. {
  42. mSCRtcPeers.Remove(name);
  43. paixuPeer.Remove(name);
  44. }
  45. }
  46. public virtual Dictionary<string, SCRtcPeer> getPeers()
  47. {
  48. return mSCRtcPeers;
  49. }
  50. public virtual List<string> getPaiXuPeers()
  51. {
  52. return paixuPeer;
  53. }
  54. public virtual SCRtcPeer getPeerName(string name)
  55. {
  56. foreach(SCRtcPeer v in mSCRtcPeers.Values)
  57. {
  58. if(v.name==name)
  59. {
  60. Debug.Log("查找到===>" + name);
  61. return v;
  62. }
  63. }
  64. return null;
  65. }
  66. public virtual SCRtcPeer getPeer(string name)
  67. {
  68. if (mSCRtcPeers.ContainsKey(name))
  69. {
  70. return mSCRtcPeers[name];
  71. }
  72. return null;
  73. }
  74. public void initPeers()
  75. {
  76. mSCRtcPeers = new Dictionary<string, SCRtcPeer>();
  77. if (paixuPeer.Count > 0)
  78. {
  79. paixuPeer.Clear();
  80. }
  81. paixuPeer = new List<string>();
  82. }
  83. }