This is a project to help you setup a dedicated websocket server for use on a raspberry pi that can support dynamic content on multiple devices such as phones,tablets,computers, and brightsign players using express-ws
Let's say you have 7 different devices and want to sync video playbacks, create a game, or even just sync a message on the screen; this is a dirt simple solution. This implementation can be used as a self-contained video playback system w/ support for Brightsign, iOS, Android, and OSX/Win as long as the devices have local network access. This does not require an internet connection, just a private network
This example sends a 'Play Video' message to all devices connected to the socket server. Any devices connected to the server will get the automatic play from the server every 5-seconds ( configurable ). Alternatively, any client can initiate the play command for all devices.
This is a very tiny example that can be easily expanded for use as a remote control, game,digital media signage, or any other use-case where you need to share commands among multiple devices in a clossed network.
I have purposely kept all code as simple as possible, so it can be adapted for your needs
Brightsign, iPhone, Android Phone, iPad, Windows, Mac
( with npm and git installed )
git clone https://github.com/willstall/VideoWebsocketServer.git
npm install
npm start
Navigate to localhost:3000 in browser to test server. You video will play within 5 seconds.
There is basic routing that can be found in server.js which will take any base level url and display an associate video. For instace: localhost:3000/01
will play the video \videos\01.mp4
. For brightsign players, you must configure the var initialVideo = "/video/03.mp4";
variable in your index file for each device.
// fullscreen video on successful player connection, turn off to see debug log
var autoFullscreen = true;
// tell all connected players to restart video on successful player connection
var restartVideosOnConnect = true;
// initial video to play if no overriding url is provided
var initialVideo = '/video/01.mp4';
// interval in milliseconds to try and resestablish a connection to the socket server
var autoReconnectInterval = 3000;
// local ip to socket server if not on localhost
var server_ip = "10.0.1.1:3000"
// line size of visual debug log
var maxLog = 20;
- Download Rasbian Lite
- Format sd-card as Fat-32
- Install Rasbian Lite on sd card using balenaEtcher
- Plug in the pi, except power
- Put in sd card
- Power up pi
- Login with username:pi password:raspberry
- Setup Autologin, Wifi, Keyboard using raspi-config
sudo raspi-config
- Update apt-get
sudo apt-get update
sudo apt-get upgrade
- Install Git
sudo apt-get install git
- Install NPM
sudo apt-get install npm
- Pull Repository
git clone https://github.com/willstall/VideoWebsocketServer.git
- Install npm dependencies in repository directory
npm install
- Test server with npm start
npm start
- Create a .bash_profile at ~ to call npm start after login
sudo nano ~/.bash_profile
Add the following in the file and save
cd VideoWebsocketServer
npm start
- Set a permanant ip for this device, that matches the server address in index.html
sudo nano /etc/dhcpcd.conf
Add this to the end of the file
interface wlan0
static ip_address=10.0.1.1/24
nohook wpa_supplicant
Save file and restart dhcp
sudo service dhcpcd restart
You can check your new ip address with ifconfig
If your ip is not 10.0.1.1, call reboot
Conneced to the same network as the server.
- Navigate to 10.0.1.1:3000 in a web-browser
- Alternately, you can place the contents on
/public/
on your device and access index.html
Edit the autrun.brs file in a text editor. You will need to change the line r=CreateObject("roRectangle",0,0,1920,1200)
so that 1920,1200 match the desired resolution for your brightsign player.
Here are two guides for setting up a raspberry pi with raspbian as a hotspot. I used a combination of these two tutorials to get everything running.
We will need hostapd to setup a hotspot and dnsmasq in order to give out proper ip's to clients.
sudo apt-get install dnsmasq hostapd