|
@ -199,7 +199,7 @@ class WebRTCCamera(Thread): |
|
|
self._queue.put({'job':'emit', 'event':event, 'data':data}) |
|
|
self._queue.put({'job':'emit', 'event':event, 'data':data}) |
|
|
|
|
|
|
|
|
def send_battery(self, val, arg): |
|
|
def send_battery(self, val, arg): |
|
|
print("sending battery value %s" % val) |
|
|
#print("sending battery value %s" % val) |
|
|
self.emit_async('battery', val) |
|
|
self.emit_async('battery', val) |
|
|
|
|
|
|
|
|
def start_global_pipeline(self): |
|
|
def start_global_pipeline(self): |
|
@ -332,7 +332,7 @@ class WebRTCCamera(Thread): |
|
|
del self._peers[client_sid] |
|
|
del self._peers[client_sid] |
|
|
|
|
|
|
|
|
def handle_sdp_answer(self, sdp, client_sid): |
|
|
def handle_sdp_answer(self, sdp, client_sid): |
|
|
print("handle_sdp_answer") |
|
|
#print("handle_sdp_answer") |
|
|
#print ('Received answer:\n%s' % sdp) |
|
|
#print ('Received answer:\n%s' % sdp) |
|
|
res, sdpmsg = GstSdp.SDPMessage.new() |
|
|
res, sdpmsg = GstSdp.SDPMessage.new() |
|
|
GstSdp.sdp_message_parse_buffer(bytes(sdp.encode()), sdpmsg) |
|
|
GstSdp.sdp_message_parse_buffer(bytes(sdp.encode()), sdpmsg) |
|
@ -345,7 +345,7 @@ class WebRTCCamera(Thread): |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
def handle_ice(self, ice, client_sid): |
|
|
def handle_ice(self, ice, client_sid): |
|
|
print("handle_ice") |
|
|
#print("handle_ice") |
|
|
candidate = ice['candidate'] |
|
|
candidate = ice['candidate'] |
|
|
if not candidate or candidate == '': |
|
|
if not candidate or candidate == '': |
|
|
print("candidate string is empty") |
|
|
print("candidate string is empty") |
|
@ -354,18 +354,18 @@ class WebRTCCamera(Thread): |
|
|
self._peers[client_sid]['webrtcbin'].emit('add-ice-candidate', sdpmlineindex, candidate) |
|
|
self._peers[client_sid]['webrtcbin'].emit('add-ice-candidate', sdpmlineindex, candidate) |
|
|
|
|
|
|
|
|
def on_negotiation_needed(self, receiver_entry, client_sid): |
|
|
def on_negotiation_needed(self, receiver_entry, client_sid): |
|
|
print("on_negotiation_needed [%s]" % client_sid) |
|
|
#print("on_negotiation_needed [%s]" % client_sid) |
|
|
promise = Gst.Promise.new_with_change_func(self.on_offer_created, receiver_entry, client_sid, None) |
|
|
promise = Gst.Promise.new_with_change_func(self.on_offer_created, receiver_entry, client_sid, None) |
|
|
receiver_entry.emit('create-offer', None, promise) |
|
|
receiver_entry.emit('create-offer', None, promise) |
|
|
|
|
|
|
|
|
def on_ice_candidate(self, _, mlineindex, candidate, client_sid): |
|
|
def on_ice_candidate(self, _, mlineindex, candidate, client_sid): |
|
|
print("on_ice_candidate [%s]" % client_sid) |
|
|
#print("on_ice_candidate [%s]" % client_sid) |
|
|
icemsg = json.dumps({'type': 'ice', 'data': {'candidate': candidate, 'sdpMLineIndex': mlineindex}, 'sid': client_sid}) |
|
|
icemsg = json.dumps({'type': 'ice', 'data': {'candidate': candidate, 'sdpMLineIndex': mlineindex}, 'sid': client_sid}) |
|
|
sio.emit('message', data=icemsg) |
|
|
sio.emit('message', data=icemsg) |
|
|
|
|
|
|
|
|
# Offer created by our pipeline, to be sent to the peer |
|
|
# Offer created by our pipeline, to be sent to the peer |
|
|
def on_offer_created(self, promise, _, client_sid, __): |
|
|
def on_offer_created(self, promise, _, client_sid, __): |
|
|
print("on_offer_created [%s]" % client_sid) |
|
|
#print("on_offer_created [%s]" % client_sid) |
|
|
promise.wait() |
|
|
promise.wait() |
|
|
reply = promise.get_reply() |
|
|
reply = promise.get_reply() |
|
|
offer = reply['offer'] |
|
|
offer = reply['offer'] |
|
@ -373,10 +373,9 @@ class WebRTCCamera(Thread): |
|
|
self._peers[client_sid]['webrtcbin'].emit('set-local-description', offer, promise) |
|
|
self._peers[client_sid]['webrtcbin'].emit('set-local-description', offer, promise) |
|
|
promise.interrupt() |
|
|
promise.interrupt() |
|
|
text = offer.sdp.as_text() |
|
|
text = offer.sdp.as_text() |
|
|
print ('Sending offer:\n%s' % text) |
|
|
#print ('Sending offer:\n%s' % text) |
|
|
msg = json.dumps({'type': 'sdp', 'data': {'type': 'offer', 'sdp': text}, 'sid': client_sid}) |
|
|
msg = json.dumps({'type': 'sdp', 'data': {'type': 'offer', 'sdp': text}, 'sid': client_sid}) |
|
|
sio.emit('message', data=msg) |
|
|
sio.emit('message', data=msg) |
|
|
print("test") |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('message') |
|
|
@sio.on('message') |
|
|
def webrtc_message(data): |
|
|
def webrtc_message(data): |
|
@ -407,12 +406,12 @@ class WebRTCCamera(Thread): |
|
|
print("Received SDP message without SDP string") |
|
|
print("Received SDP message without SDP string") |
|
|
return |
|
|
return |
|
|
if data['data']['type'] == 'answer': |
|
|
if data['data']['type'] == 'answer': |
|
|
print("Received SDP answer:") |
|
|
#print("Received SDP answer:") |
|
|
print(data['data']['sdp']) |
|
|
#print(data['data']['sdp']) |
|
|
webrtccamera.handle_sdp_answer(data['data']['sdp'], client_sid) |
|
|
webrtccamera.handle_sdp_answer(data['data']['sdp'], client_sid) |
|
|
elif data['data']['type'] == 'offer': |
|
|
elif data['data']['type'] == 'offer': |
|
|
print("Received SDP offer:") |
|
|
#print("Received SDP offer:") |
|
|
print(data['data']['sdp']) |
|
|
#print(data['data']['sdp']) |
|
|
webrtccamera.handle_sdp_offer(data['data']['sdp'], client_sid) |
|
|
webrtccamera.handle_sdp_offer(data['data']['sdp'], client_sid) |
|
|
else: |
|
|
else: |
|
|
print("Expected SDP message type \"answer\", got \"%s\"" % data['data']['type']) |
|
|
print("Expected SDP message type \"answer\", got \"%s\"" % data['data']['type']) |
|
@ -422,8 +421,8 @@ class WebRTCCamera(Thread): |
|
|
print("Received ICE message without mline index") |
|
|
print("Received ICE message without mline index") |
|
|
return |
|
|
return |
|
|
if 'candidate' in data['data']: |
|
|
if 'candidate' in data['data']: |
|
|
print("Received ICE candidate with mline index %u" % data['data']['sdpMLineIndex']) |
|
|
#print("Received ICE candidate with mline index %u" % data['data']['sdpMLineIndex']) |
|
|
print(data['data']['candidate']) |
|
|
#print(data['data']['candidate']) |
|
|
webrtccamera.handle_ice(data['data'], client_sid) |
|
|
webrtccamera.handle_ice(data['data'], client_sid) |
|
|
else: |
|
|
else: |
|
|
print("Received ICE message without ICE candidate string") |
|
|
print("Received ICE message without ICE candidate string") |
|
|