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

Commit

Permalink
Merge c2fc995 into b16c7d1
Browse files Browse the repository at this point in the history
  • Loading branch information
pjchender committed Feb 14, 2020
2 parents b16c7d1 + c2fc995 commit 3bb5d09
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const Component = () => {

const {
// connection info
isSessionInitialized,
connectionId,
isSessionConnected,

Expand Down Expand Up @@ -101,6 +102,7 @@ const [opentokProps, opentokMethods] = useOpenTok();

const {
// connection info
isSessionInitialized,
connectionId,
isSessionConnected,

Expand Down Expand Up @@ -138,6 +140,9 @@ initSessionAndConnect({
token,
});
```
This methods will first initialize the session object, and continue connected to the session.

After session initialized, the value of `isSessionInitialized` will be `true.

After connect to session, you can get the `session`, `connectionId` , `isSessionConnected`, and `connections` properties from `opentokProps`:

Expand All @@ -160,6 +165,8 @@ const { disconnectSession } = opentokMethods;
disconnectSession();
```

> If you want to control the process of session initialization and connect to session on your own, check the method `initSession({ apiKey, sessionId, sessionOptions })` and `connectSession({token, sessionToConnect })`.
### Publish and unpublished stream to the session

You can publish stream from camera or screen to session through the `publish` method.
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const useOpenTok = () => {
({ apiKey, sessionId, sessionOptions }) =>
new Promise(resolve => {
const session = OT.initSession(apiKey, sessionId, sessionOptions);
action.update({ session });
action.update({ session, isSessionInitialized: true });
resolve(session);
}),
[action]
Expand Down
2 changes: 2 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ describe('session initialization and connection', () => {
let [opentokProps, opentokMethods] = result.current;

expect(opentokProps.session).toBeUndefined();
expect(opentokProps.isSessionInitialized).toBeFalsy();
await act(() => opentokMethods.initSession(MOCK_CREDENTIALS));

[opentokProps, opentokMethods] = result.current;
expect(opentokProps.session).toBeDefined();
expect(opentokProps.isSessionInitialized).toBeTruthy();
});

it('connectSession', async () => {
Expand Down
1 change: 1 addition & 0 deletions src/libs/use-opentok-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useReducer, useMemo } from 'react';

const initialState = {
// connection info
isSessionInitialized: false,
connectionId: undefined,
isSessionConnected: false,

Expand Down

0 comments on commit 3bb5d09

Please sign in to comment.