Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
fix: unexpectedly invoke initSessionAndConnect twice when use it in u…
Browse files Browse the repository at this point in the history
…seEffect (#10)
  • Loading branch information
pjchender committed Feb 7, 2020
1 parent 763db72 commit d300f89
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ See our demo site: [react-use-opentok](https://pjchender.github.io/react-use-ope
Install it with npm:

```
npm i react-use-opentok --save
npm i @opentok/client@2.x react-use-opentok
```

Or with yarn:

```
yarn add react-use-opentok
yarn add @opentok/client@2.x react-use-opentok
```

> NOTE: remember to install the peer dependency of [@opentok/client](https://www.npmjs.com/package/@opentok/client)
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ const useOpenTok = () => {
);

const connectSession = useCallback(
(token, sessionToConnect = session) =>
(token, sessionToConnect) =>
new Promise((resolve, reject) => {
if (!token) {
reject('[react-use-opentok] token does not exist.');
return reject('[react-use-opentok] token does not exist.');
}

if (!sessionToConnect) {
reject('[react-use-opentok] session does not exist.');
return reject('[react-use-opentok] session does not exist.');
}

sessionToConnect.connect(token, error => {
Expand All @@ -92,7 +92,7 @@ const useOpenTok = () => {
}
});
}),
[action, session]
[action]
);

const initSessionAndConnect = useCallback(
Expand Down
6 changes: 3 additions & 3 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('session initialization and connection', () => {
expect(error).toMatch(/token/);
}

await act(() => opentokMethods.connectSession(MOCK_CREDENTIALS.token));
await act(() => opentokMethods.connectSession(MOCK_CREDENTIALS.token, opentokProps.session));
[opentokProps, opentokMethods] = result.current;
expect(opentokProps.isSessionConnected).toBeTruthy();
expect(opentokProps.connectionId).toEqual(expect.any(String));
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('session methods after initialization', () => {
connectionId: undefined,
});

await act(() => opentokMethods.connectSession(MOCK_CREDENTIALS.token));
await act(() => opentokMethods.connectSession(MOCK_CREDENTIALS.token, opentokProps.session));
[opentokProps, opentokMethods] = result.current;
expect(opentokProps).toMatchObject({
isSessionConnected: true,
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('session methods after initialization', () => {
await act(() => opentokMethods.initSession(MOCK_CREDENTIALS));
[opentokProps, opentokMethods] = result.current;

await act(() => opentokMethods.connectSession(MOCK_CREDENTIALS.token));
await act(() => opentokMethods.connectSession(MOCK_CREDENTIALS.token, opentokProps.session));
[opentokProps, opentokMethods] = result.current;

// register signal event
Expand Down

0 comments on commit d300f89

Please sign in to comment.