endpointjs
Version:
Endpoint.js enables modules within a web application to discover and use each other, whether that be on the same web page, other browser windows and tabs, iframes, servers and web workers in a reactive way by providing robust discovery, execution and stre
53 lines (39 loc) • 2.49 kB
HTML
<html>
<head>
<title>Endpoint.js Server Chat</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
</head>
<body>
<script type="text/javascript">
window.endpointLogLevel = 'trace';
// Modify the shared worker to use our custom one
window.endpointConfig = {
sharedWorkerUrl: '/chat-server/comm-worker.js'
};
</script>
<script src="https://cdn.socket.io/socket.io-1.3.7.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-1.11.3.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/0.7.12/HTMLImports.min.js" type="text/javascript"></script>
<script src="../build/endpoint.demo.js" type="text/javascript"></script>
<script src="chat-server.js" type="text/javascript"></script>
<link rel="import" href="chat-api/chat-api.html">
<p style="padding: 10px;">
<b>Open another window to the same URL to create the chat window.</b> <br><br>
This example will use the Node.js server's ability to relay messages to discover other browser windows
attached to the same server. It will then create a chat window to talk to them.<br><br>
Additionally, it will ensure that only one connection is created to the server, by using 'chat-server.js'
and 'comm-worker.js' to execute a leader election strategy, which will delegate a socket.io connection
responsibility to one of the open windows.<br><br>
Try try this, open many windows all pointing to this page, and noticed that there is only one Socket.io
connection. Likewise, you can change the port to '8283' and that will create a new socket.io connection,
and any windows opened to that URL will all use the same socket.io connection.<br><br>
All windows will use the shared worker to communicate with each other, and the socket.io connection to
communicate with windows accessing the server from the other port.<br><br>
</p>
<!-- Chat windows go here -->
<p id='chat'>
</p>
</body>
</html>