forward an WebRTC offer to another peer
767018
function forward (offer) {
  if (offer.answer) {
    peerTable[offer.srcId].socket
      .emit('we-handshake', offer)
    return
  }
  peerTable[offer.dstId].socket
    .emit('we-handshake', offer)
}
975365
function WebRtcPeerRecvonly(options, callback) {
  if (!(this instanceof WebRtcPeerRecvonly)) {
    return new WebRtcPeerRecvonly(options, callback)
  }

  WebRtcPeerRecvonly.super_.call(this, 'recvonly', options, callback)
}
690555
def sendto(self, data, *args):
        '''
        
        '''
        remoteaddr = args[-1]
        remoteaddr = _normalize_addrs(remoteaddr)
        return self._send(data, (self._proto, self._local_addr[0], 
            self._local_addr[1], remoteaddr[0], remoteaddr[1]))
575396
function PeerConnection(portModule, dispatchEvent,
                        RTCPeerConnection, RTCSessionDescription,
                        RTCIceCandidate) {
  // Channel for emitting events to consumer.
  this.dispatchEvent = dispatchEvent;

  // a (hopefully unique) ID for debugging.
  this.peerName = "p" + Math.random();

  // This is the portApp (defined in freedom/src/port-app.js). A way to speak
  // to freedom.
  this.freedomModule = portModule.module;

  // For tests we may mock out the PeerConnection and
  // SessionDescription implementations
  this.RTCPeerConnection = RTCPeerConnection;
  this.RTCSessionDescription = RTCSessionDescription;
  this.RTCIceCandidate = RTCIceCandidate;

  // This is the a channel to send signalling messages.
  this.signallingChannel = null;

  // The DataPeer object for talking to the peer.
  this.peer = null;

  // The Core object for managing channels.
  this.freedomModule.once('core', function (Core) {
    this.core = new Core();
  }.bind(this));
  this.freedomModule.emit(this.freedomModule.controlChannel, {
    type: 'core request delegated to peerconnection',
    request: 'core'
  });
}
865301
def send(x, inter=0, loop=0, count=None, verbose=None, realtime=None, *args, **kargs):
    """"""
    __gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose, realtime=realtime)
199418
function _e2p(emitter, event, options) {
  let p = e2p(emitter, event, options);

  return p.then(() => {
    p.cancel();
    return p;
  })
  .catch(err => {
    p.cancel();
    throw err;
  });
}
1301232
def send(self, out, addr=_MDNS_ADDR, port=_MDNS_PORT):
        """"""
        # This is a quick test to see if we can parse the packets we generate
        #temp = DNSIncoming(out.packet())
        for i in self.intf.values():
            try:
                return i.sendto(out.packet(), 0, (addr, port))
            except:
                traceback.print_exc()
                # Ignore this, it may be a temporary loss of network connection
                return -1
315531
public ForwardToView with(String varName, Object value) {
        attributes.put(varName,value);
        return this;
    }
1260112
def _sendReply(self, destination, fid, *args):
        """"""
        # Try to send the result directly to its parent
        self.addPeer(destination)

        try:
            self.direct_socket.send_multipart([
                destination,
                REPLY,
            ] + list(args),
                flags=zmq.NOBLOCK)
        except zmq.error.ZMQError as e:
            # Fallback on Broker routing if no direct connection possible
            scoop.logger.debug(
                "{0}: Could not send result directly to peer {1}, routing through "
                "broker.".format(scoop.worker, destination)
            )
            self.socket.send_multipart([
                REPLY, 
                ] + list(args) + [
                destination,
            ])

        self.socket.send_multipart([
            STATUS_DONE,
            fid,
        ])
595475
def push(item, remote_addr, trg_queue, protocol=u'jsonrpc'):
    '''  '''
    if protocol == u'jsonrpc':
        try:
            server = Server(remote_addr, encoding=_c.FSQ_CHARSET)
            return server.enqueue(item.id, trg_queue, item.item.read())
        except Exception, e:
            raise FSQPushError(e)

    raise ValueError('Unknown protocol: {0}'.format(protocol))
1313977
def forward
      a = arguments
      sr = symbolic_receiver
      forwardee.module_eval do
        define_method a.message do |*args, &blk|
          args = a.before.(*args) if a.before?
          sr
            .( self, a.target )
            .send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) ).tap do | result |
              break a.after.( result ) if a.after?
            end
        end
      end
    end
