Skip to content

Commit

Permalink
chore: use configs param for chrome channel config
Browse files Browse the repository at this point in the history
  • Loading branch information
tanlethanh committed Jul 27, 2024
1 parent bad8c4e commit cbf13dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/chrome/channel.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { AsyncChannel } from '../core/channel';
import type { RawRequest } from '../core/types';

type ChromeChannelConfigs = {
/**
* use autoReconnect will listen to disconnect event and pageshow from bfcache to reconnect to the kernel
*/
autoReconnect?: boolean;
};

export class ChromeChannel extends AsyncChannel {
connection: chrome.runtime.Port;

constructor(
channelId: string,
/**
* use autoReconnect will listen to disconnect event and pageshow from bfcache to reconnect to the kernel
*/
autoReconnect?: boolean,
) {
constructor(channelId: string, configs?: ChromeChannelConfigs) {
super();
this.connection = this.connect(channelId, autoReconnect);
this.connection = this.connect(channelId, configs?.autoReconnect);

if (autoReconnect) {
if (configs?.autoReconnect) {
window?.addEventListener('pageshow', (event) => {
if (event.persisted) {
console.warn('Page restored from bfcache, reconnect');
this.connection = this.connect(channelId, autoReconnect);
this.connection = this.connect(channelId, configs.autoReconnect);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metacraft/crab",
"version": "0.0.6",
"version": "0.1.0",
"description": "A universal messaging library for cross-platform applications",
"author": "https://metacraft.studio",
"license": "MIT",
Expand Down

0 comments on commit cbf13dc

Please sign in to comment.