| 
									
										
										
										
											2019-04-22 19:50:52 -06:00
										 |  |  | // First and foremost:
 | 
					
						
							|  |  |  | // I'm not a fan of `socket.io` because it's huge and complex.
 | 
					
						
							|  |  |  | // I much prefer `ws` because it's very simple and easy.
 | 
					
						
							|  |  |  | // That said, it's popular.......
 | 
					
						
							| 
									
										
										
										
											2019-06-03 03:47:07 -06:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2019-04-22 19:50:52 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | //var greenlock = require('greenlock-express');
 | 
					
						
							| 
									
										
										
										
											2019-06-03 03:47:07 -06:00
										 |  |  | var greenlock = require("../"); | 
					
						
							|  |  |  | var options = require("./greenlock-options.js"); | 
					
						
							|  |  |  | var socketio = require("socket.io"); | 
					
						
							| 
									
										
										
										
											2019-04-22 19:50:52 -06:00
										 |  |  | var server; | 
					
						
							|  |  |  | var io; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Any node http app will do - whether express, raw http or whatever
 | 
					
						
							| 
									
										
										
										
											2019-06-03 03:47:07 -06:00
										 |  |  | options.app = require("express")().use("/", function(req, res) { | 
					
						
							|  |  |  | 	res.setHeader("Content-Type", "text/html; charset=utf-8"); | 
					
						
							|  |  |  | 	res.end("Hello, World!\n\n💚 🔒.js"); | 
					
						
							| 
									
										
										
										
											2019-04-22 19:50:52 -06:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // The server that's handed back from `listen` is a raw https server
 | 
					
						
							|  |  |  | server = greenlock.create(options).listen(80, 443); | 
					
						
							|  |  |  | io = socketio(server); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Then you do your socket.io stuff
 | 
					
						
							| 
									
										
										
										
											2019-06-03 03:47:07 -06:00
										 |  |  | io.on("connection", function(socket) { | 
					
						
							|  |  |  | 	console.log("a user connected"); | 
					
						
							|  |  |  | 	socket.emit("Welcome"); | 
					
						
							| 
									
										
										
										
											2019-04-22 19:50:52 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-03 03:47:07 -06:00
										 |  |  | 	socket.on("chat message", function(msg) { | 
					
						
							|  |  |  | 		socket.broadcast.emit("chat message", msg); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2019-04-22 19:50:52 -06:00
										 |  |  | }); |