Skip to content

Commit

Permalink
fixes on comments from github
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryPorotov authored and daonb committed Oct 13, 2023
1 parent d629ccc commit c3c8007
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Preferences } from '@capacitor/preferences'
const FAILED_COLOR = "red"// ashort period of time, in milli
const TOOLBAR_HEIGHT = 135

interface ServerPayload {
export interface ServerPayload {
height: number
width: number
windows: SerializedWindow[]
Expand Down Expand Up @@ -553,7 +553,7 @@ export class Gate {
/*
* dump dumps the host to a state object
* */
dump() {
dump(): ServerPayload {
const windows = []
this.windows.forEach(w => {
const win: SerializedWindow = {
Expand Down
4 changes: 2 additions & 2 deletions src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export interface SerializedLayout {

export class Layout extends Cell {
cells?: Cell[]
dir: "TBD" | string
dir: "TBD" | "topbottom" | "rightleft"
active?: boolean
/*
* Layout contructor creates a `Layout` object based on a cell.
* Layout constructor creates a `Layout` object based on a cell.
* The new object wraps the `basedOn` cell and makes it his first son
*/
constructor(dir, basedOn) {
Expand Down
8 changes: 3 additions & 5 deletions src/pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class Pane extends Cell {
retries = 0
WebLinksAddon: WebLinksAddon
resizeObserver: ResizeObserver
mc: HammerManager
zoomed = false

constructor(props) {
Expand Down Expand Up @@ -208,9 +207,9 @@ export class Pane extends Cell {
}

/*
* Catches gestures on an elment using hammerjs.
* If an element is not passed in, `this.e` is used
*/
* Catches gestures on an element using hammerjs.
* If an element is not passed in, `this.e` is used
*/
catchFingers(elem = undefined) {
const e = (typeof elem == 'undefined')?this.e:elem,
h = new Manager(e, {}),
Expand Down Expand Up @@ -253,7 +252,6 @@ export class Pane extends Cell {
else
this.scale(-1)
})
this.mc = h
}

zoom() {
Expand Down
15 changes: 8 additions & 7 deletions src/ssh_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class SSHChannel extends BaseChannel {
return SSH.closeChannel({channel: this.id})
}
send(data: string | ArrayBuffer): void {
//TODO: remove next line when fixed - https://github.com/tuzig/capacitor-ssh-plugin/issues/15
//@ts-ignore the field is actually called "message" not "s"
SSH.writeToChannel({channel: this.id, message: data})
.catch(e => console.log("error from writeToChannel", e))
Expand Down Expand Up @@ -139,7 +140,7 @@ export class SSHSession extends BaseSession {
// over SSH
export class HybridSession extends SSHSession {
candidate: string
webrtcSession: Session
webrtcSession: WebRTCSession
sentMessages: Array<string>
gotREADY: boolean
constructor(address: string, username: string, port=22) {
Expand Down Expand Up @@ -244,14 +245,14 @@ export class HybridSession extends SSHSession {
return
if ((c as {candidate?}).candidate)
try {
await (this.webrtcSession as WebRTCSession).pc.addIceCandidate(c)
await this.webrtcSession.pc.addIceCandidate(c)
} catch(e) {
this.t7.log("failed the add ice candidate", e.message, c)
return
}
else
try {
await (this.webrtcSession as WebRTCSession).pc.setRemoteDescription(c as RTCSessionDescriptionInit)
await this.webrtcSession.pc.setRemoteDescription(c as RTCSessionDescriptionInit)
} catch(e) { this.t7.log("got error setting remote desc:", e.message, c) }
})
}
Expand All @@ -272,17 +273,17 @@ export class HybridSession extends SSHSession {
else if (state == "failed")
reject()
}
(this.webrtcSession as WebRTCSession).onIceCandidate = e => {
this.webrtcSession.onIceCandidate = e => {
const candidate = JSON.stringify(e.candidate)
this.sentMessages.push(candidate)
//@ts-ignore bug in the .d.ts
SSH.writeToChannel({channel: channelId, message: candidate + "\n"})
}
(this.webrtcSession as WebRTCSession).onNegotiationNeeded = () => {
this.webrtcSession.onNegotiationNeeded = () => {
this.t7.log("on negotiation needed");
(this.webrtcSession as WebRTCSession).pc.createOffer().then(d => {
this.webrtcSession.pc.createOffer().then(d => {
const offer = JSON.stringify(d);
(this.webrtcSession as WebRTCSession).pc.setLocalDescription(d)
this.webrtcSession.pc.setLocalDescription(d)
this.sentMessages.push(offer)
//@ts-ignore a .d.ts bug
SSH.writeToChannel({channel: channelId, message: offer + "\n"})
Expand Down
33 changes: 23 additions & 10 deletions src/terminal7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ import { Cell } from "./cell"
import { Pane } from "./pane"
import { PeerbookSession } from "./webrtc_session"

declare type NavType = {
standalone?: boolean
getInstalledRelatedApps(): Promise<{
id?: string,
platform: "chrome_web_store" | "play" | "chromeos_play" | "webapp" | "windows" | "f-droid" | "amazon",
url?: string,
version?: string,
}[]>
} & Navigator

declare let window: {
navigator: NavType
} & Window

declare let navigator: NavType

export const OPEN_HTML_SYMBOL = "📡"
export const ERROR_HTML_SYMBOL = "🤕"
export const CLOSED_HTML_SYMBOL = "🙁"
Expand Down Expand Up @@ -855,13 +871,14 @@ export class Terminal7 {
console.log("session is close ignoring message", m)
return
}
const session = g.session as PeerbookSession
if (m.candidate !== undefined) {
(g.session as PeerbookSession).peerCandidate(m.candidate)
session.peerCandidate(m.candidate)
return
}
if (m.answer !== undefined ) {
const answer = JSON.parse(atob(m.answer));
(g.session as PeerbookSession).peerAnswer(answer)
const answer = JSON.parse(atob(m.answer))
session.peerAnswer(answer)
return
}
}
Expand Down Expand Up @@ -1028,13 +1045,10 @@ export class Terminal7 {
this.map.shell.printPrompt()
if (!((window.matchMedia('(display-mode: standalone)').matches)
|| (window.matchMedia('(display-mode: fullscreen)').matches)
// @ts-ignore
|| window.navigator.standalone
|| (Capacitor.getPlatform() != "web")
|| document.referrer.includes('android-app://')))
// @ts-ignore
if (navigator.getInstalledRelatedApps)
// @ts-ignore
navigator.getInstalledRelatedApps().then(relatedApps => {
if (relatedApps.length > 0)
this.map.tty("PWA installed, better use it\n")
Expand Down Expand Up @@ -1167,9 +1181,8 @@ export class Terminal7 {
}
saveDotfile(text) {
this.cells.forEach(c => {
// @ts-ignore
if (typeof(c.setTheme) == "function")
(c as unknown as Pane).setTheme(this.conf.theme)
if (c instanceof Pane)
c.setTheme(this.conf.theme)
})
terminal7.loadConf(TOML.parse(text))
if (this.pb &&
Expand All @@ -1182,7 +1195,7 @@ export class Terminal7 {
|| (this.pb.email != this.conf.peerbook.email))) {
this.pbClose()
this.pb = null
this.pbConnect().then()
this.pbConnect()
}
return Preferences.set({key: "dotfile", value: text})
}
Expand Down
7 changes: 4 additions & 3 deletions src/webrtc_session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CapacitorHttp, HttpHeaders } from '@capacitor/core';
import { BaseChannel, BaseSession, Channel, ChannelID, Failure } from './session';
import { IceServers } from "./terminal7"
import { ServerPayload } from "./gate"

type ChannelOpenedCB = (channel: Channel, id: ChannelID) => void
type RTCStats = {
Expand Down Expand Up @@ -186,7 +187,7 @@ export class WebRTCSession extends BaseSession {
}
return channel
}
openChannel(cmdorid: string | string[], parent?: ChannelID, sx?: number, sy?: number):
openChannel(cmdorid: number | string | string[], parent?: ChannelID, sx?: number, sy?: number):
Promise<Channel> {
return new Promise((resolve, reject) => {
let msgID: number
Expand Down Expand Up @@ -311,7 +312,7 @@ export class WebRTCSession extends BaseSession {
}, resolve, reject)
)
}
setPayload(payload): Promise<void>{
setPayload(payload: string | ServerPayload): Promise<void>{
return new Promise((resolve, reject) =>
this.sendCTRLMsg({
type: "set_payload",
Expand Down Expand Up @@ -465,7 +466,7 @@ export class HTTPWebRTCSession extends WebRTCSession {
onNegotiationNeeded(e) {
this.t7.log("over HTTP on negotiation needed", e)
this.pc.createOffer().then(offer => {
this.pc.setLocalDescription(offer).then()
this.pc.setLocalDescription(offer)
})
}
onIceCandidate(ev: RTCPeerConnectionIceEvent) {
Expand Down

0 comments on commit c3c8007

Please sign in to comment.