{"size": 1220, "ext": "js", "max_stars_repo_path": "test/unix.test.js", "max_stars_repo_name": "StreetStrider/booth", "max_stars_repo_stars_event_min_datetime": "2018-10-09T19:38:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-13T09:11:42.000Z", "max_issues_repo_path": "test/unix.test.js", "max_issues_repo_name": "StreetStrider/booth", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/unix.test.js", "max_forks_repo_name": "StreetStrider/booth", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 14.3529411765, "max_line_length": 54, "alphanum_fraction": 0.5885245902}

console.info('unix.test')

import console from 'console-ultimate'

import { Server } from 'http'

import { Booth } from '..'
import { Endpoint } from '..'
import { Addr } from '..'


var addr = Addr.Unix('/tmp/booth')

console.log('UNIX', ...addr.view())


var server = new Server().listen(addr.for_booth())


/*
 * Booth({ server: http server })
 * .on(event, handler)
 * .on({ event: handler })
 */
var
booth = Booth({ server })
booth.on(
{
	hello (data, endp)
	{
		console.log(2, data)

		data = data.toUpperCase() + '_' + data.toLowerCase()

		endp.send('hello', data)
		console.log(3, data)
	},
	'@error' (e)
	{
		console.error('UNIX/Booth', e.message)
		console.error(e.error)
		process.exit(1)
	},
})


/*
 * Endpoint(ws_path: string)
 * .on(event, handler)
 * .on({ event: handler })
 */
var
endp = Endpoint(addr.for_endpoint())
endp.on(
{
	'@open' (_, endp)
	{
		endp.send('hello', 'Hello, World!')
		console.log(1)
	},
	hello (data, endp)
	{
		console.log(4, data)

		endp.close()
	},
	'@close' (/* _, endp */)
	{
		console.log('END 4\n')

		setTimeout(() =>
		{
			server.close()
		}
		, 1e3)
	},
	'@error' (e)
	{
		console.error('UNIX/Endpoint', e.message)
		console.error(e.error)
		process.exit(1)
	},
})
