-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove "dom" from bf-streaming tsconfig and refactor code (#1575)
* remove "dom" from bf-streaming tsconfig and refactor code * remove isBrowser, look for global members instead
- Loading branch information
Showing
10 changed files
with
137 additions
and
8 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
libraries/botframework-streaming/src/interfaces/IBrowserFileReader.ts
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,19 @@ | ||
/** | ||
* @module botframework-streaming | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
/** | ||
* Partially represents a FileReader from the W3C FileAPI Working Draft. | ||
* For more information, see https://w3c.github.io/FileAPI/#APIASynch. | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
*/ | ||
export interface IBrowserFileReader { | ||
result: any; | ||
onload: (event: any) => void; | ||
readAsArrayBuffer: (blobOrFile: any) => void; | ||
} |
24 changes: 24 additions & 0 deletions
24
libraries/botframework-streaming/src/interfaces/IBrowserWebSocket.ts
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,24 @@ | ||
/** | ||
* @module botframework-streaming | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
/** | ||
* Partially represents a WebSocket from the HTML Living Standard. | ||
* For more information, see https://html.spec.whatwg.org/multipage/web-sockets.html. | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
*/ | ||
export interface IBrowserWebSocket { | ||
onclose: (event: any) => void; | ||
onerror: (event: any) => void; | ||
onmessage: (event: any) => void; | ||
onopen: (event: any) => void; | ||
readyState: number; | ||
|
||
close(): void; | ||
send(buffer: any): void; | ||
} |
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
9 changes: 9 additions & 0 deletions
9
libraries/botframework-streaming/src/utilities/doesGlobalFileReaderExist.ts
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,9 @@ | ||
/** | ||
* @module botframework-streaming | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
export const doesGlobalFileReaderExist = new Function('try {return typeof FileReader !== "undefined" && FileReader !== null;}catch(e){ return false;}'); |
9 changes: 9 additions & 0 deletions
9
libraries/botframework-streaming/src/utilities/doesGlobalWebSocketExist.ts
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,9 @@ | ||
/** | ||
* @module botframework-streaming | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
export const doesGlobalWebSocketExist = new Function('try {return typeof WebSocket !== "undefined" && WebSocket !== null;}catch(e){ return false;}'); |
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
45 changes: 45 additions & 0 deletions
45
libraries/botframework-streaming/tests/InternalUtilities.test.js
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,45 @@ | ||
const { doesGlobalFileReaderExist, doesGlobalWebSocketExist } = require('../lib/utilities'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
describe('Internal Utilities', () => { | ||
it('doesGlobalWebSocketExist() should return true if global.WebSocket is truthy', () => { | ||
global.WebSocket = {}; | ||
try { | ||
expect(doesGlobalWebSocketExist()).to.be.true; | ||
} finally { | ||
global.WebSocket = undefined; | ||
} | ||
}); | ||
|
||
it('doesGlobalWebSocketExist() should return false if global.WebSocket is null or undefined', () => { | ||
expect(doesGlobalWebSocketExist()).to.be.false; | ||
|
||
global.WebSocket = null; | ||
try { | ||
expect(doesGlobalWebSocketExist()).to.be.false; | ||
} finally { | ||
global.WebSocket = undefined; | ||
} | ||
}); | ||
|
||
it('doesGlobalFileReaderExist() should return true if global.FileReader is truthy', () => { | ||
global.FileReader = {}; | ||
try { | ||
expect(doesGlobalFileReaderExist()).to.be.true; | ||
} finally { | ||
global.FileReader = undefined; | ||
} | ||
}); | ||
|
||
it('doesGlobalFileReaderExist() should return false if global.FileReader is null or undefined', () => { | ||
expect(doesGlobalFileReaderExist()).to.be.false; | ||
|
||
global.FileReader = null; | ||
try { | ||
expect(doesGlobalFileReaderExist()).to.be.false; | ||
} finally { | ||
global.FileReader = undefined; | ||
} | ||
}); | ||
}); |
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