27255
function sendRequest(ws, command, params, bReroutable, responseHandler){
	var request = {command: command};
	if (params)
		request.params = params;
	var content = _.clone(request);
	var tag = objectHash.getBase64Hash(request, true);
	//if (ws.assocPendingRequests[tag]) // ignore duplicate requests while still waiting for response from the same peer
	//    return console.log("will not send identical "+command+" request");
	if (ws.assocPendingRequests[tag]){
		console.log('already sent a '+command+' request to '+ws.peer+', will add one more response handler rather than sending a duplicate request to the wire');
		ws.assocPendingRequests[tag].responseHandlers.push(responseHandler);
	}
	else{
		content.tag = tag;
		// after STALLED_TIMEOUT, reroute the request to another peer
		// it'll work correctly even if the current peer is already disconnected when the timeout fires
		var reroute = !bReroutable ? null : function(){
			console.log('will try to reroute a '+command+' request stalled at '+ws.peer);
			if (!ws.assocPendingRequests[tag])
				return console.log('will not reroute - the request was already handled by another peer');
			ws.assocPendingRequests[tag].bRerouted = true;
			findNextPeer(ws, function(next_ws){ // the callback may be called much later if findNextPeer has to wait for connection
				if (!ws.assocPendingRequests[tag])
					return console.log('will not reroute after findNextPeer - the request was already handled by another peer');
				if (next_ws === ws || assocReroutedConnectionsByTag[tag] && assocReroutedConnectionsByTag[tag].indexOf(next_ws) >= 0){
					console.log('will not reroute '+command+' to the same peer, will rather wait for a new connection');
					eventBus.once('connected_to_source', function(){ // try again
						console.log('got new connection, retrying reroute '+command);
						reroute();
					});
					return;
				}
				console.log('rerouting '+command+' from '+ws.peer+' to '+next_ws.peer);
				ws.assocPendingRequests[tag].responseHandlers.forEach(function(rh){
					sendRequest(next_ws, command, params, bReroutable, rh);
				});
				if (!assocReroutedConnectionsByTag[tag])
					assocReroutedConnectionsByTag[tag] = [ws];
				assocReroutedConnectionsByTag[tag].push(next_ws);
			});
		};
		var reroute_timer = !bReroutable ? null : setTimeout(reroute, STALLED_TIMEOUT);
		var cancel_timer = bReroutable ? null : setTimeout(function(){
			ws.assocPendingRequests[tag].responseHandlers.forEach(function(rh){
				rh(ws, request, {error: "[internal] response timeout"});
			});
			delete ws.assocPendingRequests[tag];
		}, RESPONSE_TIMEOUT);
		ws.assocPendingRequests[tag] = {
			request: request,
			responseHandlers: [responseHandler], 
			reroute: reroute,
			reroute_timer: reroute_timer,
			cancel_timer: cancel_timer
		};
		sendMessage(ws, 'request', content);
	}
	return tag;
}
220608
function rtcPipe(link, initiate)
  {
    // existing noop
    if(link.rtcPipe) return link.rtcPipe;

    // outgoing signal cache and sender
    var signals = [];
    function signal(sig){
      if(signals.indexOf(sig) == -1) signals.push(sig);
      if(!link.x) return;
      // send each signal as an individual lossy channel
      var json = {type:'webrtc',c:link.x.cid()};
      json.signal = sig;
      mesh.log.debug('sending signal to',link.hashname,json);
      link.x.send({json:json});
    }

    // new pipe
    var pipe = link.rtcPipe = new telehash.Pipe('webrtc');
    pipe.cloaked = true;
    pipe.id = link.hashname;
    pipe.path = {type:'webrtc'};
    
    // handle outgoing packets based on rtc state
    pipe.onSend = function(packet, link, cb){
      if(!packet) return cb('no packet');
      var safe = packet.toString('base64')
      if(link.rtc.connected)
      {
        mesh.log.debug('rtc send',safe.length);
        link.rtc.send(safe);
        return cb();
      }
      mesh.log.debug('rtc still signalling',signals.length);
      // cache most recent packet
      link.rtc.cached = safe;
      if(!link.up) return cb('not connected');
      // if there's signals yet, resend them as they could have been lost
      signals.forEach(signal);
    }

    // new webrtc connection
    link.rtc = new rtc.peer({initiate:initiate, _self:'self', _peer:link.hashname});
    link.rtc.DEBUG = true;
    link.rtc.onsignal = signal;
    link.rtc.onconnection = function() {
      mesh.log.debug('RTC CONNECTED');
      link.rtc.connected = true;
      signals = []; // empty any cached signals too
      if(link.rtc.cached) link.rtc.send(link.rtc.cached);
      link.rtc.cached = false;
    }
    link.rtc.onmessage = function(safe) {
      mesh.log.debug('rtc receive',safe.length);
      var packet = lob.decloak(new Buffer(safe,'base64'));
      if(!packet) return mesh.log.info('dropping invalid packet',safe);
      mesh.receive(packet,pipe);
    }
    
    return pipe;
  }
