Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Expose IP address and disconnect event#1674

Open
DRSDavidSoft wants to merge 1 commit intoBrowserSync:master from
DRSDavidSoft:patch-1
Open

Expose IP address and disconnect event #1674
DRSDavidSoft wants to merge 1 commit intoBrowserSync:master from
DRSDavidSoft:patch-1

Conversation

@DRSDavidSoft
Copy link

@DRSDavidSoft DRSDavidSoft commented Mar 21, 2019
edited
Loading

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

Summary

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(data.ua);
	
	console.log(chalk`{green Connected:}`,
		`${uaString.name} version ${uaString.version}, IP: ${data.ip}`);
	// Additionally make a toast notification, if ( data.ip is external )
	nodeNotifier.notify({
		title: 'Browser connected',
		message: `${uaString.name} version ${uaString.version}, IP: ${data.ip}`,
		sound: false
	});
});
emitter.on("client:disconnected", function ( data ) {
	let uaString = bsUtils.getUaString(data.ua);
	
	console.log(chalk`{red Disconnected:}`,
		`${uaString.name} 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.

Scope

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

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

Status

  • this PR does not seem to break any functionality.

Feedback

Would be glad to hear from you!

Copy link

Any progress on this?

Copy link
Author

@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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /