demojitsimeet.lpr 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. program demojitsimeet;
  2. {$mode objfpc}
  3. {$modeswitch externalclass}
  4. uses
  5. Types, TypInfo, JS, Classes, SysUtils, Web, browserapp, libjitsimeet;
  6. Type
  7. { TJitsiClient }
  8. TJitsiClient = Class(TBrowserApplication)
  9. Private
  10. returnURL : string;
  11. jitsicontainer,jitsinode,options : TJSHTMLElement;
  12. svr,room,email,nick : TJSHTMLInputElement;
  13. BtnConnect : TJSHtmlButtonElement;
  14. BtnLeave : TJSHtmlButtonElement;
  15. API : TJMExternalAPI;
  16. GUIElements : Array[TJMUIElement] of TJSHTMLInputElement;
  17. procedure BindElements;
  18. procedure ConnectToJitsi;
  19. function DoConnectClick(aEvent: TJSMouseEvent): boolean;
  20. function DoDisConnectClick(aEvent: TJSMouseEvent): boolean;
  21. procedure doHangup(Arg: JSValue);
  22. function GetServer: String;
  23. Protected
  24. Procedure DoRun; override;
  25. end;
  26. Var
  27. Application : TJitsiClient;
  28. { TJitsiClient }
  29. function TJitsiClient.DoConnectClick(aEvent: TJSMouseEvent): boolean;
  30. begin
  31. Result:=True;
  32. if room.value='' then
  33. Window.alert('No room specified')
  34. else
  35. begin
  36. ConnectToJitsi;
  37. Options.style.cssText:='display: none;';
  38. BtnLeave.disabled:=False;
  39. BtnConnect.Disabled:=True;
  40. end;
  41. end;
  42. function TJitsiClient.DoDisConnectClick(aEvent: TJSMouseEvent): boolean;
  43. begin
  44. API.Hangup;
  45. end;
  46. procedure TJitsiClient.doHangup(Arg : JSValue);
  47. begin
  48. BtnLeave.disabled:=True;
  49. BtnConnect.Disabled:=False;
  50. Options.style.cssText:='';
  51. jitsinode.innerHTML:='';
  52. end;
  53. Function TJitsiClient.GetServer : String;
  54. begin
  55. Result:=svr.value;
  56. if Result='' then
  57. Result:='meet.jit.si';
  58. end;
  59. Procedure TJitsiClient.ConnectToJitsi;
  60. var
  61. opts : TJMMeetOptions;
  62. user : TJMUserInfo;
  63. cfg : TJMInterfaceConfig;
  64. el : TJMUIElement;
  65. els : TJMUIElements;
  66. begin
  67. els:=[];
  68. for el in TJMUIElement do
  69. if GUIElements[el].checked then
  70. Include(els,el);
  71. opts:=TJMMeetOptions.New;
  72. opts.noSSL:=False;
  73. opts.parentNode:=jitsinode;
  74. opts.roomName:=room.Value;
  75. if (email.value<>'') then
  76. begin
  77. user:=TJMUserInfo.New;
  78. user.email:=email.value;
  79. opts.userInfo:=user;
  80. end;
  81. cfg:=TJMInterfaceConfig.New;
  82. cfg.ToolbarButtons:=UIElementsStrings(Els);
  83. opts.interfaceConfigOverwrite:=cfg;
  84. API:=TJMExternalAPI.New(GetServer,opts);
  85. API.on_(EventReadyToClose,@DoHangup);
  86. if nick.value<>'' then
  87. API.SetDisplayName(nick.value);
  88. end;
  89. procedure TJitsiClient.BindElements;
  90. Var
  91. E : TJMUIElement;
  92. begin
  93. jitsinode:=GetHTMLElement('jitsi');
  94. svr:=TJSHTMLInputElement(GetHTMLElement('edtServer'));
  95. room:=TJSHTMLInputElement(GetHTMLElement('edtRoom'));
  96. email:=TJSHTMLInputElement(GetHTMLElement('edtEmail'));
  97. nick:=TJSHTMLInputElement(GetHTMLElement('edtNick'));
  98. jitsicontainer:=GetHTMLElement('jitsi-container');
  99. btnConnect:=TJSHtmlButtonElement(GetHTMLElement('btnConnect'));
  100. BtnLeave:=TJSHtmlButtonElement(GetHtmlElement('btnDisconnect'));
  101. options:=GetHTMLElement('Options');
  102. For E in TJMUIElement do
  103. GUIElements[E]:=TJSHTMLInputElement(GetHTMLElement(GetEnumName(TypeInfo(TJMUIElement),Ord(E))));
  104. end;
  105. procedure TJitsiClient.DoRun;
  106. begin
  107. Terminate;
  108. BindElements;
  109. ReturnURL:=window.location.href;
  110. btnConnect.onclick:=@DoConnectClick;
  111. btnLeave.onclick:=@DoDisConnectClick;
  112. end;
  113. begin
  114. Application:=TJitsiClient.Create(Nil);
  115. Application.Initialize;
  116. Application.Run;
  117. end.