795487
def invite_other_parties(self, possible_owners):
        
        signals.lane_user_change.send(sender=self.user,
                                      current=self,
                                      old_lane=self.old_lane,
                                      possible_owners=possible_owners
                                      )
1262948
function WebRTCSession(params) {
    this.ID = params.sessionID ? params.sessionID : generateUUID();
    this.state = WebRTCSession.State.NEW;

    this.initiatorID = parseInt(params.initiatorID);
    this.opponentsIDs = params.opIDs;
    this.callType = parseInt(params.callType);

    this.peerConnections = {};

    this.localStream = null;

    this.mediaParams = null;

    this.signalingProvider = params.signalingProvider;

    this.currentUserID = params.currentUserID;

    this.bandwidth = params.bandwidth;

    /**
     * We use this timeout to fix next issue:
     * "From Android/iOS make a call to Web and kill the Android/iOS app instantly. Web accept/reject popup will be still visible.
     * We need a way to hide it if sach situation happened."
     */
    this.answerTimer = null;

    this.startCallTime = 0;
    this.acceptCallTime = 0;
}
1242410
def sendRtspRequest(self, requestCode):
    """"""
    #-------------
    # TO COMPLETE
    #-------------

    # Setup request
    if requestCode == self.SETUP and self.state == self.INIT:
      threading.Thread(target=self.recvRtspReply).start()
      # Update RTSP sequence number.
      # ...
      self.rtspSeq = 1

      # Write the RTSP request to be sent.
      # request = ...
      request = "SETUP " + str(self.fileName) + "\n" + str(self.rtspSeq) + "\n" + " RTSP/1.0 RTP/UDP " + str(self.rtpPort)

      self.rtspSocket.send(request)
      # Keep track of the sent request.
      # self.requestSent = ...
      self.requestSent = self.SETUP

    # Play request
    elif requestCode == self.PLAY and self.state == self.READY:
      # Update RTSP sequence number.
      # ...
      self.rtspSeq = self.rtspSeq + 1
      # Write the RTSP request to be sent.
      # request = ...
      request = "PLAY " + "\n" + str(self.rtspSeq)

      self.rtspSocket.send(request)
      print('-'*60 + "\nPLAY request sent to Server...\n" + '-'*60)
      # Keep track of the sent request.
      # self.requestSent = ...
      self.requestSent = self.PLAY

    # Pause request
    elif requestCode == self.PAUSE and self.state == self.PLAYING:
      # Update RTSP sequence number.
      # ...
      self.rtspSeq = self.rtspSeq + 1
      # Write the RTSP request to be sent.
      # request = ...
      request = "PAUSE " + "\n" + str(self.rtspSeq)
      self.rtspSocket.send(request)
      print('-'*60 + "\nPAUSE request sent to Server...\n" + '-'*60)
      # Keep track of the sent request.
      # self.requestSent = ...
      self.requestSent = self.PAUSE

    # Resume request


    # Teardown request
    elif requestCode == self.TEARDOWN and not self.state == self.INIT:
      # Update RTSP sequence number.
      # ...
      self.rtspSeq = self.rtspSeq + 1
      # Write the RTSP request to be sent.
      # request = ...
      request = "TEARDOWN " + "\n" + str(self.rtspSeq)
      self.rtspSocket.send(request)
      print('-'*60 + "\nTEARDOWN request sent to Server...\n" + '-'*60)
      # Keep track of the sent request.
      # self.requestSent = ...
      self.requestSent = self.TEARDOWN

    else:
      return
483722
function onPeerConnected(peer)
    {
        if(scope.localStream)
        {
            peer.updateStream(scope.localStream,false);
        }
        scope._servConn.sendRTCState(true,peer.id);

        scope.dispatchEvent("peerConnected",peer.id);
    }