Signaling.gd 704 B

12345678910111213141516171819202122232425262728293031
  1. # A local signaling server. Add this to autoloads with name "Signaling" (/root/Signaling)
  2. extends Node
  3. # We will store the two peers here
  4. var peers = []
  5. func register(path):
  6. assert(peers.size() < 2)
  7. peers.append(path)
  8. if peers.size() == 2:
  9. get_node(peers[0]).peer.create_offer()
  10. func _find_other(path):
  11. # Find the other registered peer.
  12. for p in peers:
  13. if p != path:
  14. return p
  15. return ""
  16. func send_session(path, type, sdp):
  17. var other = _find_other(path)
  18. assert(other != "")
  19. get_node(other).peer.set_remote_description(type, sdp)
  20. func send_candidate(path, mid, index, sdp):
  21. var other = _find_other(path)
  22. assert(other != "")
  23. get_node(other).peer.add_ice_candidate(mid, index, sdp)