1
0
Fork 0

Set up ripple link websocket connection.

This commit is contained in:
Starbeamrainbowlabs 2017-01-21 18:38:52 +00:00
parent 8a5dda1c05
commit 060f01cf75
7 changed files with 43 additions and 7 deletions

View File

@ -20,6 +20,8 @@ namespace Nibriboard.Client
}
}
public string WebsocketProtocol = "RippleLink";
public ClientSettings()
{

View File

@ -36,10 +36,11 @@ namespace Nibriboard.Client
return;
}
response.ContentType = getMimeType(request.URI);
response.Headers.Add("content-type", response.ContentType);
string expandedFilePath = getEmbeddedFileReference(request.URI);
if (!embeddedFiles.Contains(expandedFilePath)) {
expandedFilePath += "index.html";
}
if (!embeddedFiles.Contains(expandedFilePath)) {
response.ResponseCode = HttpResponseCode.NotFound;
response.ContentType = "text/plain";
@ -47,6 +48,10 @@ namespace Nibriboard.Client
logRequest(request, response);
return;
}
response.ContentType = getMimeType(expandedFilePath);
response.Headers.Add("content-type", response.ContentType);
byte[] embeddedFile = EmbeddedFiles.ReadAllBytes(expandedFilePath);
response.ContentLength = embeddedFile.Length;
response.Content.Write(embeddedFile, 0, embeddedFile.Length);

View File

@ -8,10 +8,13 @@ namespace Nibriboard.Client
{
public class NibriClientManager : IWebSocketRequestHandler
{
ClientSettings clientSettings;
List<NibriClient> clients = new List<NibriClient>();
public NibriClientManager()
public NibriClientManager(ClientSettings inClientSettings)
{
clientSettings = inClientSettings;
}
/// <summary>
@ -22,8 +25,8 @@ namespace Nibriboard.Client
/// <returns>Whether we want to accept the WebSocket connection attempt or not.</returns>
public bool WillAcceptRequest(string uri, string protocol)
{
Log.WriteLine("[Nibriboard/Websocket] Accepting {0} via {1}.", uri, protocol);
return true;
Log.WriteLine("[Nibriboard/Websocket] Accepting new {0} connection.", protocol);
return clientSettings.WebsocketProtocol == protocol;
}
/// <summary>
/// Handles WebSocket clients when they first connect, wrapping them in

View File

@ -22,6 +22,7 @@ class BoardWindow extends EventEmitter
FaviconNotification.add();
get("/Settings.json").then(JSON.parse).then((function(settings) {
console.info("[setup]", "Obtained settings from server:", settings);
this.settings = settings;
this.setup();
}).bind(this), function(errorMessage) {
@ -31,6 +32,10 @@ class BoardWindow extends EventEmitter
this.trackWindowSize();
}
setup() {
this.rippleLink = new RippleLink(this.settings.WebsocketUri, this);
}
nextFrame()
{
this.update();

View File

@ -1,6 +1,18 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
class RippleLink
{
constructor(inSocketUrl, inBoardWindow)
{
this.socketUrl = inSocketUrl;
this.boardWindow = inBoardWindow;
this.settings = this.boardWindow.settings;
this.websocket = new WebSocket( this.socketUrl, [ this.settings.WebsocketProtocol ] );
}
}
function get(u){return new Promise(function(r,t,a){a=new XMLHttpRequest();a.onload=function(b,c){b=a.status;c=a.response;if(b>199&&b<300){r(c);}else{t(c);}};a.open("GET",u,true);a.send(null);})}
// npm modules
@ -22,6 +34,7 @@ class BoardWindow extends EventEmitter
FaviconNotification.add();
get("/Settings.json").then(JSON.parse).then((function(settings) {
console.info("[setup]", "Obtained settings from server:", settings);
this.settings = settings;
this.setup();
}).bind(this), function(errorMessage) {
@ -31,6 +44,10 @@ class BoardWindow extends EventEmitter
this.trackWindowSize();
}
setup() {
this.rippleLink = new RippleLink(this.settings.WebsocketUri, this);
}
nextFrame()
{
this.update();

View File

@ -3,9 +3,13 @@
class RippleLink
{
constructor(socketUrl)
constructor(inSocketUrl, inBoardWindow)
{
this.socketUrl = inSocketUrl;
this.boardWindow = inBoardWindow;
this.settings = this.boardWindow.settings;
this.websocket = new WebSocket( this.socketUrl, [ this.settings.WebsocketProtocol ] );
}
}

View File

@ -47,7 +47,7 @@ namespace Nibriboard
// Websocket setup
httpServer.AddWebSocketRequestHandler(
clientSettings.WebsocketPath,
new NibriClientManager()
new NibriClientManager(clientSettings)
);
}