Skip to content

Commit

Permalink
move websockets to be all in the bridge package
Browse files Browse the repository at this point in the history
  • Loading branch information
ddyer0 committed Dec 5, 2023
1 parent 5af5945 commit 3a44cd9
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 112 deletions.

This file was deleted.

39 changes: 39 additions & 0 deletions client/boardspace-codename1/boardspace core/bridge/WebSocket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package bridge;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import lib.G;
import lib.SocketProxy;

/**
* this is a dummy class that shouldn't be instantiated by the codename1 branch.
* It exists only to make the main code appear to be uniform
*/
public class WebSocket implements SocketProxy
{

public WebSocket(String host,int port)
{ throw G.Error("shouldn't be called");
}

public InputStream getInputStream()
{ throw G.Error("shouldn't be called");
}
public OutputStream getOutputStream()
{
throw G.Error("shouldn't be called");
}

public InetAddress getLocalAddress() {
return null;
}
public InetAddress getInetAddress() {
return null;
}
public boolean isConnected() { return false; }

public void close() throws IOException { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bridge.ClientSocket;
import bridge.Config;
import bridge.Utf8OutputStream;
import bridge.WebSocket;
/**
* this contains network code common to the legacy strings network,
* and the mixed string/binary packet used by the vnc network
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

package lib;
public interface Timestamp { String build = "3-December-2023 12:12"; }
public interface Timestamp { String build = "4-December-2023 15:12"; }

84 changes: 0 additions & 84 deletions client/boardspace-codename1/boardspace core/lib/WebSocket.java

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions client/boardspace-java/boardspace-core/bridge/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static final public String getPlatformSubtype()
{
return G.isCheerpj() ? " cheerpj" : isTable() ? " sometable" : "";
}
static private Object makeObject = new Object();
static private Object makeObject = null;
/**
* synchronized because two processes (lobby and loadthread for example) may try
* to create the first instance of a class at the same time, leading to conflicts
Expand All @@ -116,7 +116,7 @@ public static Object MakeInstance(String classname)
String expname = "";
expname = G.expandClassName(classname);
Plog.log.addLog("MakeInstance ",expname);

if(makeObject==null) { makeObject = new Object(); }
Class<?>cl = G.classForName(expname,false);
if(cl==null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package lib;
package bridge;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;

import bridge.NativeWebSocket;
import lib.G;
import lib.SocketProxy;

public class WebSocket extends NativeWebSocket implements SocketProxy
public class WebSocket implements SocketProxy
{
int socket = -1;

public native String read(int sock); // poll this to read
public native void send(int sock,String message);
public native boolean isConnected(int socket);
public native int connect(String host,int socket);

public WebSocket(String host,int port)
{ G.print("create websocket");
{ G.print("create websocket",host,port);
socket = connect(host,port);
while(!isConnected(socket)) { G.print("waiting for connection"); G.doDelay(500); }
G.print("connected websocket ",host,port);
}

private String pending = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bridge.ClientSocket;
import bridge.Config;
import bridge.Utf8OutputStream;
import bridge.WebSocket;
/**
* this contains network code common to the legacy strings network,
* and the mixed string/binary packet used by the vnc network
Expand Down
2 changes: 1 addition & 1 deletion client/boardspace-java/boardspace-core/lib/Timestamp.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

package lib;
public interface Timestamp { String build = "3-December-2023 12:12"; }
public interface Timestamp { String build = "4-December-2023 15:12"; }

3 changes: 3 additions & 0 deletions server/websockify/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ systemctl daemon-reload
systemctl enable websockify.service
systemctl start websockify.service

log files with any output from websockify are found in /var/log/messages


73 changes: 73 additions & 0 deletions server/websockify/cheerpj_02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@


function isTouchEnabled() {
return ( 'ontouchstart' in window ) ||
( navigator.maxTouchPoints > 0 ) ||
( navigator.msMaxTouchPoints > 0 );
};

function touchTest()
{ let mouse = matchMedia('(pointer:fine)').matches;
if( !mouse && isTouchEnabled())
{ alert("touch interfaces are not supported yet,\nplease use the boardspace.net app");
}
}

let sockets = [];
let nsockets = 0;

async function initNatives()
{
await cheerpjInit(
{ natives: {

Java_bridge_Cheerpj_getWidth(lib,_this) {
return document.body.clientWidth;
}
,Java_bridge_Cheerpj_getHeight(lib,_this) {
return document.body.clientHeight;
},
async Java_bridge_WebSocket_read(lib,_this,sock) {
let socket = sockets[sock];
const m = socket.message;
socket.message = null;
return m;
},
async Java_bridge_WebSocket_send(lib,_this,sock,message) {
let socket = sockets[sock];
socket.send(message);
},
Java_bridge_WebSocket_isConnected(lib,_this,sock)
{ let socket = sockets[sock];
return socket.connok;
},
Java_bridge_WebSocket_connect(lib,_this,host,socket)
{ let target = "wss://" + host + ":" + socket +"/gameserver";
console.log("make socket "+target );
let sock = new WebSocket(target);
let n = nsockets++;

sock.message =null;
sock.myIndex = n;
sock.connok = false;
sockets[n] = sock;

sock.addEventListener("open", (event) => {
console.log("connected");
sock.connok = true;
});

sock.addEventListener("message", (event) => {
sock.message = sock.message==null ? event.data : sock.message + event.data;
});
return n;
}
}
});
}






0 comments on commit 3a44cd9

Please sign in to comment.