• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Engineering Semester

Explore the technology

  • Home
  • About
  • Contact us

WebRTC Programming – Start with signaling server in Node.js

By : VINAY KP Filed Under: networking, webRTC Leave a Comment

I already explained the importance of a WebRTC signaling server through my last post  . Consequently lets move to the programming section of webRTC . In this post i want to explain a simple basic signaling server with Node.Js web socket method . If your new to the term Node.Js and webSocket , please just go through the basics of Node.Js and webSocket .

If your new to this webRTC series , please check the previous especially relevant posts

WebRTC introduction : Introduction to the browser technology 

furthermore check other post too

getusermedia API : browser getusermedia API

RTCPeerconnection API : RTCPeerconnection API

What is signaling server ?

Signaling server helps to identify and collect sharing information of the peer user . Meanwhile check the our previous guide about signaling server and protocols and signaling process in webRTC .

What is web server ?

I think most of all familiar with the word web server . isn’t ? If not , web server is a program that serve different pages to users via HTTP (Hypertext Transfer Protocol ) request . In WebRTC , We uses a signaling server to get the information of the peer users .

Why WebSocket ?

WebSocket is one of the asynchronous method to communicate between the server and the client . The communication takes place over TCP socket using ws (unsecure) or wss (secure) protocol . WebSocket is currently implemented in all latest browsers .

Why Node.Js ?

Node.Js is an open source server framework . It can run on different Operating system (Windows , Linux , MAC etc . ). It uses javascript on the server to run the framework . The benefit of Node.Js includes

  • Asynchronous Input output communication .
  • It is a Event driver I/O server-side javascript environment .
  • It is a very fast due to the javascript in the back end .

Afterwards you can check more about node.Js

Start a basic webRTC signaling server

Next let’s move to the programming of a signaling server with Node.Js webSocket  . This is the basic code using webSocket with Node.Js .

var WebSocketServer = require('ws').Server,
    wss = new WebSocketServer({ port: 8888 });

wss.on('listening', function () {
	console.log("Server started...");
});

wss.on('connection', function (connection) {
   console.log("User connected");

  //message function
   connection.on('message', function (message) {	
     console.log("message from user");
  });
  
  //close the connection
  connection.on('close', function () {
    console.log("Disconnecting user");
  });

});

This code snippet handle open, message and close connection of a signaling server . The first lines of the code snippet opens a webSocket instance wss . Next line open the connection with port 8888 .

If any user is connected to the server , it will handle the connection request by listening handler . Finally the connection is closed with the connection close handler .

How to run the server ?

first of all you should ensure whether you are installed all node package . You can check the node version with node -v or node –version command .  If your signaling server named as server.js , then you can run the server with node server.js  command. If the server is success in execution , then you can see the message “server started” on the console .

If you are interested and you want to test with writing  webRTC application from scratch , Just go though our posts ,  Write a WebRTC Application – Programming from scratch 

  • Part 1 – How to Create a Simple App Like A Pro 
  • Part 2 – Create a server with Node.js for the App
  • Part 3 – Design your first WebRTC App

Conclusion

You will get an idea about how to write a basic signaling server through this post . Also you can get a overall idea about node.Js and webSocket too . If you have in any case a query or suggestion , you can write it on comment section of this post .

If this post is useful and informative, of course don’t forget to share our post or recommend this post to your friends

Recommended Posts

Default ThumbnailIntroduction of WebRTC technology in Modern browsers Default ThumbnailWebRTC – Access user media with getUserMedia API Default ThumbnailWebRTC – signaling process and it’s importance in communication
Previous: Walk through WebRTC environment and it’s protocol
Next: Importance of Application server in Web technology

About the Author

Vinay KP is the founder of Engineering Semester blog . He is currently working as a software engineer . He is a very passionate blogger with Interest in research oriented technical articles .

You can contact via

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Latest post

  • WebRTC programming Part 3 – Design your first WebRTC App
  • WebRTC programming Part 2 – Create a server with Node.js for the App
  • WebRTC programming Part 1 – How to Create a Simple App Like A Pro
  • Why you need a signaling server in WebRTC application – You can think it
  • what is adaptive streaming and how it works on video player ?

Footer

About Admin

Welcome to Engineering Semester. I'm Vinay KP. founder and brain behind of this blog. You can feel free to contact me via





Categories

  • application server (4)
  • HTML5 (1)
  • Javascript (1)
  • kinect (1)
  • linux (2)
  • microsoft (1)
  • networking (12)
  • NodeJS (1)
  • streaming (3)
  • web technology (4)
  • webRTC (12)
  • windows (1)
Home | Contact us
Copyright © 2025 engineeringsemester