Repository navigation
Expand file tree
/
Copy pathwebphone_api.js
More file actions
1496 lines (1359 loc) · 62.5 KB
/
Copy pathwebphone_api.js
File metadata and controls
1496 lines (1359 loc) · 62.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Mizu WebPhone Java Script API.
* This file is the main interface of the WebPhone, which must be included in your html (<script src="PATH/webphone_api.js"></script>).
* You can interact with the WebPhone using the API functions below.
* See the documentation about the usage: https://www.mizu-voip.com/Portals/0/Files/Webphone_Documentation.pdf
*/
var webphone_api = (function ()
{
/**
* API parameter configuration have been moved to: webphone_config.js.
* (If you set any parameters here, those will be still loaded)
*/
var parameters = {};
/** Call this function once, passing a callback.
* The passed callback function will be called on every app state change. The states are:
* "loaded" - the webphone library is completely loaded so you can start the usage (call any other API functions after this state is received).
* "started" - the VoIP engine has successfully started (ready to register or make calls). Note: you can initiate calls also from the onLoaded and it will be queued to be executed after started.
* "stopped" - the VoIP engine has stopped (all endpoints and sipstack is destroyed).
* --PARAMETERS --
* state: the callback function will have a String parameter containing the new state of the application */
function onAppStateChange(callback)
{
if(callback === null) { webphone_api.appstatechangecb = []; return; }
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.appstatechangecb.push(callback);
}
/** Call this function once, passing a callback.
* The passed callback function will be called on every register state change. The states are:
* "registered" - the webphone is registered to the VoIP server, so you can start dialing/receiving calls/chats
* "unregistered" - the webphone is unregistered from the VoIP server
* "failed" - the webphone failed to register to the VoIP server
* --PARAMETERS --
* state: the callback function will have a String parameter containing the new state of register
* reason: the callback function will have a second String parameter containing the reason of the failed registration (only for "failed" state) */
function onRegStateChange(callback)
{
if(callback === null) { webphone_api.regstatechangecb = []; return; }
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.regstatechangecb.push(callback);
}
/** Call this function once, passing a callback.
* The passed callback function will be called on every call state change.
* --PARAMETERS --
* event: can have following values: callSetup, callRinging, callConnected, callDisconnected
* direction: 1 (outgoing), 2 (incoming)
* peername: is the other party username
* peerdisplayname: is the other party display name if any
* line: the event refers to this line
* callid: Call-ID header value from SIP signaling*/
function onCallStateChange(callback)
{
if(callback === null) { webphone_api.callstatechangecb = []; return; }
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.callstatechangecb.push(callback);
}
/** Call this function once, passing a callback.
* The passed callback function will be called when chat message is received.
* --PARAMETERS --
* from: username, phone number or sip URI of the sender
* msg: the content of the text message
* line: chat message received on this line
* group: group name; the name of the group if it's group chat, otherwise it will be an empty string */
function onChat(callback)
{
if(callback === null) { webphone_api.chatcb = []; return; }
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.chatcb.push(callback);
}
/** Call this function once, passing a callback.
* The passed callback function will be called when SMS is received.
* --PARAMETERS --
* from: phone number of the sender
* msg: the content of the text message */
function onSMS(callback)
{
if(callback === null) { webphone_api.smscb = []; return; }
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.smscb.push(callback);
}
/** Call this function once, passing a callback.
* The passed callback function will be called after each call. You will receive a CDR (call detail record).
* --PARAMETERS --
* caller: the caller party username
* called: called party username
* connecttime: milliseconds elapsed between call initiation and call connect
* duration: milliseconds elapsed between call connect and hangup (0 for not connected calls. Divide by 1000 to obtain seconds.)
* direction: 1 (outgoing), 2 (incoming)
* peerdisplayname: is the other party display name if any
* reason: disconnect reason as string
* line: the CDR refers to this line
* callid: Call-ID SIP header
*/
function onCdr(callback)
{
if(callback === null) { webphone_api.cdrcb = []; return; }
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.cdrcb.push(callback);
}
/** Call this function once, passing a callback.
* The passed callback function will be called when a DTMF is received.
* --PARAMETER --
* dtmf: string DTMF character
* line: the DTMF refers to this line */
function onDTMF(callback)
{
if(callback === null) { webphone_api.cddtmf = []; return; }
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.cddtmf.push(callback);
}
/**
* Optionally you can "start" the phone, before making any other action.
* In some circumstances the initialization procedure might take a few seconds (depending on usable engines) so you can prepare the webphone with this method
* to avoid any delay when the user really needs to use by pressing the call button for example.
* If the serveraddress/username/password is already set and auto register is not disabled, then the webphone will also register (connect) to the SIP server upon start.
* If start is not called, then the webphone will initialize itself the first time when you call some other function such as register or call.
* The webphone parameter should be set before you call this method (preset in the js file or by using the setparameter function).
*/
function start ()
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
{
return webphone_api.addtoqueue('Start', [parameters, true]);
}
else
return webphone_api.plhandler.Start(parameters, true);
}
/**
* Will stop all endpoints and sipstack. This function call is optional */
function stop ()
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Stop', [parameters]);
else
webphone_api.plhandler.Stop(parameters);
}
/** Optionally you can "register". This will "connect" to the SIP server if not already connected by the start method */
function register ()
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Register', [parameters]);
else
webphone_api.plhandler.Register(parameters);
}
/** Used to register to with multiple SIP accounts
* the accounts are passed as string in the following format:
* server,usr,pwd,ival#server2,usr2,pwd2,ival;*/
function registerex (accounts)
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('RegisterEx', [accounts]);
else
webphone_api.plhandler.RegisterEx(accounts);
}
/** Initiate call to a number, sip username or SIP URI. Parameter "number" must be of type String.*/
function call (number)
{
if (typeof (number) === 'undefined' || number === null) number = '';
else number = number.toString();
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Call', [number]);
else
webphone_api.plhandler.Call(number);
}
/** Initiate video call to a number, sip username or SIP URI. Parameter "number" must be of type String.*/
function videocall (number)
{
if (typeof (number) === 'undefined' || number === null) number = '';
else number = number.toString();
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('VideoCall', [number]);
else
webphone_api.plhandler.VideoCall(number);
}
/** Disable/enable video(stream) during a video call
* state: (boolean) can be true or false
* The direction can have the following values:
* 0: state both (default)
* 1: state remote
* 2: state local*/
function mutevideo(state, direction)
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('MuteVideo', [mute, direction]);
else
webphone_api.plhandler.MuteVideo(state, direction);
}
/** Set the size of the displayed video container. Can also be configured from css/video.css
* type: 1=for remote video container, 2=for local video container
* width: integer value of width in pixels
* height: integer value of height in pixels; this parameter can be left empty or null, and the height will be set depending on the video's aspect ratio*/
function setvideodisplaysize(type, width, height)
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('SetVideoSize', [type, width, height]);
else
webphone_api.plhandler.SetVideoSize(type, width, height);
}
/** Initiate screenshare call to a number, sip username or SIP URI. Just omit "screenid" parameter; this can be used only in Chrome OS*/
function screenshare (number, screenid)
{
if (typeof (number) === 'undefined' || number === null) number = '';
else number = number.toString();
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('ScreenShare', [number, screenid]);
else
webphone_api.plhandler.ScreenShare(number, screenid);
}
/** Terminate screenshare. hangup() function can also be used.*/
function stopscreenshare ()
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('StopScreenShare', []);
else
webphone_api.plhandler.StopScreenShare();
}
/** Disconnect current call(s).*/
function hangup (isinternal)
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Hangup', []);
else
webphone_api.plhandler.Hangup(null, isinternal);
}
/** Connect incoming call*/
function accept ()
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
return webphone_api.addtoqueue('Accept', []);
else
return webphone_api.plhandler.Accept();
}
/** Disconnect incoming call.*/
function reject (line, reason)
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Reject', []);
else
{
if (webphone_api.common.isNull(reason)) reason = '33';
webphone_api.plhandler.Reject(line, reason);
}
}
/** Ignore incoming call.*/
function ignore ()
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Ignore', []);
else
webphone_api.plhandler.Ignore();
}
/**
* Get details about a line. The line parameter can be -1 (will return the “best” line status).
* Will return the following string:
* LINEDETAILS,line,state,callid,remoteusername,localusername,type,localaddress,serveraddress,mute,hold,remotefullname */
function getlinedetails(line)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.GetLineDetails(line);
else
return '';
}
/**
* Returns a String with details about the last finished call
*/
function getlastcalldetails ()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.GetLastCallDetails();
else
return '';
}
/**
* Call this function passing a callback.
* The passed callback function will be called with a String parameter containing the reason of the last failed registration. Set the extended parameter to true to get more details
*/
function getregfailreason(callback, extended)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.GetRegFailReason(callback, extended);
else
webphone_api.Log('ERROR, webphone_api: getregfailreason webphone_api.plhandler is not defined');
}
/** Play any sound file, at least wave files (raw linear PCM) are supported in the following format: PCM SIGNED 8000.0 Hz (8 kHz) 16 bit mono (2 bytes/frame) in little-endian (128 kbits)
* --PARAMETERS --
* start: int - 1 for start or 0 to stop the playback, -1 to pre-cache
* file: String - file name or full path
* looping: int - 1 to repeat, 0 to play once
* toremotepeer: boolean - stream the playback to the connected peer
*/
function play(start, file, looping, toremotepeer)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.PlaySound(start, file, looping, toremotepeer);
else
webphone_api.Log('ERROR, webphone_api: play webphone_api.plhandler is not defined');
return false;
}
/**
* Returns a String list of available call functions, separated by comma, based on what functions are supported by the current VoIP engine
* Possible values: conference,transfer,mute,hold,chat
* or ERROR, if webphone is not yet started
*/
function getavailablecallfunc ()
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
{
webphone_api.Log('ERROR, webphone_api: getavailablecallfunc webphone_api.plhandler is not defined');
return 'ERROR, webphone is not yet started';
}
else
{
return webphone_api.plhandler.GetAvailableCallfunc();
}
}
/**
* Forward incoming call to number
*/
function forward (number)
{
if (typeof (number) === 'undefined' || number === null) number = '';
else number = number.toString();
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Forward', [number]);
else
webphone_api.plhandler.Forward(number);
}
/**
* Add people to conference.
* If number is empty than will mix the currently running calls (if there is more than one call)
* Otherwise it will call the new number (usually a phone number or a SIP user name) and once connected will join with the current session.
* number: string parameter, usually a phone number or a SIP user name
* add: boolean, true if to add, false to remove
*/
function conference (number, add)
{
if (typeof (number) === 'undefined' || number === null) number = '';
else number = number.toString();
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Conference', [number, add]);
else
webphone_api.plhandler.Conference(number, add);
}
/**
* Transfer current call to number which is usually a phone number or a SIP username. (Will use the REFER method after SIP standards).
* You can set the mode of the transfer with the "transfertype" parameter.
*/
function transfer (number)
{
if (typeof (number) === 'undefined' || number === null) number = '';
else number = number.toString();
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Transfer', [number]);
else
webphone_api.plhandler.Transfer(number);
}
/**
* Send DTMF message by SIP INFO or RFC2833 method (depending on the "dtmfmode" parameter).
* Please note that the "msg" parameter is a string. This means that multiple dtmf characters can be passed at once
* and the webphone will streamline them properly. Use the space character to insert delays between the digits.
* The dtmf messages are sent with the protocol specified with the “dtmfmode” parameter.
* Example: dtmf(" 12 345 #");
*/
function dtmf (msg)
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('Dtmf', [msg]);
else
webphone_api.plhandler.Dtmf(msg);
}
/**
* Mute current call. The direction can have the following values:
* 0: state both
* 1: state out (speakers)
* 2: state in (microphone) (Default)
*/
function mute (state, direction, isinternal)
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
return webphone_api.addtoqueue('MuteEx', [mute, direction]);
else
return webphone_api.plhandler.MuteEx(state, direction, isinternal);
}
/** Will return true if the call is muted, otherwise false */
function ismuted ()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.IsMuted();
else
return false;
}
/**
* Set state to "true" to put the calll on hold
* or "false" to unhold the call
*/
function hold (state, isinternal)
{
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
return webphone_api.addtoqueue('Hold', [state]);
else
return webphone_api.plhandler.Hold(state, null, isinternal);
}
/** Will return true if the call is on hold, otherwise false */
function isonhold ()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.IsOnHold();
else
return false;
}
/**
* Send a chat message. (SIP MESSAGE method after RFC 3428)
* --PARAMETERS --
* number: String - can be a phone number or SIP username/extension number.
* msg: String - the content of the chat message
* group: String - group name; has to be sent only for group chat, otherwise it can be an empty string
*/
function sendchat (number, msg, group)
{
if (typeof (number) === 'undefined' || number === null) number = '';
else number = number.toString();
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('SendChat', [number, msg]);
else
webphone_api.plhandler.SendChat(number, msg, group);
}
/**
* Send a SMS message.
* Number can be a PSTN or mobile phone number.
* from is optional
*/
function sendsms (number, msg, from)
{
if (typeof (number) === 'undefined' || number === null) number = '';
else number = number.toString();
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
webphone_api.addtoqueue('SendSms', [number, msg, from]);
else
webphone_api.plhandler.SendSms(number, msg, from);
}
/** Call this function and pass a callback, to receive the incoming caller id (might return two lines: caller id \n caller name)
* NOTE: if you just need the caller id, you should just use the onCallState peer name instead of this function.
* The callback will be called with a string parameter which will contain the incoming caller id. */
function getcallerdisplayfull (callback)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.GetIncomingDisplay(callback);
else
return '';
}
/** Start/stop voice record
* start: true/false
* url: FTP or HTTP url where the voice file will be uploaded to*/
function voicerecord (start, url)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.Voicerecord(start, url);
}
/** Open audio/video device selector dialog (built-in user interface).*/
function devicepopup ()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.DevicePopup();
}
/** Call this function and pass a callback, to receive a list of all available audio devices.
* For the dev parameter pass 0 for recording device names list, 1 for the playback, 2 for ringer devices, 3 for video camera devices
* The callback will be called with a string parameter which will contain the audio device names separated by CRLF */
function getdevicelist (dev, callback)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
if (typeof (dev) === 'undefined' || dev === null || dev.length < 1) dev = '-12';
webphone_api.plhandler.GetDeviceList(dev, callback);
}
}
/** Call this function and pass a callback, to receive the currently set audio device.
* For the dev parameter pass 0 for recording device, 1 for the playback, 2 for ringer device , 3 for video camera devices
* The callback will be called with a string parameter which will contain the currently set audio device names */
function getdevice (dev, callback)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
if (typeof (dev) === 'undefined' || dev === null || dev.length < 1) dev = '-13';
webphone_api.plhandler.GetDevice(dev, callback);
}
}
/** Select an audio device. The devicename should be a valid audio device name (you can list them with the getdevicelist() call)
* For the dev parameter pass 0 for recording device, 1 for the playback, 2 for ringer device, 3 for video camera devices
* The "immediate" parameter can have the following values (!!! only for Java and Native Service engines):
-0: default
-1: next call only
-2: immediately for active calls
*/
function setdevice (dev, devicename, immediate, fromcode)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
if (typeof (dev) === 'undefined' || dev === null || dev.length < 1) dev = '-14';
if (typeof (fromcode) === 'undefined' || fromcode === null) fromcode = 1;
webphone_api.plhandler.SetDevice(fromcode, dev, devicename, immediate);
}
}
/**
* Set volume (0-100%) for the selected device. Default value is 50% -> means no change
* The dev parameter can have the following values:
* 0 for the recording (microphone) audio device
* 1 for the playback (speaker) audio device
* 2 for the ringback (speaker) audio device
*/
function setvolume(dev, volume)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.SetVolume(dev, volume);
}
/**
* Call this function, passing a callback
* Return the volume (0-100%) for the selected device.
* The dev parameter can have the following values:
* 0 for the recording (microphone) audio device
* 1 for the playback (speaker) audio device
* 2 for the ringback (speaker) audio device
* --PARAMETERS --
* volume: integer representing the volume
*/
function getvolume(dev, callback)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
if (typeof (dev) === 'undefined' || dev === null || dev.length < 1) dev = '-15';
webphone_api.plhandler.GetVolume(dev, callback);
}
}
/** Call this function with boolean parameter "true" to set the default playback device on Android phones and tablets to speakerphone
* set: Boolean - true/false
*/
function setloudspeaker(set)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.SetLoudspeaker(set);
}
/**
* Create new contact in the webphone's phonebook/contact list.
* --PARAMETERS --
* fullname: String - the full name of the contact. If empty, it will be the same as the number
* number: String - Phone number or SIP URI
* email: String
* address: String
* notes: String
* website: String */
function addcontact(fullname, number, email, address, notes, website, type, isfavorite)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.AddContact(fullname, number, email, address, notes, website, type, isfavorite);
else
return false;
}
/**
* Delete existing contact from webphone's phonebook/contact list, if matches the passed name and/or number.
* --PARAMETERS --
* name: String - delete the contact that match this name
* number: String - delete the contact that match this Phone number or SIP URI */
function deletecontact(name, number)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.DeleteContact(name, number);
else
return false;
}
/**
* Delete all contacts from webphone's phonebook/contact list
*/
function delallcontacts()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.DeleteAllContacts();
else
return false;
}
/** Call this function passing the name and/or number of the contact.
* It will return a String with the following parameters separated by "tabs": \t if found. If not found, then it will return null.
* --PARAMETERS --
* name: String - the name of the contact
* number: String - number(s)/SIP URI(s) of the contact separated by Pipe(Vertical bar): |
* favorite: int - 0=No, 1=Yes
* email: String - email address of the contact
* address: String - the address of the contact
* notes: String - notes attached to this contact
* website: String: web site attached to this contact*/
function getcontact(name ,number)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.GetContact(name, number);
else return null;
}
/** This function will return a String containing the whole contact list. If there are no contacts, it will return null.
Set the all parameter to true to receive also virtual contacts as well, like voicemail number, etc...
Contacts will be separated by "carriage return new line": \r\n
Contact fields will be separated by "tabs": \t
A contact can have more than one phone numbers or SIP URIs, so these will be separated by Pipe(Vertical bar): |
See example below:
The order of fields and their meaning:
name: String - the name of the contact
number: array of String - the number(s)/SIP URI(s) of the contact
favorite: int - 0=No, 1=Yes
email: String - email address of the contact
address: String - the address of the contact
notes: String - notes attached to this contact
website: String: web site attached to this contact
Example: Name \t Number1|Number2 \t Favorite \t Email \t Address \t Notes \t Website\r\n
*/
function listcontacts(all)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.ListContacts(all);
else return null;
}
/**
* (Re)Download the contactlist as sepecified in the serveraddressbook_url parameter
*/
function synccontacts()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.DownloadServerAddressbook(true);
else
return false;
}
/** This function will return a String containing the whole call history list. If there are no entries in call history, it will return null.
Call history entries will be separated by "carriage return new line": \r\n
Call history fields will be separated by "tabs": \t
The order of fields and their meaning:
type: int - 0=Outgoing call, 1=Incoming call, 2=Missed call
name: String - can be a name, can be the same as the number or can be empty String
number: String - the phone number/SIP URI
date: int - timestamp date of call
duration: int - duration of the call in milliseconds
discreason: String - call disconnect reason
Example: 1 \t Name \t Number \t Date \t Duration \t Discreason
*/
function listcallhistory()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.ListCallhistory();
else return null;
}
/** Any additional parameters must be set before start/register/call is called*/
function setparameter (param, value, allowempty)
{
if (typeof (param) === 'undefined' || param === null || typeof (value) === 'undefined') { return false; }
if (typeof (allowempty) === 'undefined' || allowempty === null || allowempty === true)
{
if (typeof (value) === 'undefined' || value === null || value.length < 1)
{
value = 'NULL';
}
}
if (typeof (webphone_api.plhandler) === 'undefined' || webphone_api.plhandler === null)
{
webphone_api.Log2('WARNING, webphone not initialized yet. webphone_api.setparameter AddToQueue: ' + param + ': ' + value);
return webphone_api.addtoqueue('SetParameter', [param, value]);
}
else{
var valtoprint = value;
if (param === 'password') { valtoprint = '*****'; } //|| param === 'sipusername' || param === 'username'
webphone_api.Log2('EVENT, webphone_api.setparameter: ' + param + ': ' + valtoprint);
return webphone_api.plhandler.SetParameter(param, value);
}
}
/** Will return value of a parameter if exists, otherwise will return empty string*/
function getparameter (param) // string
{
if (typeof (param) === 'undefined' || param === null) { return ''; }
var value = parameters[param];
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
return webphone_api.plhandler.GetParameter(param);
}else
{
var err_msg = 'ERROR, Webphone settings not loaded just yet';
if (typeof (console) !== 'undefined' && console !== null)
{
if (typeof (console.error) !== 'undefined' && console.error !== null) { console.error(err_msg); }
else if (typeof (console.log) !== 'undefined' && console.log !== null) { console.log(err_msg); }
}
}
if (typeof (value) === 'undefined' || value === null) { return ''; }
return value;
}
/** Will set the current line. Use only if you present line selection for the users. Otherwise, you don’t have to take care about the lines as it is handled automatically by the webphone. Don't set / ignore the second keeplastreal parameter (for internal usage only). */
function setline (line, keeplastreal)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.SetLine(line, keeplastreal);
}
/** Will return the current active line number. This should be the line, which you have set previously except after incoming and outgoing calls (the webphone will automatically switch the active line to a new free line for these if the current active line is already occupied by a call). */
function getline () //int
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
return webphone_api.plhandler.GetLine();
}
return -1;
}
/** Call this function passing a line number and a callback
* The passed callback function will be called with one parameter, which will be the SIP Call-ID for the passed line number. */
function linetocallid (line, callback)
{
if ( !callback || typeof (callback) !== 'function' ) { return; }
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
webphone_api.plhandler.LineToCallID(line, callback);
}
else {
webphone_api.Log('ERROR, webphone_api: linetocallid webphone_api.plhandler is not defined');
}
}
/** Call this function passing a SIP Call-ID and a callback
* The passed callback function will be called with one parameter, which will be the line number for the passed SIP Call-ID. */
function callidtoline (callid, callback)
{
if ( !callback || typeof (callback) !== 'function' ) { return; }
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
webphone_api.plhandler.CallIDToLine(callid, callback);
}
else{
webphone_api.Log('ERROR, webphone_api: callidtoline webphone_api.plhandler is not defined');
}
}
/** Set or get the SIP Call-ID used for the first upcoming new SIP session.
* The return value is the new SIP Call-ID as string to be used in the upcoming SIP session. */
function nextcallid (callid)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
{
return webphone_api.plhandler.NextCallID(callid);
}
webphone_api.Log('ERROR, webphone_api: nextcallid webphone_api.plhandler is not defined');
return '';
}
/** Return true if the webphone is registered ("connected") to the SIP server.*/
function isregistered () // boolean
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.IsRegistered();
else
return false;
}
/** Return true if the user is in call, false otherwise*/
function isincall () // boolean
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.IsInCall();
else
return false;
}
/** Unregister SIP account from VoIP server*/
function unregister ()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.Unregister();
}
/**
* Will receive presence information as events: PRESENCE, status,username,displayname,email (displayname and email can be empty)
* To receive events use the "onEvent(callback)" API function
* userlist: list of sip account usernames separated by comma
* Also it will return an empty String or a String containing a list of users and their presence statuses separated by semicolon, example: "111111,online;222222offline;333333,online"
* Also, a callback can be specified, and in that case the presence must be requested individually for every user. The callback will be called with two String parameters: the user and its status
*/
function checkpresence (userlist, callback)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.CheckPresence(userlist, callback);
}
/** Function call to change the user online status with one of the followings strings: Online, Away, DND, Invisible, Offline (case sensitive) */
function setpresencestatus(statustring)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.SetPresenceStatus (statustring);
}
/** Call this function once, passing a callback.
* The passed callback function will be called on every presence (online/offline/others) state change (of the remote users).
* --PARAMETERS --
* peername: is the other party username (or phone number or extension)
* presence: can have following values: CallMe,Available,Pending,Other,CallForward,Speaking,Busy,Idle,DoNotDisturb,Unknown,Away,Offline,Exists,NotExists,Unknown
* displayname: optional peer display name if sent as part of presence
* email: optional peer email address if sent as part of presence */
function onPresenceStateChange(callback)
{
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.presencecb.push(callback);
}
/** Call this function once, passing a callback.
* The passed callback function will be called on every call state change (of the remote users) which might be used as BLF (busy lamp field).
* --PARAMETERS --
* peername: is the other party username (or phone number or extension)
* direction: can have one of following values: undefined, initiator (outgoing call) or receiver (incoming call)
* state: can have one of following values: trying , proceeding, early, confirmed, terminated, unknown or failed
* callid: optional SIP call-id of the call (if reported by the BLF notify)*/
function onBLFStateChange(callback)
{
if ( !callback || typeof (callback) !== 'function' ) { return; }
webphone_api.blfcb.push(callback);
}
/*
* Will receive call state information as BLF notifications and will trigger the onBlfStateChange callback.
* userlist: list of sip account usernames separated by comma
*/
function checkblf (userlist)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.CheckBLF(userlist);
else return false;
}
/** Check if communication channel is encrypted: -1=unknown, 0=no, 1=partially, 2=yes, 3=always*/
function isencrypted()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.IsEncrypted ();
else
return -1;
}
/** Set a custom sip header (a line in the SIP signaling) that will be sent with all messages.
* Can be used for various integration purposes (for example for sending the http session id).
* You can also set this with applet parameter (customsipheader).*/
function setsipheader(header)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.SetSipHeader(header);
else
webphone_api.Log('ERROR, webphone_api: setsipheader webphone_api.plhandler is not defined');
}
/** Call this function passing a callback.
* The passed callback function will be called with one parameter, which will be the string value of the requested sip header.*/
function getsipheader(header, callback, must)
{
if ( !callback || typeof (callback) !== 'function' ) { return; }
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.GetSipHeader(header, callback, must);
else
webphone_api.Log('ERROR, webphone_api: getsipheader webphone_api.plhandler is not defined');
}
/** Call this function passing a callback. The callback function will be called with the
* last SIP signaling message as specified by the current line and the dir/type parameters
* --PARAMETERS --
* dir: 0=incoming/received message, 1=out outgoing/sent message
* type: 0=any, 1=SIP request, 2=SIP answer, 3=INVITE (the last INVITE received or sent), 4=the last 200 OK */
function getsipmessage(dir, type, callback, must)
{
if ( !callback || typeof (callback) !== 'function' ) { return; }
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.GetSipMessage(dir, type,callback, must);
else
webphone_api.Log('ERROR, webphone_api: getsipmessage webphone_api.plhandler is not defined');
}
/** Change the color theme of the webphone skin. It is the same as from Settings -> Theme
* --PARAMETERS --
* theme: the integer index number of the theme. The default "Webphone" named theme is "0" "Light Blues" is "1", "Light Green" is "2" and so on. */
function changetheme(theme)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.ChangeTheme(theme);
else return false;
}
/** Call this function passing a callback.
* The passed callback function will be called with one parameter, which will be webphone's work directory.
* only for Java and Native Service engines*/
function getworkdir(callback)
{
if ( !callback || typeof (callback) !== 'function' ) { return 'ERROR, no callback'; }
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.GetWorkDir(callback);
else
return 'ERROR, getworkdir webphone_api.plhandler is not defined';
}
/** Delete stored data (from cookie and localstorage): settings, contacts, callhistory, messages
* level: 0: delete the settings only if it was not already cleared, 1: delete the settings, 2: force all (delete everything: settings, contacts, callhistory, messages), 3: delete also library cache
* !!! IMPORTANT: This API call will stop any runing engine. You will need to call start() to start the webphone */
function delsettings(level)
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
webphone_api.plhandler.delsettings(level);
else
webphone_api.Log('ERROR, webphone_api: delsettings webphone_api.plhandler is not defined');
}
/** Returns the currently used engine: "java", "webrtc", "ns", "app", "flash", "p2p", "nativedial". Can return empty string if engine selection is in progress*/
function getenginename()
{
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.Getenginename();
else {
webphone_api.Log('ERROR, webphone_api: getenginename webphone_api.plhandler is not defined');
return '';
}
}
/** Call this function passing a callback.
* The passed callback function will be called with one String parameter, which will be the last received call's SIP INVITE message. */
function getlastrecinvite(callback)
{
if ( !callback || typeof (callback) !== 'function' ) { return 'ERROR, no callback'; }
if (typeof (webphone_api.plhandler) !== 'undefined' && webphone_api.plhandler !== null)
return webphone_api.plhandler.GetLastRecInvite(callback);
else
return 'ERROR, getlastrecinvite webphone_api.plhandler is not defined';
}