Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/js-counter/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 7000,
port: 7001,
open: true,
},
plugins: [new CopyWebpackPlugin([path.join(__dirname, './src/index.html')])],
Expand Down
2 changes: 1 addition & 1 deletion examples/reactant-share-hybrid/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 7000,
port: 7001,
open: true,
},
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion examples/reactant-share-serviceworker/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
mode: 'development',
devServer: {
compress: true,
port: 7000,
port: 7001,
open: true,
https: true,
},
Expand Down
2 changes: 1 addition & 1 deletion examples/reactant-share-sharedtab/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 7000,
port: 7001,
open: true,
},
plugins: [new CopyWebpackPlugin([path.join(__dirname, './src/index.html')])],
Expand Down
2 changes: 1 addition & 1 deletion examples/reactant-share-sharedworker/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
mode: 'development',
devServer: {
compress: true,
port: 7000,
port: 7001,
open: true,
},
output: {
Expand Down
2 changes: 1 addition & 1 deletion examples/reactant-share-webrtc/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
mode: 'development',
devServer: {
compress: true,
port: 7000,
port: 7001,
open: true,
},
output: {
Expand Down
2 changes: 1 addition & 1 deletion examples/ts-bookstore/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 7000,
port: 7001,
open: true,
},
plugins: [new CopyWebpackPlugin([path.join(__dirname, './src/index.html')])],
Expand Down
2 changes: 1 addition & 1 deletion examples/ts-counter/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 7000,
port: 7001,
open: true,
},
plugins: [new CopyWebpackPlugin([path.join(__dirname, './src/index.html')])],
Expand Down
2 changes: 2 additions & 0 deletions packages/reactant-share/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
} from './constants';
import type { RouterChangeNameOptions } from './router';

export type { Transport } from 'data-transport';

export type Port = 'server' | 'client';

export interface Transports {
Expand Down
34 changes: 34 additions & 0 deletions packages/reactant-share/src/portDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Port,
PortApp,
Transports,
Transport,
} from './interfaces';

export const PortDetectorOptions = Symbol('PortDetectorOptions');
Expand Down Expand Up @@ -116,6 +117,21 @@ export class PortDetector {
throw new Error(`'onServer' argument should be a function.`);
}
this.serverCallbacks.add(callback);

if (
this.lastHooks &&
this.lastHooks.size > 0 &&
this.isServer &&
this.transport
) {
try {
const hook = callback(this.transport);
this.lastHooks.add(hook);
} catch (e) {
console.error(e);
}
}

return () => {
this.serverCallbacks.delete(callback);
};
Expand All @@ -132,6 +148,21 @@ export class PortDetector {
throw new Error(`'onClient' argument should be a function.`);
}
this.clientCallbacks.add(callback);

if (
this.lastHooks &&
this.lastHooks.size > 0 &&
this.isClient &&
this.transport
) {
try {
const hook = callback(this.transport);
this.lastHooks.add(hook);
} catch (e) {
console.error(e);
}
}

return () => {
this.clientCallbacks.delete(callback);
};
Expand All @@ -149,10 +180,13 @@ export class PortDetector {
return this.options.transports ?? {};
}

transport?: Transport;

setPort(
currentPortApp: PortApp,
transport: Required<Transports>[keyof Transports]
) {
this.transport = transport;
if (this.lastHooks) {
for (const hook of this.lastHooks) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 7000,
port: 7001,
https: true, // TODO: use https://github.com/FiloSottile/mkcert
},
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 7000,
port: 7001,
https: true, // TODO: use https://github.com/FiloSottile/mkcert
},
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 7000,
port: 7001,
},
plugins: [
new CopyWebpackPlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 7000,
port: 7001,
},
plugins: [
new CopyWebpackPlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 7000,
port: 7001,
},
plugins: [
new CopyWebpackPlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 7000,
port: 7001,
},
plugins: [
new CopyWebpackPlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 7000,
port: 7001,
},
plugins: [
new CopyWebpackPlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 7000,
port: 7001,
},
plugins: [
new CopyWebpackPlugin({
Expand Down