'use strict'; import React from 'react'; import io from 'socket.io-client'; export default class NotifPage extends React.Component { constructor(props) { super(props); this.state = { haveperm: false } } componentDidMount() { let socket = io.connect(); let room = this.props.urlid; socket.on('connect', () => { socket.emit('room', room); }); socket.on('message', (data) => { new Notification(data); }); } checkperm(permission) { if (permission === 'granted') { this.setState({haveperm: true}); } } render() { let supported = ("Notification" in window); if (supported) { Notification.requestPermission(permission => { this.checkperm(permission); }.bind(this)); } return (

Notification Page

{ supported ||

Error: This browser does not support desktop notifications :(

} { !this.state.haveperm && supported &&

Please give this site permission to display notifications.

this.checkperm(Notification.permission)}> Check Again
} { this.state.haveperm && supported &&

This page is now monitoring for notifications.

}
); } }