Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose IP address and disconnect event #1674

wants to merge 1 commit into
base: master


Copy link

DRSDavidSoft commented Mar 21, 2019

I'd like to be notified of when someone has connected to my session externally.


Since logConnections: true only emits a single Browser Connected: . . . line, bs has to expose the client's ip address from the socket event.

So, I am using the following code to be notified of new connections:

const nodeNotifier = require('node-notifier');
const bsUtils = require('browser-sync/dist/utils');
const emitter = browserSync.emitter;

emitter.on("client:connected", function ( data ) {
	let uaString = bsUtils.getUaString(;
	console.log(chalk`{green Connected:}`,
		`${} version ${uaString.version}, IP: ${data.ip}`);

	// Additionally make a toast notification, if ( data.ip is external )
		title: 'Browser connected',
		message: `${} version ${uaString.version}, IP: ${data.ip}`,
		sound: false


emitter.on("client:disconnected", function ( data ) {
	let uaString = bsUtils.getUaString(;
	console.log(chalk`{red Disconnected:}`,
		`${} version ${uaString.version}`, chalk`{yellow IP:}`, `${data.ip}`);

Without exposing handshake.address and client.on("disconnect", { . . . }) methods, it's impossible to acquire the client's ip address and thus be notified of such events.


This PR exposes's following properties in order to write custom event listeners:

  • handshake.address
  • client.on("disconnect", { . . . })


  • this PR does not seem to break any functionality.


Would be glad to hear from you!


This comment has been minimized.

Copy link

DannyvanderJagt commented Oct 21, 2019

Any progress on this?


This comment has been minimized.

Copy link

DRSDavidSoft commented Nov 7, 2019

@shakyShane I would appreciate it if you consider merging this! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.