libopentok.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. {
  2. This file is part of the Pas2JS run time library.
  3. Copyright (c) 2020 by Michael Van Canneyt
  4. OpenTok.js import classes.
  5. Actual Opentok API is copyright Tokbox/Nexmo/Vonage
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit libopentok;
  13. {$mode objfpc}
  14. {$modeswitch externalclass}
  15. interface
  16. uses
  17. JS, web;
  18. Type
  19. TJSMediaStreamTrack = class external name 'MediaStreamTrack' (TJSObject);
  20. { ---------------------------------------------------------------------
  21. Forward declarations
  22. ---------------------------------------------------------------------}
  23. TOT = Class;
  24. TOTArchiveEvent = Class;
  25. TOTAudioLevelUpdatedEvent = Class;
  26. TOTCapabilities = Class;
  27. TOTConnection = Class;
  28. TOTConnectionEvent = Class;
  29. TOTDevice = Class;
  30. TOTError = Class;
  31. TOTEvent = Class;
  32. TOTEventDispatcher = Class;
  33. TOTExceptionEvent = Class;
  34. TOTGetDevicesResponse = Class;
  35. TOTGetUserMediaOptions = Class;
  36. TOTInitPublisherOptions = Class;
  37. TOTInitSessionOptions = Class;
  38. TOTMediaStoppedEvent = Class;
  39. TOTPublisher = Class;
  40. TOTPublisherStats = Class;
  41. TOTPublisherStyleOptions = Class;
  42. TOTScreenSharingCapabilities = Class;
  43. TOTSession = Class;
  44. TOTSessionConnectEvent = Class;
  45. TOTSessionDisonnectEvent = Class;
  46. TOTSignalEvent = Class;
  47. TOTStream = Class;
  48. TOTStreamEvent = Class;
  49. TOTStreamPropertyChangedEvent = Class;
  50. TOTSubscriber = Class;
  51. TOTSubscriberStats = Class;
  52. TOTSubscriberStyleOptions = Class;
  53. TOTSupportedCodecsResponse = Class;
  54. TOTUIStyle = Class;
  55. TOTVideoElementCreatedEvent = Class;
  56. TOTVideoEnabledChangedEvent = Class;
  57. TOTConnectionDynArray = Array of TOTConnection;
  58. TOTStreamDynArray = Array of TOTStream;
  59. { ---------------------------------------------------------------------
  60. Events
  61. ---------------------------------------------------------------------}
  62. TOTEvent = Class external name 'ArchiveEvent' (TJSEvent)
  63. Public
  64. Function isDefaultPrevented : Boolean;
  65. end;
  66. { TOTStreamEvent }
  67. TOTBaseStreamEvent = Class external name 'StreamEvent' (TOTEvent)
  68. private
  69. FStream: TOTStream; external name 'stream';
  70. public
  71. Property Stream : TOTStream read FStream;
  72. end;
  73. { TOTStreamEvent }
  74. TOTStreamEvent = Class external name 'StreamEvent' (TOTBaseStreamEvent)
  75. private
  76. Fcancelable: Boolean; external name 'cancelable';
  77. FReason: string; external name 'reason';
  78. Public
  79. Property Cancelable : Boolean Read Fcancelable;
  80. Property Reason : string read FReason;
  81. end;
  82. { TOTStreamPropertyChangedEvent }
  83. TOTStreamPropertyChangedEvent = Class external name 'StreamPropertyChangedEvent' (TOTBaseStreamEvent)
  84. Private
  85. FChangedProperty: string; external name 'changedProperty';
  86. FNewValue: TJSObject; external name 'newValue';
  87. FOldValue: TJSObject; external name 'oldValue';
  88. Public
  89. Property ChangedProperty : string read FChangedProperty;
  90. Property NewValue : TJSObject Read FNewValue;
  91. Property OldValue : TJSObject Read FOldValue;
  92. end;
  93. { TOTSessionConnectEvent }
  94. TOTSessionConnectEvent = Class external name 'SessionConnect' (TOTEvent)
  95. private
  96. FReason: string; external name 'reason';
  97. Public
  98. Property Reason : string read FReason;
  99. end;
  100. { TOTSessionDisonnectEvent }
  101. TOTSessionDisonnectEvent = Class external name 'SessionDisconnect' (TOTEvent)
  102. private
  103. FConnections: TOTConnectionDynArray; external name 'connections';
  104. FStreams: TOTStreamDynArray; external name 'streams';
  105. Public
  106. Property Connections : TOTConnectionDynArray Read FConnections;
  107. Property Streams : TOTStreamDynArray Read FStreams;
  108. end;
  109. { TOTSignalEvent }
  110. TOTSignalEvent = Class external name 'SignalEvent' (TOTEvent)
  111. private
  112. FData: string; external name 'data';
  113. FFrom: TOTConnection; external name 'from';
  114. Ftype: string; external name 'type';
  115. Public
  116. Property Data : string read FData;
  117. Property From : TOTConnection Read FFrom;
  118. Property Type_ : string read Ftype;
  119. end;
  120. { TOTAudioLevelUpdatedEvent }
  121. TOTAudioLevelUpdatedEvent = Class external name 'AudioLevelUpdatedEvent' (TOTEvent)
  122. private
  123. faudiolevel: Double; external name 'audioLevel';
  124. Public
  125. Property AudioLevel : Double read faudiolevel;
  126. end;
  127. { TOTConnectionEvent }
  128. TOTConnectionEvent = Class external name 'ConnectionEvent' (TOTEvent)
  129. private
  130. fconnection: TOTConnection;external name 'connection';
  131. freason: string;external name 'reason';
  132. Public
  133. Property Connection : TOTConnection read fconnection;
  134. Property Reason : string read freason;
  135. end;
  136. { TOTExceptionEvent }
  137. TOTExceptionEvent = Class external name 'ExceptionEvent' (TOTEvent)
  138. private
  139. FCode: nativeint;external name 'code';
  140. FMessage: string;external name 'message';
  141. FTitle: string;external name 'title';
  142. Public
  143. Property Code : nativeint read FCode;
  144. Property Message : string read FMessage;
  145. Property Title : string read FTitle;
  146. end;
  147. { TOTMediaStoppedEvent }
  148. TOTMediaStoppedEvent = Class external name 'MediaStoppedEvent' (TOTEvent)
  149. private
  150. FMessage: string; external name 'message';
  151. FTitle: string; external name 'title';
  152. FTrack: TJSMediaStreamTrack; external name 'track';
  153. Public
  154. Property Message : string read FMessage;
  155. Property Title : string Read FTitle;
  156. Property Track : TJSMediaStreamTrack Read FTrack;
  157. end;
  158. { TOTArchiveEvent }
  159. TOTArchiveEvent = Class external name 'ArchiveEvent' (TOTEvent)
  160. private
  161. FID: string; external name 'id';
  162. FName: string; external name 'name';
  163. Public
  164. Property ID : string read FID;
  165. Property Name : string read FName;
  166. end;
  167. { TOTVideoElementCreatedEvent }
  168. TOTVideoElementCreatedEvent = Class external name 'VideoElementCreatedEvent' (TOTEvent)
  169. private
  170. Felement: TJSHTMLElement; external name 'element';
  171. Public
  172. Property Element : TJSHTMLElement Read Felement;
  173. end;
  174. { TOTVideoEnabledChangedEvent }
  175. TOTVideoEnabledChangedEvent = Class external name 'VideoEnabledChangedEvent' (TOTEvent)
  176. private
  177. FCancelable: Boolean; external name 'cancelable';
  178. FReason: string; external name 'reason';
  179. FTarget: TJSObject; external name 'target';
  180. FType: string; external name 'type';
  181. Public
  182. Property Cancelable : Boolean Read FCancelable;
  183. Property Reason : string Read FReason;
  184. Property Target : TJSObject Read FTarget;
  185. Property Type_ : string read FType;
  186. end;
  187. { ---------------------------------------------------------------------
  188. Real classes
  189. ---------------------------------------------------------------------}
  190. { TOTError }
  191. TOTError = class external name 'Error' (TJSError)
  192. Private
  193. FCode: nativeint; external name 'code';
  194. FName: string; external name 'name';
  195. Public
  196. Property Code : nativeint read FCode Write FCode;
  197. Property name : string read FName Write FName;
  198. end;
  199. TOTErrorHandler = reference to procedure(aErr : TOTError);
  200. { TOTEventDispatcher }
  201. TOTEventDispatcher = Class external name 'EventDispatcher' (TJSObject)
  202. Public
  203. Procedure off(aType : string; aHandler : TJSEventHandler); overload;
  204. Procedure off(aType : string); overload;
  205. Procedure off(aTypes : TJSObject; aContext : JSValue); overload;
  206. Procedure off(aTypes : TJSObject); overload;
  207. Function on_(aType : string; aHandler : TJSEventHandler) : TOTEventDispatcher; overload; external name 'on';
  208. Function on_(aType : string; aHandler : TJSEventHandler; aContext : JSValue): TOTEventDispatcher; overload; external name 'on';
  209. Function on_(aType : string; aHandler : TJSRawEventHandler) : TOTEventDispatcher; overload; external name 'on';
  210. Function on_(aType : string; aHandler : TJSRawEventHandler; aContext : JSValue): TOTEventDispatcher; overload; external name 'on';
  211. Function once(aType : string; aHandler : TJSRawEventHandler) : TJSObject; overload;
  212. Function once(aType : string; aHandler : TJSRawEventHandler; aContext : JSValue) : TJSObject; overload;
  213. Function once(aType : string; aHandler : TJSEventHandler) : TJSObject; overload;
  214. Function once(aType : string; aHandler : TJSEventHandler; aContext : JSValue) : TJSObject; overload;
  215. end;
  216. TOTConnection = Class external name 'Connection' (TJSObject)
  217. Private
  218. FconnectionId : string; external name 'connectionId';
  219. FcreationTime : NativeInt; external name 'creationTime';
  220. Fdata : string; external name 'data';
  221. Public
  222. Property connectionId : string Read FconnectionId Write FconnectionId;
  223. Property creationTime : NativeInt Read FcreationTime Write FcreationTime;
  224. Property data : string Read Fdata Write Fdata;
  225. end;
  226. TOTMediaResolution = Record
  227. height : nativeint;
  228. width : nativeint;
  229. end;
  230. { TOTStream }
  231. TOTStream = Class external name 'Stream' (TJSObject)
  232. private
  233. FConnection: TOTConnection; external name 'connection';
  234. FCreationTime: NativeInt; external name 'creationTime';
  235. FFrameRate: NativeInt; external name 'frameRate';
  236. FHasAudio: Boolean; external name 'hasAudio';
  237. FHasVideo: Boolean; external name 'hasVideo';
  238. FName: string; external name 'name';
  239. FStreamID: string; external name 'streamId';
  240. FvideoDimensions: TOTMediaResolution; external name 'videoDimensions';
  241. FVideoType: string; external name 'videoType';
  242. Public
  243. Property Connection : TOTConnection Read FConnection;
  244. Property CreationTime : NativeInt Read FCreationTime;
  245. Property FrameRate : NativeInt Read FFrameRate;
  246. Property HasAudio : Boolean Read FHasAudio;
  247. Property HasVideo : Boolean Read FHasVideo;
  248. Property Name : string Read FName;
  249. Property StreamId : string Read FStreamID;
  250. Property VideoDimensions : TOTMediaResolution Read FvideoDimensions;
  251. Property VideoType : string Read FVideoType;
  252. end;
  253. TOTCapabilities = Class external name 'Capabilities' (TJSObject)
  254. Private
  255. FforceDisconnect : byte; external name 'forceDisconnect';
  256. FforceUnpublish : byte; external name 'forceUnpublish';
  257. Fpublish : byte; external name 'publish';
  258. Fsubscribe : byte; external name 'subscribe';
  259. Public
  260. Property forceDisconnect : byte Read FforceDisconnect Write FforceDisconnect;
  261. Property forceUnpublish : byte Read FforceUnpublish Write FforceUnpublish;
  262. Property publish : byte Read Fpublish Write Fpublish;
  263. Property subscribe : byte Read Fsubscribe Write Fsubscribe;
  264. end;
  265. { TOTScreenSharingCapabilities }
  266. TOTScreenSharingCapabilities = Class external name 'Object' (TJSOBject)
  267. private
  268. FextensionRegistered: Boolean; external name 'extensionRegistered';
  269. FextensionInstalled: boolean; external name 'extensionInstalled';
  270. FextensionRequired: string; external name 'extensionRequired';
  271. FSupported: boolean;external name 'supported';
  272. FsupportedSources: TJSObject;external name 'supportedSources';
  273. Public
  274. Property extensionInstalled : boolean Read FextensionInstalled;
  275. Property supported : boolean read FSupported;
  276. Property supportedSources : TJSObject read FsupportedSources ; deprecated;
  277. Property extensionRequired : string read FextensionRequired;
  278. Property extensionRegistered : Boolean read FextensionRegistered;
  279. end;
  280. TOTScreenSharingCapabilityCallback = reference to Procedure (aResponse : TOTScreenSharingCapabilities);
  281. { TOTDevice }
  282. TOTDevice = class external name 'Object' (TJSOBject)
  283. private
  284. FDeviceID: string; external name 'deviceId';
  285. FKind: string; external name 'kind';
  286. FLabel: String; external name 'label';
  287. Public
  288. Property DeviceId : string read FDeviceID;
  289. Property Kind : string read FKind;
  290. Property Label_ : String read FLabel;
  291. end;
  292. TOTDeviceDynArray = Array of TOTDevice;
  293. { TOTGetDevicesResponse }
  294. TOTGetDevicesResponse = Class external name 'Object' (TJSOBject)
  295. private
  296. FDevices: TOTDeviceDynArray; external name 'devices';
  297. FError: TOTError; external name 'devices';
  298. Public
  299. Property Devices : TOTDeviceDynArray read FDevices;
  300. Property Error : TOTError read FError;
  301. end;
  302. TOTGetDevicesCallback = reference to Procedure (aResponse : TOTGetDevicesResponse);
  303. { TOTSupportedCodecsResponse }
  304. TOTSupportedCodecsResponse = class external name 'Object' (TJSObject)
  305. private
  306. FvideoDecoders: TStringDynArray; external name 'videoDecoders';
  307. FVideoEncoders: TStringDynArray; external name 'videoEncoders';
  308. public
  309. Property VideoDecoders : TStringDynArray Read FvideoDecoders;
  310. Property VideoEncoders : TStringDynArray read FVideoEncoders;
  311. end;
  312. TOTGetUserMediaOptions = class external name 'Object' (TJSObject)
  313. Private
  314. FaudioSource : JSValue; external name 'audioSource';
  315. FaudioSourceString : String; external name 'audioSource';
  316. FaudioSourceBoolean : boolean; external name 'audioSource';
  317. FaudioSourceTrack : TJSMediaStreamTrack; external name 'audioSource';
  318. FenableStereo : Boolean; external name 'enableStereo';
  319. FdisableAudioProcessing : Boolean; external name 'disableAudioProcessing';
  320. FfacingMode : string; external name 'facingMode';
  321. FframeRate : Byte;external name 'frameRate';
  322. FmaxResolution : TOTMediaResolution; external name 'maxResolution';
  323. Fresolution : string; external name 'resolution';
  324. FvideoSource : JSValue; external name 'videoSource';
  325. FvideoSourceString : String; external name 'videoSource';
  326. FvideoSourceBoolean : boolean; external name 'videoSource';
  327. FvideoSourceTrack : TJSMediaStreamTrack; external name 'videoSource';
  328. Public
  329. Property AudioSource : JSValue Read FaudioSource Write FaudioSource;
  330. Property AudioSourceString : String Read FaudioSourceString Write FaudioSourceString;
  331. Property AudioSourceBoolean : boolean Read FaudioSourceBoolean Write FaudioSourceBoolean;
  332. Property AudioSourceTrack : TJSMediaStreamTrack Read FaudioSourceTrack Write FaudioSourceTrack;
  333. Property DisableAudioProcessing : Boolean Read FdisableAudioProcessing Write FdisableAudioProcessing;
  334. Property EnableStereo : Boolean Read FenableStereo Write FenableStereo;
  335. Property FacingMode : string Read FfacingMode Write FfacingMode;
  336. Property FrameRate : Byte Read FframeRate Write FframeRate;
  337. Property MaxResolution : TOTMediaResolution Read FmaxResolution Write FmaxResolution;
  338. Property Resolution : string Read Fresolution Write Fresolution;
  339. Property VideoSource : JSValue Read FvideoSource Write FvideoSource;
  340. Property VideoSourceString : String Read FvideoSourceString Write FvideoSourceString;
  341. Property VideoSourceBoolean : boolean Read FvideoSourceBoolean Write FvideoSourceBoolean;
  342. Property VideoSourceTrack : TJSMediaStreamTrack Read FvideoSourceTrack Write FvideoSourceTrack;
  343. end;
  344. TOTUIStyle = Class external name 'Object' (TJSObject)
  345. Public
  346. FarchiveStatusDisplayMode : string; external name 'archiveStatusDisplayMode';
  347. FaudioLevelDisplayMode : string; external name 'audioLevelDisplayMode';
  348. FbackgroundImageURI : String; external name 'backgroundImageURI';
  349. FbuttonDisplayMode : String; external name 'buttonDisplayMode';
  350. FnameDisplayMode : string; external name 'nameDisplayMode';
  351. Public
  352. Property ArchiveStatusDisplayMode : string Read FarchiveStatusDisplayMode Write FarchiveStatusDisplayMode;
  353. Property AudioLevelDisplayMode : string Read FaudioLevelDisplayMode Write FaudioLevelDisplayMode;
  354. Property BackgroundImageURI : String Read FbackgroundImageURI Write FbackgroundImageURI;
  355. Property ButtonDisplayMode : String Read FbuttonDisplayMode Write FbuttonDisplayMode;
  356. Property NameDisplayMode : string Read FnameDisplayMode Write FnameDisplayMode;
  357. end;
  358. TOTInitPublisherOptions = Class external name 'Object' (TOTGetUserMediaOptions)
  359. Private
  360. FaudioBitrate : Nativeint; external name 'audioBitrate';
  361. FaudioFallbackEnabled : Boolean; external name 'audioFallbackEnabled';
  362. FfitMode: string; external name 'fitMode';
  363. Fheight : NativeInt; external name 'height';
  364. FheightString : String; external name 'height'; // Same as height but as string;
  365. FinsertDefaultUI : Boolean; external name 'insertDefaultUI';
  366. FinsertMode : string; external name 'insertMode';
  367. Fmirror : boolean; external name 'mirror';
  368. Fname : string;external name 'name';
  369. FpublishAudio : Boolean; external name 'publishAudio';
  370. FpublishVideo : Boolean; external name 'publishVideo';
  371. FshowControls : Boolean; external name 'showControls';
  372. Fstyle : TOTUIStyle; external name 'style';
  373. FusePreviousDeviceSelection : Boolean; external name 'usePreviousDeviceSelection';
  374. Fwidth : NativeInt; external name 'width';
  375. FwidthString : String; external name 'width'; // Same as width but as string;
  376. Public
  377. Property AudioBitrate : Nativeint Read FaudioBitrate Write FaudioBitrate ;
  378. Property AudioFallbackEnabled : Boolean Read FaudioFallbackEnabled Write FaudioFallbackEnabled ;
  379. Property FitMode: string Read FfitMode Write FfitMode ;
  380. Property Height : NativeInt Read Fheight Write Fheight ;
  381. Property HeightString : String Read FheightString Write FheightString ;
  382. Property InsertDefaultUI : Boolean Read FinsertDefaultUI Write FinsertDefaultUI ;
  383. Property InsertMode : string Read FinsertMode Write FinsertMode ;
  384. Property Mirror : boolean Read Fmirror Write Fmirror ;
  385. Property Name : string Read Fname Write Fname ;
  386. Property PublishAudio : Boolean Read FpublishAudio Write FpublishAudio ;
  387. Property PublishVideo : Boolean Read FpublishVideo Write FpublishVideo ;
  388. Property ShowControls : Boolean Read FshowControls Write FshowControls ;
  389. Property Style : TOTUIStyle Read Fstyle Write Fstyle ;
  390. Property UsePreviousDeviceSelection : Boolean Read FusePreviousDeviceSelection Write FusePreviousDeviceSelection ;
  391. Property Width : NativeInt Read Fwidth Write Fwidth ;
  392. Property WidthString : String Read FwidthString Write FwidthString ;
  393. end;
  394. TOTInitPublisherCallback = TOTErrorHandler;
  395. TOTInitSessionOptions = Class external name 'Object' (TJSObject)
  396. Protected
  397. FconnectionEventsSuppressed : Boolean; external name 'connectionEventsSuppressed';
  398. FipWhitelist : boolean; external name 'ipWhitelist';
  399. FiceConfig : TJSObject; external name 'iceConfig';
  400. Public
  401. Property ConnectionEventsSuppressed : Boolean Read FconnectionEventsSuppressed Write FconnectionEventsSuppressed ;
  402. Property IPWhitelist : boolean Read FipWhitelist Write FipWhitelist ;
  403. Property IceConfig : TJSObject Read FiceConfig Write FiceConfig ;
  404. end;
  405. TOTSubscriberAudioStats = record
  406. bytesReceived : NativeInt;
  407. packetsLost : NativeInt;
  408. packetsReceived : NativeInt;
  409. end;
  410. TOTSubscriberVideoStats = record
  411. bytesReceived : NativeInt;
  412. frameRate : NativeInt;
  413. packetsLost : NativeInt;
  414. packetsReceived : NativeInt;
  415. end;
  416. { TOTSubscriberStats }
  417. TOTSubscriberStats = Class external name 'Object' (TJSObject)
  418. private
  419. Faudio: TOTSubscriberAudioStats; external name 'audio';
  420. FTimeStamp: NativeInt; external name 'timestamp';
  421. Fvideo: TOTSubscriberVideoStats; external name 'video';
  422. Public
  423. Property audio : TOTSubscriberAudioStats Read Faudio;
  424. Property timestamp : NativeInt Read FTimeStamp;
  425. Property video : TOTSubscriberVideoStats Read Fvideo;
  426. end;
  427. TOTSubscriberStatsCallBack = Reference to Procedure (Error : TOTError; Stats : TOTSubscriberStats);
  428. TOTSubscriberStyleOptions = class external name 'Object' (TJSObject)
  429. Private
  430. FaudioBlockedDisplayMode : string; external name 'audioBlockedDisplayMode';
  431. FaudioLevelDisplayMode : string; external name 'audioLevelDisplayMode';
  432. FarchiveStatusDisplayMode : string; external name 'archiveStatusDisplayMode';
  433. FbackgroundImageURI : String; external name 'backgroundImageURI';
  434. FbuttonDisplayMode : string; external name 'buttonDisplayMode';
  435. FnameDisplayMode : string; external name 'nameDisplayMode';
  436. FvideoDisabledDisplayMode : string; external name 'videoDisabledDisplayMode';
  437. Public
  438. Property AudioBlockedDisplayMode : string Read FaudioBlockedDisplayMode Write FaudioBlockedDisplayMode ;
  439. Property AudioLevelDisplayMode : string Read FaudioLevelDisplayMode Write FaudioLevelDisplayMode ;
  440. Property ArchiveStatusDisplayMode : string Read FarchiveStatusDisplayMode Write FarchiveStatusDisplayMode ;
  441. Property BackgroundImageURI : String Read FbackgroundImageURI Write FbackgroundImageURI ;
  442. Property ButtonDisplayMode : string Read FbuttonDisplayMode Write FbuttonDisplayMode ;
  443. Property NameDisplayMode : string Read FnameDisplayMode Write FnameDisplayMode ;
  444. Property VideoDisabledDisplayMode : string Read FvideoDisabledDisplayMode Write FvideoDisabledDisplayMode ;
  445. end;
  446. { TOTSubscriber }
  447. TOTSubscriber = Class external name 'Subscriber' (TOTEventDispatcher)
  448. private
  449. FElement: TJSHTMLElement; external name 'element';
  450. FID: String; external name 'id';
  451. FStream: TOTStream; external name 'stream';
  452. Public
  453. Function getAudioVolume : NativeInt;
  454. Function getImgData : String;
  455. Procedure getStats(CallBack : TOTSubscriberStatsCallBack);
  456. Function getStyle : TJSObject;
  457. Function isAudioBlocked : boolean;
  458. Function restrictFrameRate(aValue : Boolean) : TOTSubscriber;
  459. Function setAudioVolume(aValue : NativeInt) : TOTSubscriber;
  460. Procedure setPreferredFrameRate(aFrameRate : NativeInt);
  461. Procedure setPreferredResolution(aResolution : TOTMediaResolution);
  462. Function setStyle(aStyle : TOTSubscriberStyleOptions) : TOTSubscriber; overload;
  463. Function setStyle(aProp,aValue : String): TOTSubscriber; overload;
  464. Function subscribeToAudio(aValue : Boolean) : TOTSubscriber;
  465. Function subscribeToVideo(aValue : Boolean) : TOTSubscriber;
  466. Function videoHeight : NativeInt;
  467. Function videoWidth : NativeInt;
  468. Public
  469. Property Element : TJSHTMLElement Read FElement;
  470. Property ID : String Read FID;
  471. Property Stream : TOTStream Read FStream;
  472. end;
  473. TOTSubscriberArray = Array of TOTSubscriber;
  474. { TOTSession }
  475. TOTConnectCallBack = TOTErrorHandler;
  476. TOTSignalData = Class external name 'Object' (TJSObject)
  477. Private
  478. Fdata : string; external name 'data';
  479. FretryAfterReconnect : Boolean; external name 'retryAfterReconnect';
  480. Fto : TOTConnection; external name 'to';
  481. FType : string; external name 'type';
  482. Public
  483. Property Data : string Read FData Write FData;
  484. Property RetryAfterReconnect : Boolean Read FretryAfterReconnect Write FretryAfterReconnect;
  485. Property To_ : TOTConnection Read FTo Write FTo;
  486. Property Type_ : string Read FType Write FType;
  487. end;
  488. { TJSSubscribeStyle }
  489. TJSSubscribeStyle = class external name 'Object' (TJSObject)
  490. Private
  491. FaudioBlockedDisplayMode : string; external name 'audioBlockedDisplayMode';
  492. FaudioLeveldDisplayMode : string; external name 'audioLeveldDisplayMode';
  493. FbackgroundImageURI : String; external name 'backgroundImageURI';
  494. FbuttonDisplayMode : string; external name 'buttonDisplayMode';
  495. FnameDisplayMode : string; external name 'nameDisplayMode';
  496. FvideoDisabledDisplayMode : String; external name 'videoDisabledDisplayMode';
  497. Public
  498. Property AudioBlockedDisplayMode : string Read FaudioBlockedDisplayMode Write FaudioBlockedDisplayMode;
  499. Property AudioLeveldDisplayMode : string Read FaudioLeveldDisplayMode Write FaudioLeveldDisplayMode;
  500. Property BackgroundImageURI : String Read FbackgroundImageURI Write FbackgroundImageURI;
  501. Property ButtonDisplayMode : string Read FbuttonDisplayMode Write FbuttonDisplayMode;
  502. Property NameDisplayMode : string Read FnameDisplayMode Write FnameDisplayMode;
  503. Property VideoDisabledDisplayMode : String Read FvideoDisabledDisplayMode Write FvideoDisabledDisplayMode;
  504. end;
  505. { TOTInitSubscriberOptions }
  506. TOTInitSubscriberOptions = class external name 'Object' (TJSObject)
  507. Private
  508. FaudioVolume : Byte; external name 'audioVolume';
  509. Ffitmode : string; external name 'fitmode';
  510. Fheight : NativeInt; external name 'height';
  511. FheightString : String; external name 'height';
  512. FinsertDefaultUI : Boolean; external name 'insertDefaultUI';
  513. FinsertMode : string; external name 'insertMode';
  514. FpreferredFrameRate : NativeInt; external name 'preferredFrameRate';
  515. FpreferredResolution : TOTMediaResolution; external name 'preferredResolution';
  516. FshowControls : Boolean; external name 'showControls';
  517. Fstyle : TJSSubscribeStyle; external name 'style';
  518. FsubscribeToAudio : Boolean; external name 'subscribeToAudio';
  519. FsubscribeToVideo : Boolean; external name 'subscribeToVideo';
  520. FtestNetwork : Boolean; external name 'testNetwork';
  521. Fwidth : NativeInt; external name 'width';
  522. FwidthString : String; external name 'width';
  523. Public
  524. Property AudioVolume : Byte read FaudioVolume Write FaudioVolume;
  525. Property Fitmode : string read Ffitmode Write Ffitmode;
  526. Property Height : NativeInt read Fheight Write Fheight;
  527. Property HeightString : String read FheightString Write FheightString; // height as string;
  528. Property InsertDefaultUI : Boolean read FinsertDefaultUI Write FinsertDefaultUI;
  529. Property InsertMode : string read FinsertMode Write FinsertMode;
  530. Property PreferredFrameRate : NativeInt read FpreferredFrameRate Write FpreferredFrameRate;
  531. Property PreferredResolution : TOTMediaResolution read FpreferredResolution Write FpreferredResolution;
  532. Property ShowControls : Boolean read FshowControls Write FshowControls;
  533. Property Style : TJSSubscribeStyle read Fstyle Write Fstyle;
  534. Property SubscribeToAudio : Boolean read FsubscribeToAudio Write FsubscribeToAudio;
  535. Property SubscribeToVideo : Boolean read FsubscribeToVideo Write FsubscribeToVideo;
  536. Property TestNetwork : Boolean read FtestNetwork Write FtestNetwork;
  537. Property Width : NativeInt read Fwidth Write Fwidth;
  538. Property WidthString : String read FwidthString Write FwidthString; // width as string;
  539. end;
  540. TOTSession = Class external name 'Session' (TOTEventDispatcher)
  541. private
  542. FCapabilities: TOTCapabilities; external name 'capabilities';
  543. FConnection: TOTConnection; external name 'connection';
  544. FSessionID: string; external name 'sessionId';
  545. public
  546. Procedure connect(aToken : String; callback : TOTConnectCallBack);
  547. Procedure disconnect;
  548. Procedure forceDisconnect(aConnection : TOTConnection; callBack : TOTConnectCallBack);
  549. Procedure forceUnpublish(aStream : TOTStream; callBack : TOTConnectCallBack);
  550. Function getPublisherForStream(aStream : TOTStream) : TOTPublisher;
  551. Function getSubscribersForStream(aStream : TOTStream) : TOTSubscriberArray;
  552. Function publish(aPublisher : TOTPublisher; callBack : TOTErrorHandler) : TOTPublisher; overload;
  553. Function publish(aPublisher : TOTPublisher) : TOTPublisher; overload;
  554. Procedure signal(aSignal : TJSObject; callBack :TOTErrorHandler);
  555. Procedure signal(aSignal : TOTSignalData; callBack :TOTErrorHandler);
  556. Function subscribe(stream : TOTStream; target : TJSHTMLElement; aProperties : TOTInitSubscriberOptions; callBack : TOTErrorHandler) : TOTSubscriber; overload;
  557. Function subscribe(stream : TOTStream; targetID : String; aProperties : TOTInitSubscriberOptions; callBack : TOTErrorHandler) : TOTSubscriber; overload;
  558. Procedure unpublish(aPublisher : TOTPublisher);
  559. Procedure unsubscribe(aSubscriber : TOTSubscriber);
  560. Public
  561. Property Capabilities : TOTCapabilities Read FCapabilities;
  562. Property Connnection : TOTConnection Read FConnection;
  563. Property SessionId : string Read FSessionID;
  564. end;
  565. TOTPublisherAudioStats = record
  566. bytesSent : NativeInt;
  567. packetsLost : NativeInt;
  568. packetsSent : NativeInt;
  569. end;
  570. TOTPublisherVideoStats = record
  571. bytesSent : NativeInt;
  572. frameRate : NativeInt;
  573. packetsLost : NativeInt;
  574. packetsSent : NativeInt;
  575. end;
  576. TOTPublisherStatsRecord = record
  577. audio : TOTPublisherAudioStats;
  578. timestamp : NativeInt;
  579. video : TOTPublisherVideoStats;
  580. end;
  581. { TOTPublisherStats }
  582. TOTPublisherStats = class external name 'Object' (TJSObject)
  583. private
  584. FConnectionID: String; external name 'connectionId';
  585. FStats: TOTPublisherStatsRecord; external name 'stats';
  586. FSubscriberID: String; external name 'subscriberId';
  587. Public
  588. Property ConnectionId : String read FConnectionID;
  589. Property Stats : TOTPublisherStatsRecord read FStats;
  590. Property SubscriberId : String Read FSubscriberID;
  591. end;
  592. TOTPublisherStatsArray = Array of TOTPublisherStats;
  593. TOTPublisherStatsCallback = Reference to Procedure (error : TOTError; StatsArray : TOTPublisherStatsArray);
  594. { TOTPublisherStyleOptions }
  595. TOTPublisherStyleOptions = class external name 'Object' (TJSObject)
  596. Private
  597. FarchiveStatusDisplayMode : string; external name 'archiveStatusDisplayMode';
  598. FaudioLevelDisplayMode : string; external name 'audioLevelDisplayMode';
  599. FbackgroundImageURI : String; external name 'backgroundImageURI';
  600. FbuttonDisplayMode : string; external name 'buttonDisplayMode';
  601. FnameDisplayMode : string; external name 'nameDisplayMode';
  602. Public
  603. Property ArchiveStatusDisplayMode : string Read FArchiveStatusDisplayMode Write FArchiveStatusDisplayMode;
  604. Property AudioLevelDisplayMode : string Read FaudioLevelDisplayMode Write FaudioLevelDisplayMode;
  605. Property BackgroundImageURI : String Read FbackgroundImageURI Write FbackgroundImageURI;
  606. Property ButtonDisplayMode : string Read FbuttonDisplayMode Write FbuttonDisplayMode;
  607. Property NameDisplayMode : string Read FnameDisplayMode Write FnameDisplayMode;
  608. end;
  609. { TOTPublisher }
  610. TOTPublisher = Class external name 'Publisher' (TOTEventDispatcher)
  611. private
  612. FaccessAllowed: Boolean; external name 'accessAllowed';
  613. Felement: TJSHTMLElement; external name 'element';
  614. FID: string;external name 'id';
  615. FSession: TOTSession;external name 'session';
  616. FStream: TOTStream;external name 'stream';
  617. public
  618. Function cycleVideo : TJSPromise;
  619. Function destroy : TOTPublisher;
  620. Function getAudioSource : TJSMediaStreamTrack;
  621. Function getImgData : String;
  622. Procedure getStats (callback : TOTPublisherStatsCallback);
  623. Function getStyle : TJSObject;
  624. Procedure publishAudio(value : Boolean);
  625. Procedure publishVideo(value : Boolean);
  626. Function setAudioSource(aID : String) : TJSPromise; overload;
  627. Function setAudioSource(aStream : TJSMediaStreamTrack) : TJSPromise; overload;
  628. Function setStyle(aStyle : TOTPublisherStyleOptions) : TOTPublisher; overload;
  629. Function setStyle(aProp,aValue : String): TOTPublisher; overload;
  630. Function videoHeight : NativeInt;
  631. Function videoWidth : NativeInt;
  632. Public
  633. Property AccessAllowed : Boolean read FaccessAllowed;
  634. Property Element : TJSHTMLElement read Felement;
  635. Property ID : string read FID;
  636. Property Stream : TOTStream Read FStream;
  637. Property Session : TOTSession read FSession;
  638. end;
  639. { ---------------------------------------------------------------------
  640. Main class, serves as namespace.
  641. ---------------------------------------------------------------------}
  642. { TOT }
  643. TOTReportIssueCallBack = reference to Procedure (err : TOTError; reportID : string);
  644. TOT = Class external name 'OT' (TOTEventDispatcher)
  645. Public
  646. const NONE : Integer;
  647. const ERROR : Integer;
  648. const WARN : Integer;
  649. const INFO : Integer;
  650. const LOG_ : Integer; // Cannot use external name :(
  651. const DEBUG : Integer;
  652. Public
  653. class Procedure checkScreenSharingCapability(callBack : TOTScreenSharingCapabilityCallback);
  654. class Function checkSystemRequirements : NativeInt;
  655. class Procedure getDevices(callBack : TOTGetDevicesCallback);
  656. class Function getSupportedCodecs : TJSPromise;
  657. class Function getUserMedia : TJSPromise;
  658. class Function getUserMedia(options : TOTGetUserMediaOptions) : TJSPromise;
  659. class Function initPublisher(aElement : TJSHTMLElement; properties : TOTInitPublisherOptions; CompletionHandler : TOTInitPublisherCallback) : TOTPublisher;
  660. class Function initPublisher(aElementId : String; properties : TOTInitPublisherOptions; CompletionHandler : TOTInitPublisherCallback) : TOTPublisher;
  661. class Function initSession(APIKey,SessionID : String) : TOTSession; overload;
  662. class Function initSession(APIKey,SessionID : String; Options : TOTInitSessionOptions) : TOTSession; overload;
  663. class Procedure log(msg : string);
  664. class Procedure registerScreenSharingExtension(kind : String; id : string; version : Integer);
  665. class Procedure reportIssue(aCallBack : TOTReportIssueCallBack);
  666. class Procedure setLogLevel(Number : String);
  667. class Procedure unblockAudio;
  668. class Procedure upgradeSystemRequirements;
  669. end;
  670. TOTClass = Class of TOT;
  671. var
  672. OpenTok : TOTClass; external name 'OT';
  673. implementation
  674. end.