Skip to content

Commit ddfa091

Browse files
committed
app-launched-message
1 parent 66dfc19 commit ddfa091

File tree

6 files changed

+49
-29
lines changed

6 files changed

+49
-29
lines changed

index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ export * from 'global-input-message';
44
export function useGlobalInputApp(config: ConfigData | (() => ConfigData), canConnect?: boolean, configId?: any): GlobalInputData;
55
export function getGlobalInputState(): GlobalInputState;
66

7+
interface RegisteredInfo {
8+
session: string;
9+
url: string;
10+
}
711
interface GlobalInputState {
812
isLoading: boolean;
913
isReady: boolean;
@@ -13,6 +17,7 @@ interface GlobalInputState {
1317
isConnectionDenied: boolean;
1418
initData: InitData;
1519
senders: Sender[];
20+
registeredInfo?: RegisteredInfo|null;
1621
}
1722

1823
export type OnchangeFunction = (evt: FieldChanged) => void;
@@ -56,8 +61,11 @@ export type ConnectQRProps = {
5661
hspace?: number;
5762
mobile:GlobalInputData;
5863
};
64+
65+
5966
export interface GlobalInputData {
6067
connectionCode: string;
68+
registeredInfo?: RegisteredInfo;
6169
pairingCode: string;
6270
field: FormField;
6371
errorMessage: string;
@@ -76,6 +84,7 @@ export interface GlobalInputData {
7684
setOnchange: (onchange: OnchangeFunction) => void;
7785
close: () => void;
7886
restart: (config?: ConfigData) => void;
87+
setClientAppLaunched: (listener:(data:any)=>void ) => void;
7988
}
8089

8190
export function generateRandomString(length?: number): string;

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"webpack": "^5.73.0"
7070
},
7171
"dependencies": {
72-
"global-input-message": "^2.1.6",
73-
"qrcode.react": "^3.1.0"
72+
"global-input-message": "^2.1.8",
73+
"qrcode.react": "^4.1.0"
7474
}
75-
}
75+
}

src/globalinput.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export const initialState = {
3636
isConnectionDenied: false,
3737
isDisconnected: false,
3838
initData: null,
39-
connected: []
39+
connected: [],
40+
registeredInfo: null
41+
4042
};
4143

4244

@@ -170,16 +172,22 @@ const buildMessageHandlersForInitData = (initData, notify) => {
170172
};
171173
};
172174

173-
175+
let onClientAppLaunched = null;
176+
export const setClientAppLaunched = (clientAppLaunched) => {
177+
onClientAppLaunched=clientAppLaunched;
178+
}
174179
const buildMobileConfig = (initData, config, notify) => {
175180
const options = config.options;
176181
return {
177182
initData,
178-
onRegistered: (connectionCode) => {
183+
onClientAppLaunched: (data) => {
184+
onClientAppLaunched && onClientAppLaunched(data);
185+
},
186+
onRegistered: (connectionCode, registeredInfo) => {
179187
mobileData.mobileState = MobileState.WAITING_FOR_MOBILE;
180188
options && options.onRegistered && options.onRegistered(connectionCode);
181189
config && config.initSocket && config.initSocket(mobileData.session.socket);
182-
notify({ type: ACTION_TYPES.REGISTERED, connectionCode });
190+
notify({ type: ACTION_TYPES.REGISTERED, connectionCode, registeredInfo });
183191
},
184192
onRegisterFailed: errorMessage => {
185193
mobileData.mobileState = MobileState.ERROR;
@@ -285,7 +293,7 @@ export const reducer = (state, action) => {
285293
state = { ...state, errorMessage: '', field: null, isConnectionDenied: false };
286294
break;
287295
case ACTION_TYPES.REGISTERED:
288-
state = { ...state, errorMessage: '', field: null, connectionCode: action.connectionCode, pairingCode: getParingCode(), isConnectionDenied: false };
296+
state = { ...state, errorMessage: '', field: null, connectionCode: action.connectionCode, pairingCode: getParingCode(), isConnectionDenied: false, registeredInfo: action.registeredInfo };
289297
break;
290298
case ACTION_TYPES.RECEIVED_FIELD:
291299
state = { ...state, field: action.field, isConnectionDenied: false };

src/useGlobalInputApp.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const useGlobalInputApp = (config, canConnect = true, configId = "") => {
1515
isConnectionDenied,
1616
initData,
1717
senders,
18-
sender
18+
sender,
19+
registeredInfo
1920
}, dispatch] = useReducer(globalInput.reducer, globalInput.initialState);
2021

2122
const attached = useRef(true);
@@ -127,5 +128,7 @@ export const useGlobalInputApp = (config, canConnect = true, configId = "") => {
127128
setOnchange,
128129
close,
129130
restart,
131+
registeredInfo,
132+
setClientAppLaunched: globalInput.setClientAppLaunched,
130133
};
131134
};

src/widgets.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import QRCode from "qrcode.react";
2+
import {QRCodeSVG} from "qrcode.react";
33

44
const styles = {
55
label: {
@@ -63,7 +63,7 @@ export const ConnectQR = ({ mobile, level = 'H', size = null, label = qrCodeLabe
6363
}
6464
return (
6565
<div style={styles.qrCode}>
66-
<QRCode value={mobile.connectionCode} level={level} size={size ? size : optimumSize} />
66+
<QRCodeSVG value={mobile.connectionCode} level={level} size={size ? size : optimumSize} />
6767
{label}
6868
</div>
6969
);
@@ -105,7 +105,7 @@ export const PairingQR = ({ mobile, level = 'H', size = null, label = qrCodeLabe
105105
}
106106
return (
107107
<div style={styles.qrCode}>
108-
<QRCode value={mobile.pairingCode} level={level} size={size ? size : optimumSize} />
108+
<QRCodeSVG value={mobile.pairingCode} level={level} size={size ? size : optimumSize} />
109109
{label}
110110
</div>
111111
);

0 commit comments

Comments
 (0)