# Namespace: webrtc

## webrtc

Manage the WebRTC peer to peer communication channels. This objects contains all the necessary client-side WebRTC components, allowing browsers to use WebRTC to communicate with each other. To provide signaling, the WebRTC extension sets up custom listeners. /rtcsignal - for sending RTC signalling information between peers /rtcmessage - for client-side rtc messages to be submitted back into beef and logged.

To ensure signaling gets back to the peers, the hook.js dynamic construction also includes the signalling.

This is all mostly a Proof of Concept

Source:
  - webrtc.js, line 8

### Members

#### (static) beefrtcs

To handle multiple peers - we need to have a hash of Beefwebrtc objects. The key is the peer id.

Source:
  - webrtc.js, line 27

#### (static) globalrtc

To handle multiple Peers - we have to have a global hash of RTCPeerConnection objects these objects persist outside of everything else. The key is the peer id.

Source:
  - webrtc.js, line 33

#### (static) rtcrecvchan

To handle multiple event channels - we need to have a global hash of these. The key is the peer id

Source:
  - webrtc.js, line 45

#### (static) rtcstealth

stealth should only be initiated from one peer - this global variable will contain: false - i.e not stealthed; or - i.e. the id of the browser which initiated stealth mode

Source:
  - webrtc.js, line 40

### Methods

#### (static) Beefwebrtc(initiator, peer, turnjson, stunservers, verbparam)

Beefwebrtc object - wraps everything together for a peer connection One of these per peer connection, and will be stored in the beefrtc global hash

##### Parameters:

Name | Type | Description
--- | --- | ---
`initiator` |  |
`peer` |  |
`turnjson` |  |
`stunservers` |  |
`verbparam` |  |

Source:
  - webrtc.js, line 57

#### (static) Beefwebrtc#calleeStart()

Check for messages - which includes signaling from a calling peer - this gets kicked off in maybeStart()

Source:
  - webrtc.js, line 529

#### (static) Beefwebrtc#createPeerConnection()

Try and establish the RTC connection

Source:
  - webrtc.js, line 136

#### (static) Beefwebrtc#doAnswer()

As part of the processSignalingMessage function, we check for 'offers' from peers. If there's an offer, we answer, as below

Source:
  - webrtc.js, line 621

#### (static) Beefwebrtc#doCall()

RTC - create an offer - the caller runs this, while the receiver runs calleeStart()

Source:
  - webrtc.js, line 460

#### (static) Beefwebrtc#execCmd()

How the browser executes received JS (this is pretty hacky)

Source:
  - webrtc.js, line 415

#### (static) Beefwebrtc#forceTurn()

Forces the TURN configuration (we can't query that computeengine thing because it's CORS is restrictive) These values are now simply passed in from the config.yaml for the webrtc extension

Source:
  - webrtc.js, line 119

#### (static) Beefwebrtc#goStealth()

This is the function when a peer tells us to go into stealth by sending a dataChannel message of "!gostealth"

Source:
  - webrtc.js, line 314

#### (static) Beefwebrtc#iceCandidateType()

Helper method to determine what kind of ICE Candidate we've received

Source:
  - webrtc.js, line 630

#### (static) Beefwebrtc#initialize()

Initialize the object

Source:
  - webrtc.js, line 86

#### (static) Beefwebrtc#maybeStart()

Try and initiate, will check that system hasn't started, and that signaling is ready, and that TURN servers are ready

Source:
  - webrtc.js, line 434

#### (static) Beefwebrtc#mergeConstraints()

Helper method to merge SDP constraints

Source:
  - webrtc.js, line 472

#### (static) Beefwebrtc#noteIceCandidate()

Used to record ICS candidates locally

Source:
  - webrtc.js, line 245

#### (static) Beefwebrtc#onAddIceCandidateError()

Event handler for unsuccessful addition of ICE Candidates

Source:
  - webrtc.js, line 652

#### (static) Beefwebrtc#onAddIceCandidateSuccess()

Event handler for successful addition of ICE Candidates

Source:
  - webrtc.js, line 644

#### (static) Beefwebrtc#onCreateSessionDescriptionError()

If the browser can't build an SDP

Source:
  - webrtc.js, line 513

#### (static) Beefwebrtc#onDataChannel()

When a data channel has been established - within here is the message handling function as well

Source:
  - webrtc.js, line 345

#### (static) Beefwebrtc#onIceCandidate()

When the PeerConnection receives a new ICE Candidate

Source:
  - webrtc.js, line 165

#### (static) Beefwebrtc#onIceConnectionStateChanged()

When the ICE Connection State changes - this is useful to determine connection statuses with peers.

Source:
  - webrtc.js, line 265

#### (static) Beefwebrtc#onRemoteHangup()

If a peer hangs up (we bring down the peerconncetion via the stop() method)

Source:
  - webrtc.js, line 660

#### (static) Beefwebrtc#onSetRemoteDescriptionSuccess()

If the browser successfully sets a remote description

Source:
  - webrtc.js, line 521

#### (static) Beefwebrtc#onSignalingStateChanged()

When the signalling state changes. We don't actually do anything with this except log it.

Source:
  - webrtc.js, line 257

#### (static) Beefwebrtc#processMessage()

For all rtc signalling messages we receive as part of hook.js polling - we have to process them with this function This will either add messages to the msgQueue and try and kick off maybeStart - or it'll call processSignalingMessage against the message directly

Source:
  - webrtc.js, line 196

#### (static) Beefwebrtc#processSignalingMessage()

Process messages, this is how we handle the signaling messages, such as candidate info, offers, answers

Source:
  - webrtc.js, line 540

#### (static) Beefwebrtc#sendPeerMsg()

Shortcut function to SEND a data messsage

Source:
  - webrtc.js, line 425

#### (static) Beefwebrtc#sendSignalMsg()

Send a signalling message ..

Source:
  - webrtc.js, line 235

#### (static) Beefwebrtc#setRemote()

Used to set the RTC remote session

Source:
  - webrtc.js, line 612

#### (static) Beefwebrtc#stop()

Bring down the peer connection

Source:
  - webrtc.js, line 671

#### (static) rtcpollPeer()

This is the actual poller when in stealth, it is global as well because we're using the setTimeout to execute it

Source:
  - webrtc.js, line 327