5.0.0 • Published 5 years ago

the-talk v5.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

the-talk

Build Status npm Version JS Standard

Talking via webrtc

Installation

$ npm install the-talk --save

Usage

'use strict'

import React from 'react'
import { TheTalk, TheTalkStyle } from 'the-talk'
import { TheSpinStyle } from 'the-spin'
import { TheButtonStyle } from 'the-button'
import { TheRTCClient } from 'the-rtc-client'

class ExampleComponent extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      localClient: null,
      remoteClients: {}
    }
    this.renderRemoteClient = this.renderRemoteClient.bind(this)
    this.rtcClient = null
    this.renderLocalClient = this.renderLocalClient.bind(this)
  }

  componentDidMount () {
    void this.joinToTalk()
  }

  async joinToTalk () {
    const rtcClient = new TheRTCClient({
      // Additional info
      info: {
        userAgent: navigator.userAgent,
        who: `user-${new Date().getTime()}`
      },
      onLocal: (localClient) => {
        this.setState({localClient})
      },
      onRemote: (remoteClient) => {
        const {rid} = remoteClient
        this.setState({
          remoteClients: {
            ...this.state.remoteClients,
            [rid]: remoteClient,
          },
        })
      }
    })
    await rtcClient.connect(`http://localhost:3000`)
    await rtcClient.join(`the-talk-example-room-${new Date().getFullYear()}`)
    this.rtcClient = rtcClient
  }

  render () {
    const {localClient, remoteClients} = this.state
    return (
      <div>
        <TheSpinStyle/>
        <TheButtonStyle/>
        <TheTalkStyle/>
        <TheTalk {...{localClient, remoteClients}}
                 onToggleVideo={(videoEnabled) => this.rtcClient.toggleVideoEnabled(videoEnabled)}
                 onToggleAudio={(audioEnabled) => this.rtcClient.toggleAudioEnabled(audioEnabled)}
                 renderRemoteClient={this.renderRemoteClient}
                 renderLocalClient={this.renderLocalClient}
        />
      </div>

    )
  }

  renderRemoteClient (state) {

  }

  renderLocalClient ({info}) {
    return (
      <span>{`${info.who} (${info.userAgent})`}</span>
    )
  }
}

export default ExampleComponent

Components

TheTalk

Talking via webrtc

Props

NameTypeDescriptionDefault
localClientobjectHandle videonull
onVideofunc
remoteClientsobjectOf object{}
renderLocalClientfunc() => null
renderRemoteClientfunc() => null
videoHeightunionHeight of video
localVideoHeight100
remoteVideoHeight200

TheTalkStyle

Style for TheTalk

Props

NameTypeDescriptionDefault
optionsobjectStyle options{}

License

This software is released under the MIT License.

Links

5.0.0

5 years ago

3.0.2

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.3.5

6 years ago

2.3.4

6 years ago

2.3.3

6 years ago

2.3.2

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago