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

Commit

Permalink
Support subscriber options (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjrink committed Mar 4, 2020
1 parent f10bbea commit e5a91dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -4,7 +4,8 @@
"description": "React Hook for @opentok/client SDK",
"contributors": [
"PJCHENder <pjchender@gmail.com> (https://pjchender.blogspot.com)",
"Andyyou <andyyu0920@gmail.com> (http://andyyou.github.io/)"
"Andyyou <andyyu0920@gmail.com> (http://andyyou.github.io/)",
"Mwjrink <mwjrink@gmail.com> (https://github.com/mwjrink)"
],
"license": "MIT",
"main": "dist/react-use-opentok.cjs.min.js",
Expand Down
17 changes: 11 additions & 6 deletions src/index.js
Expand Up @@ -110,17 +110,21 @@ const useOpenTok = () => {
}, [action, session]);

const publish = useCallback(
({ name, element, options = defaultOptions }) => {
({ name, element, options }) => {
if (publisher[name]) {
throw new Error(`The publisher(${name}) is already existed`);
}

return new Promise((resolve, reject) => {
const newPublisher = OT.initPublisher(element, options, (error) => {
if (error) {
reject(error);
const newPublisher = OT.initPublisher(
element,
{ ...defaultOptions, ...options },
(error) => {
if (error) {
reject(error);
}
}
});
);
resolve(newPublisher);
}).then((newPublisher) => {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -158,12 +162,13 @@ const useOpenTok = () => {
);

const subscribe = useCallback(
({ stream, element }) => {
({ stream, element, options }) => {
const { streamId } = stream;
const pickedStream = streams.find(s => s.streamId === streamId);

const subscriber = session.subscribe(pickedStream, element, {
...defaultOptions,
...options,
});

action.addSubscriber(subscriber);
Expand Down

0 comments on commit e5a91dd

Please sign in to comment.