SCRtcFactory.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class SCRtcFactory
  6. {
  7. private static SCRtcFactory _instance;
  8. public static SCRtcFactory Instance
  9. {
  10. get
  11. {
  12. if (_instance == null)
  13. {
  14. _instance = new SCRtcFactory();
  15. }
  16. return _instance;
  17. }
  18. }
  19. public SCRtcManager mSCRtcManager;
  20. public SCRtcHandle mSCRtcHandle;
  21. public SCRtcMe mSCRtcMe;
  22. public SCRtcPeers mSCRtcPeers;
  23. public bool isClose = true;
  24. public SCRtcFactory()
  25. {
  26. mSCRtcHandle = SCRtcHandle.Instance;
  27. }
  28. public SCRtcConfig mSCRtcConfig;
  29. public void init(SCRtcConfig sRtc, SCRtcManager ms, SCRtcMe me, SCRtcPeers sPeers=null)
  30. {
  31. this.mSCRtcConfig = sRtc;
  32. if (sPeers != null)
  33. {
  34. this.mSCRtcPeers = sPeers;
  35. }
  36. else
  37. {
  38. this.mSCRtcPeers = new SCRtcPeers();
  39. }
  40. this.mSCRtcManager = ms;
  41. if (me != null)
  42. {
  43. this.mSCRtcMe = me;
  44. }
  45. else
  46. {
  47. this.mSCRtcMe = new SCRtcMe();
  48. }
  49. mSCRtcHandle.InitRTC(sRtc);
  50. isClose = false;
  51. }
  52. public void Close()
  53. {
  54. this.mSCRtcHandle.Close();
  55. //
  56. }
  57. public void Update()
  58. {
  59. if(!isClose)
  60. {
  61. mSCRtcHandle.goThread();
  62. if (this.mSCRtcManager != null)
  63. {
  64. if (this.mSCRtcManager.queue.Count > 0)
  65. this.mSCRtcManager.OnRtcListener(this.mSCRtcManager.queue.Dequeue());
  66. }
  67. if (mSCRtcMe != null)
  68. mSCRtcMe.updateTexture();
  69. if (mSCRtcPeers != null)
  70. mSCRtcPeers.updateTextures();
  71. }
  72. }
  73. }