Code Monkey home page Code Monkey logo

chattest's Introduction

Extremly simple chat

An example chat application showing how to abstract away PeerConnection as a DOM element using Web Components

Why

Since webRTC is still changing quickly, highly coupled to the browser environment and inherently between two instances it makes sense to abstract it away. Web Components seems like an ideal solution as it abstracts DOM elements behind higher level DOM elements. <appear-in></appear-in> is an attempt at making such an element and it looks like this: <appear-in peerId='anId' local=stream remote=stream></appear-in>.

By giving the element an id and a local stream the remote stream will correspond to another <appear-in /> tag somewhere on the internet.

How

When both peerId and local is set a websocket is created to facilitate the PeerConnection handshake and on success it will close. In this way there is no persistence, state or even server interaction beyond the inital setup.

Again .. why !?

By doing this

  • webRTC is abstracted away leaving you free to make the service as you want
  • The element is a standard DOM element. Gives lots of new flexibility for third party integration
  • The signaling is pure websocket without any libraries on top. Handshake can be standardized after RFC 6455

Scalability

Since there is no state each pair only needs two server connections for the duration of the handshake (seconds). Also, server partitioning can be done by url load balancing as the peerId is given in the url. i.e:

var signaling_channel = new WebSocket('ws://signalingserver.com/someCommonPeerId'); (Done internalliy by the <appear-in /> element)

Also, since the resulting chat server is now so simple it doesn't depend on any state outside socket.io and the socket.io store and will thus 'just work' with e.g. redis.

How to

This example have two servers: One RTC signaling server (server.js) and one chat room server using the <appear-in /> element (chat.js). They are completely separate. The chat application uses chat.js while the <appear-in /> element uses server.js behind the scenes.

chattest's People

Contributors

olavhn avatar

Watchers

Mattis Eeten-Jeppsson avatar  avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.