Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. async _initSignal(Janus, session){
  2. let textPlugin;
  3. let stingId = Janus.randomString(5);
  4. let opaqueId = Number(new Date());
  5.  
  6. let onSuccess = (pluginHandle) =>{
  7. textPlugin = pluginHandle;
  8.  
  9. pluginHandle.send({
  10. message: {
  11. request: 'setup'
  12. }
  13. });
  14. };
  15.  
  16. let onMessage = (msg, jsep) => {
  17. let error = msg.error;
  18.  
  19. if (error){
  20. this.trigger('exception', error);
  21. }
  22.  
  23. if (jsep){
  24.  
  25. let answer = {
  26. jsep,
  27. media: {
  28. audio: false,
  29. video: false,
  30. data: true
  31. },
  32. success: (jsep) => {
  33. textPlugin.send({
  34. jsep,
  35. message: {
  36. request: 'ack'
  37. }
  38. });
  39. },
  40. error: this.onError.bind(this)
  41. };
  42. textPlugin.createAnswer(answer);
  43. }
  44. };
  45.  
  46. let onDataOpen = (/*data*/) => {
  47. Janus.log("The DataChannel is available!");
  48.  
  49. let transaction = Janus.randomString(12);
  50. let register = {
  51. textroom: 'join',
  52. transaction: transaction,
  53. room: this.textRoomId,
  54. username: stingId,
  55. display: stingId
  56. };
  57.  
  58. textPlugin.data({
  59. text: JSON.stringify(register),
  60. error: this.onError.bind(this)
  61. });
  62. };
  63.  
  64. let onData = (data) =>{
  65. let json = JSON.parse(data);
  66.  
  67. let eventName = json["textroom"];
  68.  
  69. if (eventName === 'success'){
  70. exempleResolveFunction()
  71. }
  72.  
  73. if (eventName === 'message'){
  74. exampleGetMessage(json);
  75. }
  76. };
  77.  
  78. session.attach({
  79. plugin: "janus.plugin.textroom",
  80. opaqueId: opaqueId,
  81. success: onSuccess,
  82. error: this.onError.bind(this),
  83. onmessage: onMessage,
  84. ondataopen: onDataOpen,
  85. ondata: onData
  86. });
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement