Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Peer

A class to represent a Peer. Functions config(), setLocalDescription() and listenToMsg() are based on the code from https://github.com/ScaleDrone/webrtc-text-chat-tutorial/blob/master/script.js .

Hierarchy

  • Peer

Index

Constructors

constructor

Properties

actionManager

actionManager: ActionManager

Action Manager that represent the user.

color

color: string

Color to be used to represend this peer.

connection

connection: RTCPeerConnection

WebRTC connection to the peer.

dataChannel

dataChannel: RTCDataChannel

Data channel between the two peers to send message.

isOfferer

isOfferer: boolean

If isOfferer, this peer is the one asking to connect, i.e. is a new peer.

peerId

peerId: string

Id of the peer

signalingChannel

signalingChannel: SignalingChannel

SignalingChannel to use during the ICE framework.

Static colorList

colorList: string[] = ["#E69F00", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#000000"]

List of possible color for the peers.

Static index

index: number = 0

Current index in the list of color.

Methods

Private config

  • config(): void

Private listenToMsg

  • listenToMsg(): void
  • Listen to messages received through the signaling channel.

    Returns void

Private onDataChannelOpen

  • onDataChannelOpen(): void
  • When the data channel is open, emit an event that a new user is connected and send the current state of the application.

    Returns void

Private onPeerMsg

  • onPeerMsg(event: MessageEvent): void
  • Reconstructs events receive from a peer then emit them.

    Parameters

    • event: MessageEvent

      event to reconstruc.

    Returns void

Private send

  • send(msg: string): void
  • Sends a message through the data channel to the peer.

    Parameters

    • msg: string

      Message to send.

    Returns void

Private sendActionEvent

  • Sends action event throught the data channel to the peer if the action was done by the user.

    Parameters

    Returns void

Private sendCurrentState

  • sendCurrentState(): void
  • Sends current state of the application to newly connected peer.

    Returns void

Private sendEvent

  • sendEvent(event: Event): void
  • Sends an event through the data channel to the peer.

    Parameters

    • event: Event

      Event to send.

    Returns void

Private setLocalDescription

  • setLocalDescription(description: RTCSessionDescriptionInit): void
  • Create and set the local description for the RTCPeerConnection. Then send the description to the peer.

    Parameters

    • description: RTCSessionDescriptionInit

      RTCSessionDescriptionInit to use to create the local description.

    Returns void

Private setRemoteDescription

  • setRemoteDescription(description: RTCSessionDescriptionInit): void
  • Create and set the remote description for the RTCPeerConnection. If the description is an offer, then send an answer to the peer.

    Parameters

    • description: RTCSessionDescriptionInit

      RTCSessionDescriptionInit to use to create the remote description.

    Returns void

Private setupColor

  • setupColor(): void

setupDataChannel

  • setupDataChannel(): void
  • Setup the data channel to use for communication between the peers.

    Returns void

Private setupEventHandler

  • setupEventHandler(): void

Generated using TypeDoc