This repository was archived by the owner on Nov 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Add TypeScript declaration files #117
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
37ca98e
Add TypeScript declaration files
janjakubnanista 80dd3a5
Improve types for opentok, add global OT object
janjakubnanista e28e6e8
Add ref to OTSubscriberProps and OTPublisherProps
janjakubnanista cf85ed1
Change Element to HTMLElement in opentok.d.ts types
janjakubnanista ddd0fbd
Add isConnected method to Session interface
janjakubnanista f7fe151
Rename CreateSessionResult interface to SessionHelper
janjakubnanista 16461ea
Merge branch 'dev' into feature/types
ggoldens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| example/ | ||
| src/ | ||
| test/ | ||
| types/index.test-d.ts | ||
| types/tsconfig.json | ||
| karma.conf.js | ||
| .travis.yml | ||
| .npmignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import React from 'react'; | ||
| import { Session, Error, PublisherProperties, Stream, SubscriberProperties, PublisherEventHandlers, SessionEventHandlers, SubscriberEventHandlers, Subscriber, Publisher } from './opentok'; | ||
|
|
||
| export interface OTPublisherRef { | ||
| getPublisher(): Publisher; | ||
| } | ||
|
|
||
| export interface OTPublisherProps { | ||
| session?: Session; | ||
| properties?: PublisherProperties; | ||
| ref?: React.Ref<OTPublisherRef>; | ||
| eventHandlers?: PublisherEventHandlers; | ||
| onInit?: () => void; | ||
| onPublish?: () => void; | ||
| onError?: (error: Error) => void; | ||
| } | ||
|
|
||
| export interface OTSessionProps { | ||
| apiKey: string; | ||
| sessionId: string; | ||
| token: string; | ||
| eventHandlers?: SessionEventHandlers; | ||
| onConnect?: () => void; | ||
| onError?: (error: Error) => void; | ||
| } | ||
|
|
||
| export interface OTStreamsProps { | ||
| children: React.ReactElement; | ||
| session?: Session; | ||
| streams?: Stream[]; | ||
| } | ||
|
|
||
| export interface OTSubscriberRef { | ||
| getSubscriber(): Subscriber; | ||
| } | ||
|
|
||
| export interface OTSubscriberProps { | ||
| eventHandlers?: SubscriberEventHandlers; | ||
| properties?: SubscriberProperties; | ||
| ref?: React.Ref<OTSubscriberRef>; | ||
| session?: Session; | ||
| stream?: Stream; | ||
| onSubscribe?: () => void; | ||
| onError?: (error: Error) => void; | ||
| } | ||
|
|
||
| export const OTPublisher: React.ComponentType<OTPublisherProps>; | ||
| export const OTSession: React.ComponentType<OTSessionProps>; | ||
| export const OTStreams: React.ComponentType<OTStreamsProps>; | ||
| export const OTSubscriber: React.ComponentType<OTSubscriberProps>; | ||
janjakubnanista marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export interface CreateSessionOptions { | ||
| apiKey: string; | ||
| sessionId: string; | ||
| token: string; | ||
| onStreamsUpdated?: (streams: Stream[]) => void; | ||
| } | ||
|
|
||
| export interface SessionHelper { | ||
| session: Session; | ||
| streams: Stream[]; | ||
| disconnect: () => void; | ||
| } | ||
|
|
||
| export function createSession(options: CreateSessionOptions): SessionHelper; | ||
|
|
||
| export interface PreloadScriptProps { | ||
| loadingDelegate?: React.ReactNode; | ||
| opentokClientUrl?: string; | ||
| } | ||
|
|
||
| export function preloadScript(component: React.ComponentType): React.ComponentType<PreloadScriptProps>; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| import React from 'react'; | ||
| import { expectNotAssignable, expectAssignable } from 'tsd'; | ||
| import { OTSessionProps, OTPublisherProps, OTStreamsProps, OTSubscriberProps, OTSubscriberRef, OTPublisherRef } from "."; | ||
| import { Error, Event, ArchiveEvent, SignalEvent, Session, AudioLevelUpdatedEvent, Stream, SubscriberProperties } from "./opentok"; | ||
|
|
||
| /** | ||
| * OTSessionProps | ||
| */ | ||
| expectNotAssignable<OTSessionProps>({}); | ||
| expectNotAssignable<OTSessionProps>({ | ||
| apiKey: '' | ||
| }); | ||
| expectNotAssignable<OTSessionProps>({ | ||
| apiKey: '', | ||
| sessionId: '' | ||
| }); | ||
|
|
||
| expectAssignable<OTSessionProps>({ | ||
| apiKey: '', | ||
| sessionId: '', | ||
| token: '' | ||
| }); | ||
| expectAssignable<OTSessionProps>({ | ||
| apiKey: '', | ||
| sessionId: '', | ||
| token: '', | ||
| eventHandlers: {} | ||
| }); | ||
| expectAssignable<OTSessionProps>({ | ||
| apiKey: '', | ||
| sessionId: '', | ||
| token: '', | ||
| eventHandlers: { | ||
| archiveStarted: (event: ArchiveEvent) => {} | ||
| } | ||
| }); | ||
| expectAssignable<OTSessionProps>({ | ||
| apiKey: '', | ||
| sessionId: '', | ||
| token: '', | ||
| eventHandlers: { | ||
| archiveStarted: (event: ArchiveEvent) => {}, | ||
| 'signal:foo': (event: SignalEvent) => {}, | ||
| 'archiveStarted streamCreated': (event: Event) => {} | ||
| } | ||
| }); | ||
|
|
||
| declare const session: Session; | ||
| declare const publisherRef: React.RefObject<OTPublisherRef>; | ||
|
|
||
| /** | ||
| * OTPublisherProps | ||
| */ | ||
| expectNotAssignable<OTPublisherProps>({ | ||
| session: null | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| session, | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| session, | ||
| properties: {} | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| properties: { | ||
| audioBitrate: 10000 | ||
| } | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| eventHandlers: {} | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| ref: undefined | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| ref: (instance: OTPublisherRef | null) => {} | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| ref: publisherRef | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| eventHandlers: { | ||
| accessAllowed: (event: Event) => undefined, | ||
| accessDenied: (event: Event<'accessDenied'>) => undefined, | ||
| destroyed: event => undefined, | ||
| audioLevelUpdated: (event: AudioLevelUpdatedEvent) => undefined | ||
| } | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| onInit: () => undefined | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| onPublish: () => undefined | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| onError: () => undefined | ||
| }); | ||
| expectAssignable<OTPublisherProps>({ | ||
| onError: (error: Error) => undefined | ||
| }); | ||
|
|
||
| declare const node: React.ReactNode; | ||
| declare const nodeArray: React.ReactNodeArray; | ||
| declare const element: React.ReactElement; | ||
| declare const stream: Stream; | ||
|
|
||
| /** | ||
| * OTStreamsProps | ||
| */ | ||
| expectNotAssignable<OTStreamsProps>({}); | ||
| expectNotAssignable<OTStreamsProps>({ session }); | ||
| expectNotAssignable<OTStreamsProps>({ session, streams: [] }); | ||
| expectNotAssignable<OTStreamsProps>({ | ||
| children: node | ||
| }); | ||
| expectNotAssignable<OTStreamsProps>({ | ||
| children: nodeArray | ||
| }); | ||
| expectAssignable<OTStreamsProps>({ | ||
| children: element | ||
| }); | ||
| expectAssignable<OTStreamsProps>({ | ||
| children: element, | ||
| session | ||
| }); | ||
| expectAssignable<OTStreamsProps>({ | ||
| children: element, | ||
| streams: [] | ||
| }); | ||
| expectAssignable<OTStreamsProps>({ | ||
| children: element, | ||
| streams: [stream] | ||
| }); | ||
|
|
||
| declare const subscriberProperties: SubscriberProperties; | ||
| declare const subscriberRef: React.RefObject<OTSubscriberRef>; | ||
|
|
||
| /** | ||
| * OTSubscriberProps | ||
| */ | ||
| expectAssignable<OTSubscriberProps>({}); | ||
| expectAssignable<OTSubscriberProps>({ session }); | ||
| expectAssignable<OTSubscriberProps>({ stream }); | ||
| expectAssignable<OTSubscriberProps>({ onSubscribe: () => undefined }); | ||
| expectAssignable<OTSubscriberProps>({ onError: () => undefined }); | ||
| expectAssignable<OTSubscriberProps>({ onError: error => undefined }); | ||
| expectAssignable<OTSubscriberProps>({ onError: (error: Error) => undefined }); | ||
| expectAssignable<OTSubscriberProps>({ | ||
| properties: subscriberProperties | ||
| }); | ||
| expectNotAssignable<OTSubscriberProps>({ | ||
| properties: null | ||
| }); | ||
| expectNotAssignable<OTSubscriberProps>({ | ||
| properties: { | ||
| fitMode: NaN | ||
| } | ||
| }); | ||
| expectAssignable<OTSubscriberProps>({ | ||
| eventHandlers: {} | ||
| }); | ||
| expectAssignable<OTSubscriberProps>({ | ||
| ref: undefined | ||
| }); | ||
| expectAssignable<OTSubscriberProps>({ | ||
| ref: (instance: OTSubscriberRef | null) => {} | ||
| }); | ||
| expectAssignable<OTSubscriberProps>({ | ||
| ref: subscriberRef | ||
| }); | ||
| expectAssignable<OTSubscriberProps>({ | ||
| eventHandlers: { | ||
| videoDimensionsChanged: event => undefined, | ||
| audioBlocked: (event: Event) => undefined, | ||
| audioLevelUpdated: (event: AudioLevelUpdatedEvent) => undefined, | ||
| videoElementCreated: (event: Event) => undefined | ||
| } | ||
| }); | ||
| expectNotAssignable<OTSubscriberProps>({ | ||
| eventHandlers: { | ||
| 'foo': (event: Event) => undefined | ||
| } | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.