-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(stream): add browser support #93
feat(stream): add browser support #93
Conversation
Okay, that did end up being a quirk of my setup (Create-React-App not properly handling cjs-type imports). I've addressed it but am now failing on
Looks like Node.js's |
0ee2543
to
1e791ff
Compare
Assuming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job so far.
You can use an intersection type for Timeout
, something like Timeout | number
. When it comes to unref
it is there to not keep the process alive if that is the only thing left. I would add something like this.timeout.unref && this.timeout.unref()
to mitigate this.
I have actually swapped setImmediate
for process.nextTick
as that has the better behavior. You might want to add a utility function to utils called nextTick
and use this snippet:
function nextTick(callback: Function, ...args: any[]): void {
if (process && process.nextTick)
process.nextTick(callback, ...args);
else if (setImmediate)
setImmediate(callback, ...args);
else
setTimeout(callback, 0, ...args);
}
setImmediate
should work for some browsers, I think Firefox is one that it might not work with.
Ignore that |
Thanks!
Less support than you might expect 😞. This is one of the rare times I've seen IE be the early adopter.
I got a TypeScript error with the proposed so had to tweak it a bit:
Seeing a new issue now, looks like a race condition (maybe as a result of
at ps2census/src/client/utils/queue.ts Line 11 in 465b4e6
|
Websocket in browsers do not support the callback that is used in
send(data: CensusCommand): void {
if (!this.connection)
throw new Error(`Connection not available`);
this.connection.send(JSON.stringify(data), err => {
if (err) this.emit('error', err);
});
}
private sendCommand<T>(
queue: Queue<CommandCallback<T>>,
command: CensusCommand,
): Promise<T> {
if (!this.stream.isReady)
return Promise.reject(new StreamResponseException('Stream is closed'));
return new Promise<T>((resolve, reject) => {
this.stream.send(command);
queue.enqueue({
resolve,
reject,
});
});
} |
Thanks again. With the latest push -- this library is now working for me in both the browser and node without errors! 🎉 This includes calling |
Co-authored-by: Sjors <[email protected]>
Probably want to squash (up to you) but I think this is ready! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. There are some small things I need to do, which will probably be later today. Once that is done I will create a new release.
Resolves #55
isomorphic-ws
[x] Fix issue with AxiosTimeout
being Node-onlysetImmediate
being Node-onlyWas hoping to use this in the browser after really appreciating it in Node.js. I've added the latest version of
isomorphic-ws
as suggested in #55.This doesn't seem to quite work yet (or might be a quirk of my setup),
as I now get an error around howAxios
is being included/used in theCensusClient
'sRestClient
's constructor. It seems like the default import ends up being a string of the path to thecjs
import, rather than an import matching theAxiosStatic
interface.Error