-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Logging back from Sleeper app (#35)
- Convert console.log statements to return messages from sleeper app - Fix Windows Docker issue with recompiling
- Loading branch information
1 parent
f565d55
commit c5a1779
Showing
10 changed files
with
192 additions
and
120 deletions.
There are no files selected for viewing
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,6 +1,7 @@ | ||
import * as Sleeper from './src/components'; | ||
import DevServer from './src/dev_server'; | ||
import * as Types from './src/types'; | ||
import {Fonts, Theme} from './src/styles'; | ||
import { Fonts, Theme } from './src/styles'; | ||
import MiniLogger from './src/components/MiniLogger'; | ||
|
||
export {Sleeper, DevServer, Types, Fonts, Theme}; | ||
export { Sleeper, DevServer, Types, Fonts, Theme, MiniLogger }; |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
class PacketParser { | ||
constructor(props) { | ||
this.logsEnabled = props.logsEnabled || false; | ||
this.messageLength = 0; | ||
this.messageType = ''; | ||
this.messageLength = 0; | ||
this.partialMessage = ''; | ||
this.onMessageRecieved = props.onMessageRecieved; | ||
} | ||
|
||
parseMessage(msgString) { | ||
while (msgString.length > 0) { | ||
if (this.messageLength === 0) { | ||
const delimit = msgString.indexOf('\n'); | ||
if (delimit === -1) { | ||
console.log("[Sleeper] Message header not found, throwing out message."); | ||
return; | ||
} | ||
|
||
const header = msgString.substring(0, delimit); | ||
try { | ||
const headerObject = JSON.parse(header); | ||
this.messageType = headerObject.type; | ||
this.messageLength = headerObject.size; | ||
} catch (e) { | ||
console.log("[Sleeper] Message header malformed, throwing out message."); | ||
this.messageLength = 0; | ||
this.messageType = ''; | ||
return; | ||
} | ||
|
||
msgString = msgString.substring(delimit + 1); | ||
} | ||
|
||
const partialLength = this.messageLength - this.partialMessage.length; | ||
if (partialLength < 0) { | ||
// We need to wait for more data | ||
this.partialMessage += msgString; | ||
return; | ||
} | ||
|
||
const remainingLength = msgString.length - partialLength; | ||
if (remainingLength === 0) { | ||
// We have the full message | ||
this.partialMessage += msgString; | ||
msgString = ''; | ||
if (this.logsEnabled) console.log("[Sleeper] Message built.", this.partialMessage.length); | ||
|
||
} else { | ||
// We have more than the full message | ||
this.partialMessage += msgString.substring(0, partialLength); | ||
msgString = msgString.substring(partialLength); | ||
|
||
if (remainingLength <= 0) { | ||
// We have less than the full message | ||
if (this.logsEnabled) console.log("[Sleeper] Building message: ", this.partialMessage.length, this.messageLength, remainingLength); | ||
return; | ||
} | ||
} | ||
|
||
try { | ||
const json = JSON.parse(this.partialMessage); | ||
this.partialMessage = ''; | ||
this.messageLength = 0; | ||
|
||
this.onMessageRecieved({ | ||
type: this.messageType, | ||
data: json, | ||
}); | ||
} catch (e) { | ||
console.log("[Sleeper] Failed to parse message: ", e); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
}; | ||
|
||
module.exports = PacketParser; |
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,18 @@ | ||
import Rx from 'rx'; | ||
|
||
class MiniLogger { | ||
public static messages = new Rx.Subject; | ||
|
||
static log(...args: any[]) { | ||
this.messages.onNext({ | ||
type: 'mini_dev_server', | ||
action: 'onConsoleLog', | ||
message: Array.from(args).join(' '), | ||
}); | ||
} | ||
} | ||
|
||
// Add global function for mini logging | ||
global.log_mini = (...args: any[]) => { MiniLogger.log(...args); } | ||
|
||
export default MiniLogger; |
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
Oops, something went wrong.