-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move websockets to be all in the bridge package
- Loading branch information
ddyer0
committed
Dec 5, 2023
1 parent
5af5945
commit 3a44cd9
Showing
12 changed files
with
133 additions
and
112 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
client/boardspace-codename1/boardspace core/bridge/NativeWebSocket.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
client/boardspace-codename1/boardspace core/bridge/WebSocket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
84
client/boardspace-codename1/boardspace core/lib/WebSocket.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
client/boardspace-java/boardspace-core/bridge/NativeWebSocket.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 12 additions & 4 deletions
16
...e-java/boardspace-core/lib/WebSocket.java → ...ava/boardspace-core/bridge/WebSocket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|